Sign in to follow this  
littlejth

Saving money not working?

Recommended Posts

Does someone know why this may not be working, this is the example from the wiki that I am trying to use:

function onPlayerQuit ( ) 
  
      local playeraccount = getPlayerAccount ( source ) 
      if ( playeraccount ) then 
            local playermoney = getPlayerMoney ( source ) 
            setAccountData ( playeraccount, "money", playermoney ) 
      end 
end 
  
function onPlayerJoin ( ) 
  
      local playeraccount = getPlayerAccount ( source ) 
      if ( playeraccount ) then 
            local playermoney = getAccountData ( playeraccount, "money" ) 
            if ( playermoney ) then 
                  setPlayerMoney ( source, playermoney ) 
            end 
      end 
end 
............. 
addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit ) 
addEventHandler ( "onPlayerJoin", getRootElement ( ), onPlayerJoin ) 

Share this post


Link to post
Does someone know why this may not be working, this is the example from the wiki that I am trying to use:

function onPlayerQuit ( ) 
  
      local playeraccount = getPlayerAccount ( source ) 
      if ( playeraccount ) then 
            local playermoney = getPlayerMoney ( source ) 
            setAccountData ( playeraccount, "money", playermoney ) 
      end 
end 
  
function onPlayerJoin ( ) 
  
      local playeraccount = getPlayerAccount ( source ) 
      if ( playeraccount ) then 
            local playermoney = getAccountData ( playeraccount, "money" ) 
            if ( playermoney ) then 
                  setPlayerMoney ( source, playermoney ) 
            end 
      end 
end 
............. 
addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit ) 
addEventHandler ( "onPlayerJoin", getRootElement ( ), onPlayerJoin ) 

You just should have to save

            setAccountData ( playeraccount, "money", playermoney ) 

in another file.

And for the onPlayerJoin part the sever have to know who the player is. And how many money he or she has.

Maybe try getClientName or something.

Share this post


Link to post

Hookerkiller, you obviously haven't got the foggiest idea of what you're saying. Shut up until you know what you're talking about.

As for you, littlejth,

1) Don't listen to thehookerkiller

2) You need to give us more info. Error messages and warnings (the entire message) and the lines they indicate.

Share this post


Link to post

I think this part is giving you trouble...

function onPlayerJoin ( ) 
  
      local playeraccount = getPlayerAccount ( source ) 
      if ( playeraccount ) then 
            local playermoney = getAccountData ( playeraccount, "money" ) 
            if ( playermoney ) then 
                  setPlayerMoney ( source, playermoney ) 
            end 
      end 
end 

Because most probably, when a player joins, he still is on a guest account. (which doesn't have any account data)

I guess this might make it work, not sure, but worth a try I guess... (I think you can remove onPlayerJoin if you use this)

function onClientLogin ( previous, new ) 
      if new and not isGuestAccount ( new ) then -- Just added this to be sure 
            local playermoney = getAccountData ( new, "money" ) 
            if ( playermoney ) then 
                  setPlayerMoney ( source, playermoney ) 
            end 
      end 
end 
addEventHandler ( "onClientLogin", getRootElement ( ), onClientLogin ) 

Share this post


Link to post

Wow. I shouldv'e seen that. ._.

Anyways, I think you should rename the function itself (I'm not sure, but I think I've heard that having functions the same names as av event isn't good.)

Share this post


Link to post
Anyways, I think you should rename the function itself (I'm not sure, but I think I've heard that having functions the same names as av event isn't good.)

Nah, nothing bad about it

Share this post


Link to post
Anyways, I think you should rename the function itself (I'm not sure, but I think I've heard that having functions the same names as av event isn't good.)

Nah, nothing bad about it

Good to know, thanks. ;)

Share this post


Link to post

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.