Jump to content

Player data saver


Recommended Posts

Hy! We write a player data saver, but i got some problem whit it.

function onExit ( playerSource ) 
 local newx, newy, newz = getElementPosition( playerSource ) 
 local newpenz = getPlayerMoney ( playerSource  ) 
 local newhp = getElementHealth ( playerSource  ) 
 local newarmor = getPedArmor ( playerSource  ) 
 -- Mysql rész 
 local pName = getPlayerName(playerSource) 
 local sqlpName = mysql_query(handler,"SELECT * FROM account_data WHERE AccountName = '"..pName.."';") 
 local pAdat = mysql_fetch_assoc(sqlpName) 
 mysql_query(handler,"UPDATE account_data SET x="..newx..", y="..newy..", z="..newz..", hp="..newhp..", armor="..newarmor.." WHERE AccountName='"..pAdat['IGName'].."' ;") 
 outputChatBox("Saved  "..pAdat['AccountName'].."!", source, 255, 0, 0) 
end 
addCommandHandler("save",onExit) 
  

It's working fine now,but it's manually.

We want to make this automaticly if the player quit,but this

addEventHandler ( "onPlayerQuit", getRootElement(), onQuit ) 

doesen't work it's save always the same datas. (Something default or i don't know. Save this: x,y,z = 2497,

2497,2496.604492187)

Any idea :?:

Link to comment

If it works when you're using the command then you can call this function from onPlayerQuit event.

addEventHandler( "onPlayerQuit", root, 
    function( ) 
        onExit( source ); 
    end 
) 

Link to comment

Now i understand the problem to a call bad element (I guess)

But i don't know how i call the player who's left when i use addEventHanler()

Somebody/You can explain me?

(I writed this but its maybe nonsense. mmm... and i don't understand what should i write in the function's parenthesis pl.: function (here)[/lua]):

function onExit ( root ) 
    local newx, newy, newz = getElementPosition( root ) 
    local newpenz = getPlayerMoney ( root ) 
    local newhp = getElementHealth ( root ) 
    local newarmor = getPedArmor ( root ) 
    -- Mysql rész 
    local pName = getPlayerName( root ) 
    local sqlpName = mysql_query(handler,"SELECT * FROM account_data WHERE IGName = '"..pName.."';") 
    local pAdat = mysql_fetch_assoc(sqlpName) 
    mysql_query(handler,"UPDATE account_data SET x="..newx..", y="..newy..", z="..newz..", hp="..newhp..", armor="..newarmor.." WHERE IGName='"..pAdat['IGName'].."' ;") 
    --outputChatBox("Saved "..pAdat['IGName'].." !", source, 255, 0, 0)  
    outputDebugString("One player adat has been saved!") 
end 
--addCommandHandler("save",onExit)  
addEventHandler ("onPlayerExit", root, onExit) 
  

(It isn't work)

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