Tekken Posted May 3, 2020 Posted May 3, 2020 So I'm interested into replacing element data functions to more efficient store data into tables but with this comes a problem, syncing the data between client and server so I taught of creating a shared Lua file and building the system there so in this way the functions will work both client/server. But will this work? Or should I use a make around with the event system? Resources I made: attachToBones - A newer bone_attach. Simple Level system - Just a simple level system. Do not PM me for help with leaked scripts! I WILL NOT HELP YOU!
sacr1ficez Posted May 3, 2020 Posted May 3, 2020 12 minutes ago, Tekken said: So I'm interested into replacing element data functions to more efficient store data into tables but with this comes a problem, syncing the data between client and server so I taught of creating a shared Lua file and building the system there so in this way the functions will work both client/server. But will this work? Or should I use a make around with the event system? Shared won't work. Example: -- Client local clientTable = {} -- function onClientDataSync(serverData) clientTable = serverData end addEvent("onClientDataSync", true) addEventHandler("onClientDataSync", resourceRoot, onClientDataSync) -- function onClientReceiveVehicleData(...) local receivedData = {...} local vehicleUserdata = receivedData[1] local vehicleData = receivedData[2] clientTable[vehicleUserdata] = vehicleData outputConsole(inspect(clientTable)) end addEvent("onClientReceiveVehicleData", true) addEventHandler("onClientReceiveVehicleData", resourceRoot, onClientReceiveVehicleData) -- Server local serverTable = {} local newVehicle = createVehicle(411, 0, 0, 3) -- serverTable[newVehicle] = "Some data you want to pass" About sync: --[[Sync for everyone]] triggerClientEvent(root, "onClientReceiveVehicleData", resourceRoot, newVehicle, serverTable[newVehicle]) --[[When player latejoined - pass data f.e when he logins]] triggerClientEvent(source, "onClientDataSync", resourceRoot, serverTable) 1 Script security
Tekken Posted May 3, 2020 Author Posted May 3, 2020 But why shared will not work? Resources I made: attachToBones - A newer bone_attach. Simple Level system - Just a simple level system. Do not PM me for help with leaked scripts! I WILL NOT HELP YOU!
sacr1ficez Posted May 3, 2020 Posted May 3, 2020 1 minute ago, Tekken said: But why shared will not work? Tables aren't synced by default. If you create tables via shared script, they do not have same data (unless you will sync it). Take a look at this topic, might be helpful. 1 Script security
Moderators IIYAMA Posted May 3, 2020 Moderators Posted May 3, 2020 (edited) 21 minutes ago, Tekken said: But why shared will not work? If you enable shared, this is what will happen: <script src="file.Lua" type="shared"/> becomes <script src="file.Lua" type="client"/> <script src="file.Lua" type="server"/> The file is now used for serverside as well as clientside. But they are still loaded on 2 different applications. And as you know, you can't share your memory across the internet without taking the connection delay `ping` in consideration. The concept behind `shared` is a feature to make (utility) functionalities that work on both sides (client/server). Main purpose: Less maintenance The following content could be useful for in a shared file: https://wiki.multitheftauto.com/wiki/FindRotation https://wiki.multitheftauto.com/wiki/Table.random https://wiki.multitheftauto.com/wiki/Table.compare etc. Edited May 3, 2020 by IIYAMA 1 Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
Fist Posted May 3, 2020 Posted May 3, 2020 It's really easy to create alternative setElementData function what uses tables instead with automatic syncing. https://github.com/rivor/ttt-mta/blob/master/terrortown/scripts/server/playerdata.Lua this is the way i did back when i was still making my own stuff on mta, you can check client side, which is in client files but it's exact same code just reversed. Of course for better security, i recommend it so that you wouldn't use syncing from client side to server for obvious reasons.
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