Baseplate Posted September 10, 2012 Share Posted September 10, 2012 Well, I have a column called "Occupation" and I wanna save that Data, any ideas? Link to comment
Baseplate Posted September 10, 2012 Author Share Posted September 10, 2012 Thanks, now let's see cause I did it wrong I think function onPlayerQuit ( ) -- when a player leaves, store his current money amount in his account data local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) and not isGuestAccount ( playeraccount ) then -- if the player is logged in local playermoney = getElementData ( source ) -- get the player data setAccountData ( playeraccount, "samgrpg.data", playermoney ) -- save it in his account end end function onPlayerLogin (_, playeraccount ) -- when a player logins, retrieve his money amount from his account data and set it if ( playeraccount ) then local playermoney = getAccountData ( playeraccount, "samgrpg.data" ) -- make sure there was actually a value saved under this key (check if playermoney is not false). -- this will for example not be the case when a player plays the gametype for the first time if ( playermoney ) then setElementData ( source, playermoney ) end end end addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit ) addEventHandler ( "onPlayerLogin", getRootElement ( ), onPlayerLogin) Link to comment
TAPL Posted September 10, 2012 Share Posted September 10, 2012 You have forgot the key of the element data. key: The name of the element data entry you want to retrieve. (Maximum 31 characters.) key: The key you wish to store the data under. (Maximum 31 characters.) Here: local playermoney = getElementData ( source ) And here: setElementData ( source, playermoney ) Link to comment
Baseplate Posted September 10, 2012 Author Share Posted September 10, 2012 function onPlayerQuit ( ) -- when a player leaves, store his current money amount in his account data local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) and not isGuestAccount ( playeraccount ) then -- if the player is logged in local playermoney = getElementData ( source, Occupation ) -- get the player data setAccountData ( playeraccount, "samgrpg.data", playermoney ) -- save it in his account end end function onPlayerLogin (_, playeraccount ) -- when a player logins, retrieve his money amount from his account data and set it if ( playeraccount ) then local playermoney = getAccountData ( playeraccount, "samgrpg.data" ) -- make sure there was actually a value saved under this key (check if playermoney is not false). -- this will for example not be the case when a player plays the gametype for the first time if ( playermoney ) then setElementData ( source, playermoney, "Occupation" ) end end end addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit ) addEventHandler ( "onPlayerLogin", getRootElement ( ), onPlayerLogin) So? Link to comment
TAPL Posted September 10, 2012 Share Posted September 10, 2012 This: local playermoney = getElementData ( source, Occupation ) should be local playermoney = getElementData ( source, "Occupation" ) And this: setElementData ( source, playermoney, "Occupation" ) should be: setElementData ( source, "Occupation", playermoney ) Link to comment
Baseplate Posted September 10, 2012 Author Share Posted September 10, 2012 Works fine and perfectly Thanks TAPL 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