dugasz1 Posted May 8, 2013 Share Posted May 8, 2013 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
50p Posted May 8, 2013 Share Posted May 8, 2013 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
dugasz1 Posted May 9, 2013 Author Share Posted May 9, 2013 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
xXMADEXx Posted May 9, 2013 Share Posted May 9, 2013 This script dosn't make very much sense... Read here: https://wiki.multitheftauto.com/wiki/OnPlayerQuit -- "onPlayerExit" isn't even an event... unless its custom. Link to comment
dugasz1 Posted May 9, 2013 Author Share Posted May 9, 2013 Thanks it's working perfect It got 2 error: 1. Bad event 2. And the function (here) writed things. 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