knightscript Posted January 20, 2016 Posted January 20, 2016 Hello, im trying to create a table where the players kills and deaths are saved, using this: function playercreatekillsdeaths() if not getElementData(source,"kills") then setElementData(source,"kills",0) outputDebugString("testing") end if not getElementData(source,"deaths") then setElementData(source,"deaths",0) outputDebugString("testing") end end addEventHandler("onPlayerLogin", getRootElement(), playercreatekillsdeaths) To record when the player is killed im trying to use this: function onplayerkilledplayer(source) thePlayer = getPlayerFromName (source) local count = getElementData(thePlayer,"kills") setElementData(thePlayer,"kills",count+1) end addEventHandler("onPlayerWasted", getRootElement(), onplayerkilledplayer) I really dont know how to achieve this. Thanks
knightscript Posted January 20, 2016 Author Posted January 20, 2016 Alright, i found this script on the MTA resources page (https://community.multitheftauto.com/in ... ls&id=3472) And it is working, except for 1 think, it is not showing the deaths on the table, and it shows no errors on the debugscript, here is the code if its easier for you: addEventHandler ( "onPlayerWasted", root, function( totalAmmo, killer, killerWeapon, bodypart, stealth ) if killer then local account = getPlayerAccount ( killer ) if killer ~= source then setAccountData( account,"totalkillsdeaths.Kills",tonumber( getAccountData( account,"totalkillsdeaths.Kills" ) or 0 ) +1 ) setElementData( killer, "T/K", tonumber( getAccountData( account,"totalkillsdeaths.Kills" ) ) ) end else local accountSource = getPlayerAccount ( source ) setAccountData( accountSource,"totalkillsdeaths.Deaths",tonumber( getAccountData(accountSource,"totalkillsdeaths.Deaths") or 0 ) +1 ) setElementData( source, "T/D", tonumber( getAccountData( accountSource,"totalkillsdeaths.Deaths" ) ) ) end end ) addEventHandler( "onPlayerLogin",root, function( thePreviousAccount, theCurrentAccount, autoLogin ) local account = getPlayerAccount ( source ) if not getAccountData( account,"totalkillsdeaths.Kills" ) and not getAccountData( account,"totalkillsdeaths.Deaths" ) then setAccountData( account,"totalkillsdeaths.Kills",0 ) setAccountData( account,"totalkillsdeaths.Deaths",0 ) end setElementData( source,"T/D",tonumber( getAccountData( account,"totalkillsdeaths.Deaths" ) or 0 ) ) setElementData( source,"T/K",tonumber( getAccountData( account,"totalkillsdeaths.Kills" ) or 0 ) ) end ) addEventHandler( "onResourceStart",resourceRoot, function( ) outputDebugString( "add Total Kills to scoreboard Return: "..tostring( call( getResourceFromName("Scoreboard"), "addScoreboardColumn", "T/K",root,2, 0.035 ) ) ) outputDebugString( "add Total Deaths to scoreboard Return: "..tostring( call( getResourceFromName("Scoreboard"), "addScoreboardColumn", "T/D",root,3, 0.035 ) ) ) end ) Thanks
Army@1 Posted January 21, 2016 Posted January 21, 2016 it is not showing the deaths on the table What do you mean by table? scoreboard?
Army@1 Posted January 22, 2016 Posted January 22, 2016 I have modified the script a bit and it seems to work flawlessly. -- Remove all the below comments to add kills and deaths ratio. peds = getElementsByType("ped") players = getElementsByType("player") addEventHandler ( "onPlayerWasted", root, function( totalAmmo, killer, killerWeapon, bodypart, stealth ) if killer == players and killer ~= peds and source == players and source ~= peds then local account = getPlayerAccount ( killer ) if killer ~= source then setAccountData( account,"totalkillsdeaths.Kills",tonumber( getAccountData( account,"totalkillsdeaths.Kills" ) or 0 ) +1 ) setElementData( killer, "Kills", tonumber( getAccountData( account,"totalkillsdeaths.Kills" ) ) ) -- setElementData( killer, "Ratio", tonumber(getElementData( killer, "Kills" )/getElementData( source, "Deaths") ) ) end else local accountSource = getPlayerAccount ( source ) setAccountData( accountSource,"totalkillsdeaths.Deaths",tonumber( getAccountData(accountSource,"totalkillsdeaths.Deaths") or 0 ) +1 ) setElementData( source, "Deaths", tonumber( getAccountData( accountSource,"totalkillsdeaths.Deaths" ) ) ) --setElementData( source, "Ratio", tonumber(getElementData( killer, "Kills" )/getElementData( source, "Deaths") ) ) end end ) addEventHandler( "onPlayerLogin",root, function( thePreviousAccount, theCurrentAccount, autoLogin ) local account = getPlayerAccount ( source ) if not getAccountData( account,"totalkillsdeaths.Kills" ) and not getAccountData( account,"totalkillsdeaths.Deaths" ) then setAccountData( account,"totalkillsdeaths.Kills",0 ) setAccountData( account,"totalkillsdeaths.Deaths",0 ) end setElementData( source,"Deaths",tonumber( getAccountData( account,"totalkillsdeaths.Deaths" ) or 0 ) ) setElementData( source,"Kills",tonumber( getAccountData( account,"totalkillsdeaths.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( exports.scoreboard:addScoreboardColumn('Kills',getRootElement(),4,50) --) ) --outputDebugString( "add Total Deaths to scoreboard Return: "..tostring( exports.scoreboard:addScoreboardColumn('Deaths',getRootElement(),5,50) --) ) --outputDebugString( "add Kills Deaths Ratio to scoreboard Return: "..tostring( --exports.scoreboard:addScoreboardColumn('Ratio',getRootElement(),6,50) -- ) ) end )
knightscript Posted January 22, 2016 Author Posted January 22, 2016 Hello @Army@1, i´ve just tested your code, the deaths are updating correctly but the kills aren´t, i copied the same exact code, what can be wrong?
Army@1 Posted January 23, 2016 Posted January 23, 2016 In above script, killing doesn't save when you kill your own self. Test this one. -- Remove all the below comments to add kills and deaths ratio. peds = getElementsByType("ped") players = getElementsByType("player") addEventHandler ( "onPlayerWasted", root, function( totalAmmo, killer, killerWeapon, bodypart, stealth ) if killer == players and killer ~= peds and source == players and source ~= peds then local account = getPlayerAccount ( killer ) setAccountData( account,"totalkillsdeaths.Kills",tonumber( getAccountData( account,"totalkillsdeaths.Kills" ) or 0 ) +1 ) setElementData( killer, "Kills", tonumber( getAccountData( account,"totalkillsdeaths.Kills" ) ) ) -- setElementData( killer, "Ratio", tonumber(getElementData( killer, "Kills" )/getElementData( source, "Deaths") ) ) else local accountSource = getPlayerAccount ( source ) setAccountData( accountSource,"totalkillsdeaths.Deaths",tonumber( getAccountData(accountSource,"totalkillsdeaths.Deaths") or 0 ) +1 ) setElementData( source, "Deaths", tonumber( getAccountData( accountSource,"totalkillsdeaths.Deaths" ) ) ) --setElementData( source, "Ratio", tonumber(getElementData( killer, "Kills" )/getElementData( source, "Deaths") ) ) end end ) addEventHandler( "onPlayerLogin",root, function( thePreviousAccount, theCurrentAccount, autoLogin ) local account = getPlayerAccount ( source ) if not getAccountData( account,"totalkillsdeaths.Kills" ) and not getAccountData( account,"totalkillsdeaths.Deaths" ) then setAccountData( account,"totalkillsdeaths.Kills",0 ) setAccountData( account,"totalkillsdeaths.Deaths",0 ) end setElementData( source,"Deaths",tonumber( getAccountData( account,"totalkillsdeaths.Deaths" ) or 0 ) ) setElementData( source,"Kills",tonumber( getAccountData( account,"totalkillsdeaths.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( exports.scoreboard:addScoreboardColumn('Kills',getRootElement(),4,50) --) ) --outputDebugString( "add Total Deaths to scoreboard Return: "..tostring( exports.scoreboard:addScoreboardColumn('Deaths',getRootElement(),5,50) --) ) --outputDebugString( "add Kills Deaths Ratio to scoreboard Return: "..tostring( --exports.scoreboard:addScoreboardColumn('Ratio',getRootElement(),6,50) -- ) ) end )
knightscript Posted January 23, 2016 Author Posted January 23, 2016 I didnt kill myself, i killed another player, his deaths were incremented but my kills wasn´t, what can it be?
Army@1 Posted January 23, 2016 Posted January 23, 2016 Try this one: -- Remove all the below comments to add kills and deaths ratio. addEventHandler ( "onPlayerWasted", root, function ( totalAmmo, killer, killerWeapon, bodypart, stealth ) if ( killer ) then local accountKiller = getPlayerAccount ( killer ) if ( getElementType(killer) == "player" ) then setAccountData ( accountKiller,"kills",tonumber ( getAccountData ( accountKiller,"kills" ) or 0 ) + 1 ) setElementData ( killer, "kills", tonumber ( getAccountData ( accountKiller,"kills" ) ) ) end end local accountSource = getPlayerAccount ( source ) setAccountData ( accountSource, "Deaths",tonumber ( getAccountData ( accountSource, "Deaths" ) or 0 ) +1 ) setElementData ( source, "Deaths", tonumber ( getAccountData ( accountSource, "Deaths" ) ) ) end ) addEventHandler( "onPlayerLogin",root, function( thePreviousAccount, theCurrentAccount, autoLogin ) local account = getPlayerAccount ( source ) if not getAccountData( account,"Kills" ) and not getAccountData( account,"Deaths" ) then setAccountData( account,"Kills",0 ) setAccountData( account,"Deaths",0 ) end setElementData( source,"Deaths",tonumber( getAccountData( account,"Deaths" ) or 0 ) ) setElementData( source,"Kills",tonumber( getAccountData( account,"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( exports.scoreboard:addScoreboardColumn('Kills',getRootElement(),4,50) --) ) --outputDebugString( "add Total Deaths to scoreboard Return: "..tostring( exports.scoreboard:addScoreboardColumn('Deaths',getRootElement(),5,50) --) ) --outputDebugString( "add Kills Deaths Ratio to scoreboard Return: "..tostring( --exports.scoreboard:addScoreboardColumn('Ratio',getRootElement(),6,50) -- ) ) end )
ALw7sH Posted January 23, 2016 Posted January 23, 2016 Try this one: -- Remove all the below comments to add kills and deaths ratio. addEventHandler ( "onPlayerWasted", root, function ( totalAmmo, killer, killerWeapon, bodypart, stealth ) if ( killer ) then local accountKiller = getPlayerAccount ( killer ) if ( getElementType(killer) == "player" ) then setAccountData ( accountKiller,"kills",tonumber ( getAccountData ( accountKiller,"kills" ) or 0 ) + 1 ) setElementData ( killer, "kills", tonumber ( getAccountData ( accountKiller,"kills" ) ) ) end end local accountSource = getPlayerAccount ( source ) setAccountData ( accountSource, "Deaths",tonumber ( getAccountData ( accountSource, "Deaths" ) or 0 ) +1 ) setElementData ( source, "Deaths", tonumber ( getAccountData ( accountSource, "Deaths" ) ) ) end ) addEventHandler( "onPlayerLogin",root, function( thePreviousAccount, theCurrentAccount, autoLogin ) local account = getPlayerAccount ( source ) if not getAccountData( account,"Kills" ) and not getAccountData( account,"Deaths" ) then setAccountData( account,"Kills",0 ) setAccountData( account,"Deaths",0 ) end setElementData( source,"Deaths",tonumber( getAccountData( account,"Deaths" ) or 0 ) ) setElementData( source,"Kills",tonumber( getAccountData( account,"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( exports.scoreboard:addScoreboardColumn('Kills',getRootElement(),4,50) --) ) --outputDebugString( "add Total Deaths to scoreboard Return: "..tostring( exports.scoreboard:addScoreboardColumn('Deaths',getRootElement(),5,50) --) ) --outputDebugString( "add Kills Deaths Ratio to scoreboard Return: "..tostring( --exports.scoreboard:addScoreboardColumn('Ratio',getRootElement(),6,50) -- ) ) end ) setAccountData save strings only
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