Narrator Posted September 25, 2014 Share Posted September 25, 2014 Hi all! As i know MTA has two main ways for temporarily storing data. First: elementData. Second: server's table. Ok, i want create something big (gamemode with inventory, etc), but elementData is slow and very expensive for CPU and i don't want use this way. Ok, temporarily server's table is fastest than elementData and not so expensive. But how i can get value from server's table in client-side script (for GUI, etc)? Is in this situation third way if i can't? Sorry for my grammar mistakes if they're. Link to comment
Narrator Posted September 25, 2014 Author Share Posted September 25, 2014 how i can trigger the table if trigger don't return value? Yes, i can write slowpoke-style code, which will get values from the table, but will it better than elementData? Link to comment
'LinKin Posted September 25, 2014 Share Posted September 25, 2014 You've got the table in the server. Then when a client opens the GUI, you trigger a server event where you select the values u want from the table and then trigger a client event to return the info. And yes, it would be better than elementData, it'd save CPU and bandwith. Simply, why would a player need to know the inventory of every player on the server? - It's unnessesary. Link to comment
Narrator Posted September 26, 2014 Author Share Posted September 26, 2014 'LinKin, thanks for answer. Who can tell me why when i use this scheme: client trigger to server for table -> server trigger to client with table result of #triggeredtable is always 0 but i can get values from this table so it's not empty. Why? How i can get correctly length? Link to comment
Anubhav Posted September 26, 2014 Share Posted September 26, 2014 myTable = { "select1", 'select2' } addCommandHandler("test", function() for k,v in ipairs(getElementsByType("player")) do triggerClientEvent(resourceRoot, "sendTable", resourceRoot, myTable) end end ) client: addEvent("sendTable",true) addEventHandler("sendTable", root, function(table) for k,v in ipairs(table) do outputChatBox(v) end end ) Use test. It will output all table containts. This was just a example how to trigger a table to client side and loop it. I suggest you to do like this. Link to comment
Narrator Posted September 26, 2014 Author Share Posted September 26, 2014 Anubhav, thanks for answer. I already made and use this scheme. But my table is empty when server start and only when player log in it generate subtables look like "items", "properties", etc. And result of #MyTable always is 0. It have fields, i get values from those fields but when i want get length of table, i get 0. Why? Link to comment
Narrator Posted September 26, 2014 Author Share Posted September 26, 2014 Thanks for all. Topic can be closed. 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