Jump to content

Table vs setElementData


Recommended Posts

Hello, I have been writing gamemode for a long time, everything that is important (information about the vehicle, player, object) is stored on the server side in the table.
My question is: what is safer and more optimal? Variables saved on the server side in the table and called to the client by events or elementData?

Link to comment

There is no problem using element data. Just try to limit the amount of data you have laying around if you don't really need it. This goes to both methods, tables or element data, limit the amount of data where possible!

Just one security related thing to element data though, you need to make sure you don't allow changing element data if it wasn't done by the server. You can read more on how here: https://wiki.multitheftauto.com/wiki/Script_security#Validating_client_setElementData

I usually just carry an ID on elements that have an entry in the database so I can fetch/save data from/to a database for that specific element. Some data that you will be accessing a lot is better to have cached in element data or tables rather than always make a database query when you need it, but this depends on how you edit data. If you for example edit data through the database or a control panel somewhere, the data might get out of sync with what is stored in a table or element data. So it depends on your situation, really.

I'd go with element data, but keep in mind script security as I linked above.

Also to keep in mind, is if you store things in a table, all of that data will be lost upon resource restart, whereas element data will stay if the element is not deleted by the stopping resource or something else. This I think is one of the good sides about element data.

Edited by myonlake
  • Like 1
Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...