liamknight24 Posted January 16, 2010 Share Posted January 16, 2010 ok so i want to save my players kills and i cant figure it out :: function onPlayerQuit ( ) local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) then local kills = getElementData ( source, "the kills" ) setAccountData ( playeraccount, "kills", kills ) end end function onPlayerLogin ( ) local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) then local kills = getAccountData ( playeraccount, "kills" ) if ( kills ) then setPlayerScore( source, "the kills", kills ) end end end addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit ) addEventHandler ( "onPlayerLogin", getRootElement ( ), onPlayerLogin ) any help will be appreciated. Link to comment
liamknight24 Posted January 16, 2010 Author Share Posted January 16, 2010 ok so i want to save my players kills and i cant figure it out :: function onPlayerQuit ( ) local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) then local kills = getElementData ( source, "the kills" ) setAccountData ( playeraccount, "kills", kills ) end end function onPlayerLogin ( ) local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) then local kills = getAccountData ( playeraccount, "kills" ) if ( kills ) then setPlayerScore( source, "the kills", kills ) end end end addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit ) addEventHandler ( "onPlayerLogin", getRootElement ( ), onPlayerLogin ) any help will be appreciated. Link to comment
Gamesnert Posted January 16, 2010 Share Posted January 16, 2010 A few questions: setPlayerScore( source, "the kills", kills ) Does this function actually exist? function onPlayerLogin ( ) local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) then Why are you using getPlayerAccount if onPlayerLogin actually has a parameter containing the currently used account? It could just be done as: function onPlayerLogin ( blah, playeraccount ) Perhaps that might also be the solution to your problem. local kills = getElementData ( source, "the kills" ) I'm not sure how get/setElementData responds to spaces in the name, but as a last resort you could try removing it. Link to comment
Gamesnert Posted January 16, 2010 Share Posted January 16, 2010 A few questions: setPlayerScore( source, "the kills", kills ) Does this function actually exist? function onPlayerLogin ( ) local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) then Why are you using getPlayerAccount if onPlayerLogin actually has a parameter containing the currently used account? It could just be done as: function onPlayerLogin ( blah, playeraccount ) Perhaps that might also be the solution to your problem. local kills = getElementData ( source, "the kills" ) I'm not sure how get/setElementData responds to spaces in the name, but as a last resort you could try removing it. Link to comment
50p Posted January 16, 2010 Share Posted January 16, 2010 .... local kills = getElementData ( source, "the kills" ) I'm not sure how get/setElementData responds to spaces in the name, but as a last resort you could try removing it. It's a string. It doesn't matter if it has spaces, same for custom event names (addEvent). @liamknight24, getPlaterAccount in every player event with source passed as argument will always return player account. I would advice to check if account isGuestAccount. Link to comment
50p Posted January 16, 2010 Share Posted January 16, 2010 .... local kills = getElementData ( source, "the kills" ) I'm not sure how get/setElementData responds to spaces in the name, but as a last resort you could try removing it. It's a string. It doesn't matter if it has spaces, same for custom event names (addEvent). @liamknight24, getPlaterAccount in every player event with source passed as argument will always return player account. I would advice to check if account isGuestAccount. Link to comment
subenji99 Posted January 16, 2010 Share Posted January 16, 2010 50p didn't make that very clear so I'll just elaborate here - getPlayerAccount will never fail to return an account as long as a valid player element is passed to it. However, anyone that is not logged in has a guest account. Data is never permanently saved to a guest account, (erased when the player quits) and cannot be retrieved on a later connect. That's why 50p is recommending you check isGuestAccount. Link to comment
subenji99 Posted January 16, 2010 Share Posted January 16, 2010 50p didn't make that very clear so I'll just elaborate here - getPlayerAccount will never fail to return an account as long as a valid player element is passed to it. However, anyone that is not logged in has a guest account. Data is never permanently saved to a guest account, (erased when the player quits) and cannot be retrieved on a later connect. That's why 50p is recommending you check isGuestAccount. Link to comment
liamknight24 Posted January 16, 2010 Author Share Posted January 16, 2010 function onPlayerQuit ( ) local kills = getElementData ( source, "the kills" ) setAccountData ( playeraccount, "kills", kills ) end function onPlayerLogin ( ) -- if this is not a real function what can i put there instead? local kills = getAccountData ( playeraccount, "kills" ) if ( kills ) then setPlayerScoreboardForced( player, "the kills", kills ) end end addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit ) addEventHandler ( "onPlayerLogin", getRootElement ( ), onPlayerLogin ) i tested it and it still dosent work the script i showed before saved the kills but did not put them onto the scoreboard, and also 50p players have to login if they want to play on the server so i dont think i need to check if its a guest account, but thanks for the info guys. Link to comment
liamknight24 Posted January 16, 2010 Author Share Posted January 16, 2010 function onPlayerQuit ( ) local kills = getElementData ( source, "the kills" ) setAccountData ( playeraccount, "kills", kills ) end function onPlayerLogin ( ) -- if this is not a real function what can i put there instead? local kills = getAccountData ( playeraccount, "kills" ) if ( kills ) then setPlayerScoreboardForced( player, "the kills", kills ) end end addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit ) addEventHandler ( "onPlayerLogin", getRootElement ( ), onPlayerLogin ) i tested it and it still dosent work the script i showed before saved the kills but did not put them onto the scoreboard, and also 50p players have to login if they want to play on the server so i dont think i need to check if its a guest account, but thanks for the info guys. Link to comment
robhol Posted January 16, 2010 Share Posted January 16, 2010 Well, obviously they don't... you haven't defined playeraccount anywhere. For onPlayerQuit, use getPlayerAccount(), for onPlayerLogin, it is passed as an argument to the event handler. Check the wiki page. setPlayerScoreboardForced doesn't do anything of that sort... use setElementData. Link to comment
robhol Posted January 16, 2010 Share Posted January 16, 2010 Well, obviously they don't... you haven't defined playeraccount anywhere. For onPlayerQuit, use getPlayerAccount(), for onPlayerLogin, it is passed as an argument to the event handler. Check the wiki page. setPlayerScoreboardForced doesn't do anything of that sort... use setElementData. 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