xeon17 Posted January 28, 2014 Share Posted January 28, 2014 What functions i need to use to save players kills,deaths,ratio when player quit in his account , and when he enter he have his kills,dealth,ratio . Link to comment
MTA Team 0xCiBeR Posted January 28, 2014 MTA Team Share Posted January 28, 2014 getPlayerAccount setAccountData getAccountData Link to comment
xeon17 Posted January 28, 2014 Author Share Posted January 28, 2014 Will this work ? addEventHandler ( "onPlayerWasted", root, function( totalAmmo, killer, killerWeapon, bodypart, stealth ) if killer then local account = getPlayerAccount ( killer ) if killer ~= source then setAccountData( account,"killsdeathsratio.Kills",tonumber( getAccountData( account,"killdeathsratio.Kills" ) or 0 ) +1 ) setElementData( killer, "Kills", tonumber( getAccountData( account,"killsdeathsratio.Kills" ) ) ) setElementData( killer, "Ratio, tonumber(getElementData( killer, "Kills" )/getElementData( source, "Deaths") ) ) end else local accountSource = getPlayerAccount ( source ) setAccountData( accountSource,"killsdeathsratio.Deaths",tonumber( getAccountData(accountSource,"killsdeathsratio.Deaths") or 0 ) +1 ) setElementData( source, "Deaths, tonumber( getAccountData( accountSource,"killsdeathsratio.Deaths" ) ) ) setElementData( source, "Ratio", getElementData( killer, "Kills )/getElementData( source, "Deaths") ) end end ) addEventHandler( "onPlayerLogin",root, function( thePreviousAccount, theCurrentAccount, autoLogin ) local account = getPlayerAccount ( source ) if not getAccountData( account,"killsdeathsratio.Kills" ) and not getAccountData( account,"killsdeathsratio.Deaths" ) then setAccountData( account,"killsdeathsratio.Kills",0 ) setAccountData( account,"killsdeathsratio.Deaths",0 ) end setElementData( source,"Deaths",tonumber( getAccountData( account,"killsdeathsratio.Deaths" ) or 0 ) ) setElementData( source,"Kills,tonumber( getAccountData( account,"killsdeathsratio.Kills" ) or 0 ) ) setElementData( source, "Ratio", getElementData( source, "Kills" )/getElementData( source, "Deaths) ) end ) Link to comment
MTA Team 0xCiBeR Posted January 28, 2014 MTA Team Share Posted January 28, 2014 No that will not work. Try this, and if you get any errors post them: addEventHandler ( "onPlayerWasted", root, function( totalAmmo, killer, killerWeapon, bodypart, stealth ) if killer then local account = getPlayerAccount ( killer ) if killer ~= source then setAccountData( account,"killsdeathsratio.Kills",tonumber( getAccountData( account,"killdeathsratio.Kills" ) or 0 ) +1 ) setElementData( killer, "Kills", tonumber( getAccountData( account,"killsdeathsratio.Kills" ) ) ) setElementData( killer, "Ratio", tonumber(getElementData( killer, "Kills" )/getElementData( source, "Deaths") ) ) end else local accountSource = getPlayerAccount ( source ) setAccountData( accountSource,"killsdeathsratio.Deaths",tonumber( getAccountData(accountSource,"killsdeathsratio.Deaths") or 0 ) +1 ) setElementData( source, "Deaths", tonumber( getAccountData( accountSource,"killsdeathsratio.Deaths" ) ) ) setElementData( source, "Ratio", getElementData( killer, "Kills" )/getElementData( source, "Deaths") ) end end ) addEventHandler( "onPlayerLogin",root, function( thePreviousAccount, theCurrentAccount, autoLogin ) local account = getPlayerAccount ( source ) if not getAccountData( account,"killsdeathsratio.Kills" ) and not getAccountData( account,"killsdeathsratio.Deaths" ) then setAccountData( account,"killsdeathsratio.Kills",0 ) setAccountData( account,"killsdeathsratio.Deaths",0 ) end setElementData( source,"Deaths",tonumber( getAccountData( account,"killsdeathsratio.Deaths" ) or 0 ) ) setElementData( source,"Kills",tonumber( getAccountData( account,"killsdeathsratio.Kills" ) or 0 ) ) setElementData( source, "Ratio", getElementData( source, "Kills" )/getElementData( source, "Deaths") ) end ) Link to comment
iPrestege Posted January 28, 2014 Share Posted January 28, 2014 No it's not and you can find why using 'debugscript3' cmd . Edit : Sorry ciber we post in the same time ! Link to comment
xeon17 Posted January 28, 2014 Author Share Posted January 28, 2014 All is working nice but in the scoreboard frist is Deaths after Ratio and Kills. should be Kills,Deaths,Ratio here the full script : addEventHandler ( "onPlayerWasted", root, function( totalAmmo, killer, killerWeapon, bodypart, stealth ) if killer then local account = getPlayerAccount ( killer ) if killer ~= source then setAccountData( account,"killsdeathsratio.Kills",tonumber( getAccountData( account,"killdeathsratio.Kills" ) or 0 ) +1 ) setElementData( killer, "Kills", tonumber( getAccountData( account,"killsdeathsratio.Kills" ) ) ) setElementData( killer, "Ratio", tonumber(getElementData( killer, "Kills" )/getElementData( source, "Deaths") ) ) end else local accountSource = getPlayerAccount ( source ) setAccountData( accountSource,"killsdeathsratio.Deaths",tonumber( getAccountData(accountSource,"killsdeathsratio.Deaths") or 0 ) +1 ) setElementData( source, "Deaths", tonumber( getAccountData( accountSource,"killsdeathsratio.Deaths" ) ) ) setElementData( source, "Ratio", getElementData( killer, "Kills" )/getElementData( source, "Deaths") ) end end ) addEventHandler( "onPlayerLogin",root, function( thePreviousAccount, theCurrentAccount, autoLogin ) local account = getPlayerAccount ( source ) if not getAccountData( account,"killsdeathsratio.Kills" ) and not getAccountData( account,"killsdeathsratio.Deaths" ) then setAccountData( account,"killsdeathsratio.Kills",0 ) setAccountData( account,"killsdeathsratio.Deaths",0 ) end setElementData( source,"Deaths",tonumber( getAccountData( account,"killsdeathsratio.Deaths" ) or 0 ) ) setElementData( source,"Kills",tonumber( getAccountData( account,"killsdeathsratio.Kills" ) or 0 ) ) setElementData( source, "Ratio", getElementData( source, "Kills" )/getElementData( source, "Deaths") ) end ) addEventHandler( "onResourceStart",resourceRoot, function( ) outputDebugString( "add Total Kills to scoreboard Return: "..tostring( call( getResourceFromName("Scoreboard"), "addScoreboardColumn", "Kills",root,5, 0.070 ) ) ) outputDebugString( "add Total Kills to scoreboard Return: "..tostring( call( getResourceFromName("Scoreboard"), "addScoreboardColumn", "Deaths",root,5, 0.070 ) ) ) outputDebugString( "add Ratio to scoreboard Return: "..tostring( call( getResourceFromName("Scoreboard"), "addScoreboardColumn", "Ratio",root,5, 0.070 ) ) ) end ) an picture : Picture with my Favorite scoreboard whitch i use Link to comment
xeon17 Posted January 28, 2014 Author Share Posted January 28, 2014 I got a bug now [2014-01-28 20:37:32] WARNING: X-Scores\server.lua:15: Bad argument @ 'getElementData' [Expected element at argument 1, got boolean] [2014-01-28 20:37:32] ERROR: X-Scores\server.lua:15: attempt to perform arithmetic on a boolean value Link to comment
Castillo Posted January 28, 2014 Share Posted January 28, 2014 addEventHandler ( "onPlayerWasted", root, function ( totalAmmo, killer, killerWeapon, bodypart, stealth ) if ( killer ) then local account = getPlayerAccount ( killer ) if ( killer ~= source ) then setAccountData ( account, "killsdeathsratio.Kills", tonumber ( getAccountData ( account,"killdeathsratio.Kills" ) or 0 ) + 1 ) setElementData ( killer, "Kills", tonumber ( getAccountData ( account,"killsdeathsratio.Kills" ) ) ) setElementData ( killer, "Ratio", tonumber ( ( getElementData ( killer, "Kills" ) or 0 ) / ( getElementData ( source, "Deaths" ) or 0 ) ) ) end else local accountSource = getPlayerAccount ( source ) setAccountData ( accountSource, "killsdeathsratio.Deaths", tonumber ( getAccountData ( accountSource, "killsdeathsratio.Deaths" ) or 0 ) + 1 ) setElementData ( source, "Deaths", tonumber ( getAccountData ( accountSource, "killsdeathsratio.Deaths" ) ) ) setElementData ( source, "Ratio", ( getElementData ( source, "Kills" ) or 0 ) / ( getElementData ( source, "Deaths" ) or 0 ) ) end end ) addEventHandler ( "onPlayerLogin", root, function ( thePreviousAccount, theCurrentAccount, autoLogin ) local account = getPlayerAccount ( source ) if ( not getAccountData ( account, "killsdeathsratio.Kills" ) and not getAccountData ( account, "killsdeathsratio.Deaths" ) ) then setAccountData ( account,"killsdeathsratio.Kills", 0 ) setAccountData ( account,"killsdeathsratio.Deaths", 0 ) end setElementData ( source, "Deaths",tonumber ( getAccountData ( account, "killsdeathsratio.Deaths" ) or 0 ) ) setElementData ( source, "Kills",tonumber ( getAccountData ( account, "killsdeathsratio.Kills" ) or 0 ) ) setElementData ( source, "Ratio", ( getElementData ( source, "Kills" ) or 0 ) / ( getElementData ( source, "Deaths" ) or 0 ) ) end ) addEventHandler( "onResourceStart",resourceRoot, function( ) outputDebugString( "add Total Kills to scoreboard Return: "..tostring( call( getResourceFromName("Scoreboard"), "addScoreboardColumn", "Kills",root,5, 0.070 ) ) ) outputDebugString( "add Total Kills to scoreboard Return: "..tostring( call( getResourceFromName("Scoreboard"), "addScoreboardColumn", "Deaths",root,5, 0.070 ) ) ) outputDebugString( "add Ratio to scoreboard Return: "..tostring( call( getResourceFromName("Scoreboard"), "addScoreboardColumn", "Ratio",root,5, 0.070 ) ) ) end ) Link to comment
MTA Team 0xCiBeR Posted January 28, 2014 MTA Team Share Posted January 28, 2014 As for the order check the export variables: bool scoreboardAddColumn ( string name, [ element forElement = getRootElement(), int width = 70, string friendlyName = name, int priority = slot after "name" column ] ) Priority is were you should set the order for the column Link to comment
xeon17 Posted January 28, 2014 Author Share Posted January 28, 2014 Thanks Castilo & CiBeR for your help script working perfect now without bugs Link to comment
MTA Team 0xCiBeR Posted January 28, 2014 MTA Team Share Posted January 28, 2014 You're Welcome Dude. Link to comment
xeon17 Posted May 10, 2014 Author Share Posted May 10, 2014 Script doesen't save kills anymore.. please help ? i no have idea why.. it worked great. Link to comment
Castillo Posted May 10, 2014 Share Posted May 10, 2014 Have you changed anything on it? if so, then post the new script. Link to comment
xeon17 Posted May 10, 2014 Author Share Posted May 10, 2014 addEventHandler ( "onPlayerWasted", root, function ( totalAmmo, killer, killerWeapon, bodypart, stealth ) if ( killer ) then local account = getPlayerAccount ( killer ) if ( killer ~= source ) then setAccountData ( account, "killsdeathsratio.Kills", tonumber ( getAccountData ( account,"killdeathsratio.Kills" ) or 0 ) + 1 ) setElementData ( killer, "Kills", tonumber ( getAccountData ( account,"killsdeathsratio.Kills" ) ) ) setElementData ( killer, "Ratio", tonumber ( ( getElementData ( killer, "Kills" ) or 0 ) / ( getElementData ( source, "Deaths" ) or 0 ) ) ) end else local accountSource = getPlayerAccount ( source ) setAccountData ( accountSource, "killsdeathsratio.Deaths", tonumber ( getAccountData ( accountSource, "killsdeathsratio.Deaths" ) or 0 ) + 1 ) setElementData ( source, "Deaths", tonumber ( getAccountData ( accountSource, "killsdeathsratio.Deaths" ) ) ) setElementData ( source, "Ratio", ( getElementData ( source, "Kills" ) or 0 ) / ( getElementData ( source, "Deaths" ) or 0 ) ) end end ) addEventHandler ( "onPlayerLogin", root, function ( thePreviousAccount, theCurrentAccount, autoLogin ) local account = getPlayerAccount ( source ) if ( not getAccountData ( account, "killsdeathsratio.Kills" ) and not getAccountData ( account, "killsdeathsratio.Deaths" ) ) then setAccountData ( account,"killsdeathsratio.Kills", 0 ) setAccountData ( account,"killsdeathsratio.Deaths", 0 ) end setElementData ( source, "Deaths",tonumber ( getAccountData ( account, "killsdeathsratio.Deaths" ) or 0 ) ) setElementData ( source, "Kills",tonumber ( getAccountData ( account, "killsdeathsratio.Kills" ) or 0 ) ) setElementData ( source, "Ratio", ( getElementData ( source, "Kills" ) or 0 ) / ( getElementData ( source, "Deaths" ) or 0 ) ) end ) addEventHandler( "onResourceStart",resourceRoot, function( ) outputDebugString( "add Total Kills to scoreboard Return: "..tostring( call( getResourceFromName("Scoreboard"), "addScoreboardColumn", "Kills",root,5, 0.070 ) ) ) outputDebugString( "add Total Kills to scoreboard Return: "..tostring( call( getResourceFromName("Scoreboard"), "addScoreboardColumn", "Deaths",root,5, 0.070 ) ) ) outputDebugString( "add Ratio to scoreboard Return: "..tostring( call( getResourceFromName("Scoreboard"), "addScoreboardColumn", "Ratio",root,5, 0.070 ) ) ) end ) "EufraT" name="Event" version="2.0.0" type="script" description="Bases"/> As think i no changed nothing , i only use the script on a other server , it saves deaths but no kills 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