Dudalus Posted October 2, 2012 Share Posted October 2, 2012 Hi I use element data's for saving my playerstats, but the problem is, that they aren't safe (Clienthack), so my plan is to use a table. My first idea was to block all (player-element) changes from from client to the server (onElementDataChange) and use an own setPlayerElementData function. Before I use a clientside getElementData function , I sync the data from the server. But this solution has an overhead, and tables look much better Is there a good way to use a table ? Link to comment
codeluaeveryday Posted October 2, 2012 Share Posted October 2, 2012 (edited) Tables are a very efficent way to store data , I use to them in many of my scripts found in K@N Zombies. This is a small example I cooked up for you. playerSkin = {} addEventHandler("onPlayerWasted", getRootElement(), function() playerSkin[source] = getElementModel(source) end ) addEventHandler("onPlayerSpawn", getRootElement(), function() setElementModel(source, playerSkin[source] or 0) end ) Its very simple, playerSkin[source] is adding a key to the table so and by using it like a variable its setting a value to the key. playerSkin[source] == getElementModel(source) is equivalent to playerSkin = { playerElement = skinID } I hope this helps you understand, if it doesnt please explain what you are planning to do and the community of MTASA will help you . Edited October 2, 2012 by Guest Link to comment
Anderl Posted October 2, 2012 Share Posted October 2, 2012 Tables are a very efficent way to store data , I use to them in many of my scripts found in K@N Zombies. This is a small example I cooked up for you. playerSkin = {} addEventHandler("onPlayerWasted", getRootElement(), function() playerSkin[source] == getElementModel(source) end ) addEventHandler("onPlayerSpawn", getRootElement(), function() setElementModel(source, playerSkin[source]) end ) Its very simple, playerSkin[source] is adding a key to the table so and by using it like a variable its setting a value to the key. playerSkin[source] == getElementModel(source) is equivalent to playerSkin = { playerElement = skinID } I hope this helps you understand, if it doesnt please explain what you are planning to do and the community of MTASA will help you . Your code won't work because two reasons: - You're using a comparition symbol instead of a single =. - In 'onPlayerSpawn' it won't work the first time as when the player is spawned for first time he hasn't been killed yet. Link to comment
codeluaeveryday Posted October 2, 2012 Share Posted October 2, 2012 Fixed and thanks, Its just an example post, he could have easily found the error himself . Link to comment
Dudalus Posted October 3, 2012 Author Share Posted October 3, 2012 Hey, thank you for the reply, it works fine with tables. onPlayerSpawn isn't that problem, because I call (trigger) an own function 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