JamieSA Posted January 19, 2017 Share Posted January 19, 2017 (edited) Hi, I've been working on a personal vehicle script recently and have run into a problem... in my GUI panel, I have a grid list that is populated by calling a function that pulls the user data "personal_vehicle_x" from the internal DB and sets it into element data with the same name and displays it in the list.... it works at first, when the panel is first initiated by pressing the bound key (num_add) (i call the server function each time the corresponding key is pressed to ensure the list is updated)... I can see the data changing in the database, however, the code accessing it is not getting the new result... is there something fundamental I am missing? and should I be adding custom tables for this? or is it ok to make use of the user data table? Also... the data updates upon the player logging in, where I am also calling the function initially Edited January 19, 2017 by JamieSA Link to comment
JamieSA Posted January 19, 2017 Author Share Posted January 19, 2017 Server: ------------------------------------------------------------------------------------ -- Get Garage function - used to fill and refresh personal vehicle list ------------------------------------------------------------------------------------ addEvent("getGarage", true) function getGarage ( thePlayer ) playerAccount = getPlayerAccount(thePlayer) dataTable = {} dataTable[10] = getAccountData(playerAccount, "activePV") for i=0,9 do id = getAccountData(playerAccount, "personal_vehicle_"..i) dataTable[i] = id end for k,v in ipairs(dataTable) do setElementData(source, "personal_vehicle_"..k, v) end outputConsole("--- Vehicle list returned from server. ---") triggerClientEvent("getGarageCallback", thePlayer, dataTable) end addEventHandler ( "getGarage", getRootElement(), getGarage ) ------------------------------------------------------------------------------------ Client: ------------------------------------------------------------------------------------ -- Get garage callback ------------------------------------------------------------------------------------ addEvent("getGarageCallback", true) function getGarageCallback(theGarage) if(theGarage)then outputConsole("--- Vehicle list received by client. ---") end end addEventHandler ( "getGarageCallback", getRootElement(), getGarageCallback ) ------------------------------------------------------------------------------------ works the first time... but never again whats going on?? Link to comment
JamieSA Posted January 19, 2017 Author Share Posted January 19, 2017 solved this myself... getAllAccountData saved me here Link to comment
Moderators IIYAMA Posted January 19, 2017 Moderators Share Posted January 19, 2017 (edited) Here some more improvements: First of all use: local On: ? playerAccount, dataTable, id Shouldn't be able to access from other places! They should be freed from the memory after the code has been executed! Define the target player, you want the data to be send back to: (else all players get this data!) triggerClientEvent(thePlayer, "getGarageCallback", thePlayer, dataTable) Edited January 19, 2017 by IIYAMA Link to comment
JamieSA Posted January 19, 2017 Author Share Posted January 19, 2017 Thankyou for your reply 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