DBY Posted October 17, 2015 Share Posted October 17, 2015 I want to compile a file using API mta. But there are two functions that do not exist in MTA (fileSave and fileLoad) Any ideas? https://luac.multitheftauto.com/api/ local FROM="example.lua" local TO="compiled.lua" fetchRemote( "https://luac.multitheftauto.com/?compile=1&debug=0&obfuscate=0", function(data) fileSave(TO,data) end, fileLoad(FROM), true ) Link to comment
N1kS Posted October 17, 2015 Share Posted October 17, 2015 You can write it... function fileSave( File, Data ) if( fileExists( File ) ) then fileDelete( File ); end local File = fileCreate( File ); fileWrite( File, Data ); fileClose( File ); end function fileLoad( File ) return fileRead( File, fileGetSize( File ) ); end Link to comment
DBY Posted October 17, 2015 Author Share Posted October 17, 2015 You can write it... function fileSave( File, Data ) if( fileExists( File ) ) then fileDelete( File ); end local File = fileCreate( File ); fileWrite( File, Data ); fileClose( File ); end function fileLoad( File ) return fileRead( File, fileGetSize( File ) ); end That I had already tried, but still not working. (Now do not get errors in the debugscript) Link to comment
Kenix Posted October 17, 2015 Share Posted October 17, 2015 Try function fileSave( sFile, sData ) if fileExists( sFile ) then fileDelete( sFile ); end local pFile = fileCreate( sFile ); fileWrite( pFile, sData ); fileClose( pFile ); end function fileLoad( sFile ) local pFile = fileOpen( sFile, true ); local sData = fileRead( pFile, fileGetSize( pFile ) ); fileClose( pFile ); return sData; end Link to comment
DBY Posted October 17, 2015 Author Share Posted October 17, 2015 Try function fileSave( sFile, sData ) if fileExists( sFile ) then fileDelete( sFile ); end local pFile = fileCreate( sFile ); fileWrite( pFile, sData ); fileClose( pFile ); end function fileLoad( sFile ) local pFile = fileOpen( sFile, true ); local sData = fileRead( pFile, fileGetSize( pFile ) ); fileClose( pFile ); return sData; end Thank you very much for commenting, but these functions do the same thing that I've done. PS: Still not working. Link to comment
Kenix Posted October 17, 2015 Share Posted October 17, 2015 Please show me full script. Link to comment
DBY Posted October 17, 2015 Author Share Posted October 17, 2015 function fileSave(filePath, fileContent) if fileExists(filePath) then fileDelete(filePath) end local file = fileCreate(filePath) fileWrite(file, fileContent) fileClose(file) end function fileLoad(filePath) if fileExists(filePath) then local file = fileOpen(filePath) local fileContent = fileRead(file, fileGetSize(file)) fileClose(file) return fileContent end end function fileCompile(FROM, TO) if FROM and TO then fetchRemote("https://luac.multitheftauto.com/?compile=1&debug=0&obfuscate=0", function(data) fileSave(TO, data) end, fileLoad(FROM), true) end end The problem now is that it creates the file but the page returns "ERROR" Link to comment
N1kS Posted October 17, 2015 Share Posted October 17, 2015 Works for me: function fileSave( sFile, sData ) if fileExists( sFile ) then fileDelete( sFile ); end local pFile = fileCreate( sFile ); fileWrite( pFile, sData ); fileClose( pFile ); end function fileLoad( sFile ) local pFile = fileOpen( sFile, true ); local sData = fileRead( pFile, fileGetSize( pFile ) ); fileClose( pFile ); return sData; end local FROM="example.lua" local TO="compiled.luac" fetchRemote( "https://luac.multitheftauto.com/?compile=1&debug=0&obfuscate=0", function(data) print( tostring( data ) ) fileSave( TO, data ) end, fileLoad( FROM ), true ); Link to comment
UserToDelete Posted October 17, 2015 Share Posted October 17, 2015 Can be error from fileLoad.. not save.. Link to comment
Noki Posted October 17, 2015 Share Posted October 17, 2015 The problem now is that it creates the file but the page returns "ERROR" The page on a web browser displays "ERROR" when the uploaded file has a syntax error. Link to comment
UserToDelete Posted October 17, 2015 Share Posted October 17, 2015 The problem now is that it creates the file but the page returns "ERROR" The page on a web browser displays "ERROR" when the uploaded file has a syntax error. Or fileLoad or codification doesnt work Link to comment
Noki Posted October 17, 2015 Share Posted October 17, 2015 No, the file functions he is using return bools, file handlers or an integer representing a number of bytes either read or written. The only way "ERROR" could be returned is through fetchRemote. Link to comment
DBY Posted October 18, 2015 Author Share Posted October 18, 2015 The script creates the file, but inside it there is only "ERROR" Link to comment
UserToDelete Posted October 18, 2015 Share Posted October 18, 2015 function fileLoad(path) local File = fileOpen(path, true) if File then local data = fileRead(File, fileGetSize(File)) fileClose(File) return data end end function fileSave(path, data) local File = fileCreate(path) if File then fileWrite(File, data) fileClose(File) end end Link to comment
DBY Posted October 18, 2015 Author Share Posted October 18, 2015 function fileLoad(path) local File = fileOpen(path, true) if File then local data = fileRead(File, fileGetSize(File)) fileClose(File) return data end end function fileSave(path, data) local File = fileCreate(path) if File then fileWrite(File, data) fileClose(File) end end Your code does the same job as my code. Still creates a file containing "ERROR". Link to comment
Noki Posted October 18, 2015 Share Posted October 18, 2015 If it throws an error when you try to compile the script on the website, then you have a syntax error in your script. It works fine for me and it throws "ERROR" when I try to compile a file with a syntax error. Link to comment
DBY Posted October 18, 2015 Author Share Posted October 18, 2015 If it throws an error when you try to compile the script on the website, then you have a syntax error in your script. It works fine for me and it throws "ERROR" when I try to compile a file with a syntax error. I put "print()" into file i want compile. But still return "error" Link to comment
MisterQuestions Posted October 18, 2015 Share Posted October 18, 2015 https://wiki.multitheftauto.com/wiki/GetResourceScripts Link to comment
The Don Posted October 18, 2015 Share Posted October 18, 2015 https://community.multitheftauto.com/in ... ls&id=9219 Link to comment
DBY Posted October 18, 2015 Author Share Posted October 18, 2015 Apparently, the problem is not the script, it's my localhost. FetchRemote not work, I tried some compilers and none worked for me. Your comments are appreciated. Link to comment
MisterQuestions Posted October 19, 2015 Share Posted October 19, 2015 Apparently, the problem is not the script, it's my localhost. FetchRemote not work, I tried some compilers and none worked for me.Your comments are appreciated. Lel, the test funct from getResourceScripts works perfectly for compiling Just modify the funct. Add xmlUnloadFile for meta xmlFile (or will keep opening files and stay loaded at memory). Link to comment
Saml1er Posted November 19, 2015 Share Posted November 19, 2015 Because you need to do port forwarding. Execute "openports" in your server console and it will you whether your ports are open or no. If no then do port forwarding. Link to comment
Addlibs Posted November 19, 2015 Share Posted November 19, 2015 (edited) Because you need to do port forwarding. Execute "openports" in your server console and it will you whether your ports are open or no. If no then do port forwarding. Port forwarding (in regards to /openports) is for incoming connections, not outgoing. The API server already has the necessary ports open, and therefore connection should work (unless there's firewall the outgoing server) Edited November 19, 2015 by Guest Link to comment
Saml1er Posted November 19, 2015 Share Posted November 19, 2015 Because you need to do port forwarding. Execute "openports" in your server console and it will you whether your ports are open or no. If no then do port forwarding. Port forwarding is for incoming connections, not outgoing. The API server already has the necessary ports open, and therefore connection should work (unless there's firewall the outgoing server) I wonder why callRemote was not working for me when my ports were not open? Hmmm I think it was an year ago. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now