.:HyPeX:. Posted April 28, 2014 Share Posted April 28, 2014 Hey Guys should this work? local chatbox = outputChatBox function CallMe() chatbox("Test") end CallMe() Also, can i save them down as a string to send them, and how? function BassHandler() --Stuff end local MyString = ""..BassHandler.."" MyLoad = loadstring(MyString) Link to comment
Moderators Citizen Posted April 28, 2014 Moderators Share Posted April 28, 2014 Hey Guys should this work? local chatbox = outputChatBox function CallMe() chatbox("Test") end CallMe() Yes (why didn't you try yourself ?!) Also, can i save them down as a string to send them, and how? function BassHandler() --Stuff end local MyString = ""..BassHandler.."" MyLoad = loadstring(MyString) This won't work even if you used the tostring function because you would get a lua function pointer instead of the instructions. As far I know, you can't If you want to call a function with its name, you can do something like this: function callMyFunction( funcName ) _G[funcName]() end --and then function myFunction() outputChatBox("Hi") end callMyFunction("myFunction") But if your function is on the server side, you can't call it from the client side and vice-versa. Btw, I just got an idea. It would be possible actually. You can do this by making a function which will take a function name as argument. It will then open all lua files look for the function using the name provided. Once it found it, then it will read the instruction and append each line of it into a string. When the end keyword of that function is found, then it will stop everything and send the string to the client side wich will receive the string, use the loadstring function and then call that function. That should definitly work if you can make a well coded function to parse the files and get the functions properly. Link to comment
.:HyPeX:. Posted April 29, 2014 Author Share Posted April 29, 2014 Well, i'm just saying about not using any client-side script, just loadstring and everything on a string server-side. Doing this will have any effect on event handlers or it will work perfectly? (I would only have a client-side function wich loads all server-side stuff) PD: About the first stuff, i thought anyone could just say it out, seemed easier than trying it (Since it was just a random question, it involved less effort from both sides to ask it. ) Link to comment
Moderators Citizen Posted April 29, 2014 Moderators Share Posted April 29, 2014 Doing this will have any effect on event handlers or it will work perfectly? (I would only have a client-side function wich loads all server-side stuff) Please explain better (give a lot of details) what you are trying to achieve. Do you want to prevent others to steal your client script code ? Link to comment
.:HyPeX:. Posted April 29, 2014 Author Share Posted April 29, 2014 Doing this will have any effect on event handlers or it will work perfectly? (I would only have a client-side function wich loads all server-side stuff) Please explain better (give a lot of details) what you are trying to achieve. Do you want to prevent others to steal your client script code ? Yes, but im unsure if loadstring will let a function go on perfectly, if i load like this, will it work? myString = "function Cheetah() dxDrawText('Test', 400,200, 100,100,tocolor(255,255,255,255),3) end addEventHandler('onClientRender', getRootElement(), Cheetah)" loadstring(myString) Link to comment
Moderators Citizen Posted April 30, 2014 Moderators Share Posted April 30, 2014 (edited) Doing this will have any effect on event handlers or it will work perfectly? (I would only have a client-side function wich loads all server-side stuff) Please explain better (give a lot of details) what you are trying to achieve. Do you want to prevent others to steal your client script code ? Yes, but im unsure if loadstring will let a function go on perfectly, if i load like this, will it work? myString = "function Cheetah() dxDrawText('Test', 400,200, 100,100,tocolor(255,255,255,255),3) end addEventHandler('onClientRender', getRootElement(), Cheetah)" loadstring(myString) Yes it will work but only if you don't forget to execute that loaded string: loadstring(myString)() --the extra parenthesis will execute the string loaded returned by the loadstring function Also note that you can't wrote a string in multiple lines like u did from line 2 to 5 but I got the main idea you were trying to explain. There is a usefull topic for what you want to achieve: https://forum.multitheftauto.com/viewtopic.php?f ... 90#p337791 This script is sending only one file to the clientside but you can easilly modify it to provide a list of file to send (for example using a xml file like the meta but only listing the client files you want to send using this way). It's loading that script as a string, then send it to the client that will receive and then use the loadstring as you did to make this work. Note that the event "onClientResourceStart" won't be triggered for your resource in your resource because it would be triggered before your script has done loading your script from the server. Edited April 30, 2014 by Guest Link to comment
LonelyRoad Posted April 30, 2014 Share Posted April 30, 2014 To write a string over multiple lines you need to use double squared brackets ( [[ ]] ) IIRC. Link to comment
Saml1er Posted April 30, 2014 Share Posted April 30, 2014 Use pcall with loadString ^^ local code = loadstring(myString) if code then pcall(code) print (worked) end 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