Jump to content

Updating user data


JamieSA

Recommended Posts

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 by JamieSA
Link to comment
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
  • Moderators

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 by IIYAMA
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...