Jump to content

Total Kills / Deaths


Recommended Posts

Hey all, I wrote this within an hour... I realized that the scoreboard columns aren't creating... I haven't ever called a function before... Other than admin panel flags...

function addTotalKill(totalAmmo, killer, killerWeapon, bodypart, stealth) 
local account = getPlayerAccount (killer) 
if (account) and (killer) then 
setAccountData(account,"totalkillsdeaths.kills",getAccountData(account,"totalkillsdeaths.kills")+1) 
setElementData(killer, "Total Kills", getAccountData(account,"totalkillsdeaths.kills")) 
end 
end 
addEventHandler ("onPlayerWasted", getRootElement(), addTotalKill) 
  
function addTotalDeath(totalAmmo, killer, killerWeapon, bodypart, stealth) 
local account = getPlayerAccount (source) 
if (account) then 
setAccountData(account,"totalkillsdeaths.Deaths",getAccountData(account,"totalkillsdeaths.Deaths")+1) 
setElementData(source, "Total Deaths", getAccountData(account,"totalkillsdeaths.Deaths")) 
end 
end 
addEventHandler ("onPlayerWasted", getRootElement(), addTotalKill) 
  
function checkAccountKillsDeaths(thePreviousAccount, theCurrentAccount, autoLogin) 
if (getAccountData(theCurrentAccount,"totalkillsdeaths.kills") == nil) and (getAccountData(theCurrentAccount,"totalkillsdeaths.deaths") == nil) then 
setAccountData(theCurrentAccount,"totalkillsdeaths.kills",0) 
setAccountData(theCurrentAccount,"totalkillsdeaths.deaths",0) 
end 
end 
addEventHandler("onPlayerLogin",getRootElement(),checkAccountKillsDeaths) 
  
function addScoreboardItems() 
call(getResourceFromName("scoreboard"), "scoreboardAddColumn", "Total Kills",getRootElement(),100,"Total Kills",3) 
call(getResourceFromName("scoreboard"), "scoreboardAddColumn", "Total Deaths",getRootElement(),100,"Total Kills",3) 
end 
addEventHandler("onResourceStart",getRootElement(),addScoreboardItems) 

Thanks in advance,

Chris

Link to comment

Capy i tried your thing...

function addScoreboardItems() 
call(getResourceFromName("scoreboard"), "addScoreboardColumn", "Total Kills",getRootElement(),1, 0.5) 
call(getResourceFromName("scoreboard"), "addScoreboardColumn", "Total Deaths",getRootElement(),1, 0.5) 
end 
addEventHandler("onResourceStart",getRootElement(),addScoreboardItems) 

It still not creating columns :S

Link to comment

/debugscript 3 not say errors?

maybe resource scoreboard not running

Check return value call function

And you don't need use getRootElement() in event "onResourceStart" you need use resourceRoot

Otherwise every start resource add columns to scoreboard

Edited by Guest
Link to comment
/debugscript 3 not say errors?

maybe resource scoreboard not running

Check return value call function

And you don't need use getRootElement() you need use resourceRoot

Otherwise every start resource add columns to scoreboard

Debug shows nothing,

um resource/s are defiantly running :S

and What about return lol?

Thanks for the info on resourceRoot.

So What do u mean Check return value call function :| I have never needed to call before in scripts ive made :S

Link to comment
function addScoreboardItems( ) 
    outputDebugString( "add Total Kills to scoreboard Return: "..tostring(  
        call( getResourceFromName("scoreboard"), "addScoreboardColumn", "Total Kills",root,1, 0.5 ) 
    ) )  
    outputDebugString( "add Total Deaths to scoreboard Return: "..tostring(  
        call( getResourceFromName("scoreboard"), "addScoreboardColumn", "Total Deaths",root,1, 0.5 ) 
    ) )  
end 
addEventHandler( "onResourceStart",resourceRoot,addScoreboardItems ) 

EDIT:I update upper post please read. :D

EDIT2:In future if you need debug for example client side script read clientscript.log in folder:MTA_FOLDER\MTA\clientscript.log this is rly useful.

Edited by Guest
Link to comment
function addScoreboardItems( ) 
    outputDebugString( "add Total Kills to scoreboard Return: "..tostring(  
        call( getResourceFromName("scoreboard"), "addScoreboardColumn", "Total Kills",root,1, 0.5 ) 
    ) )  
    outputDebugString( "add Total Deaths to scoreboard Return: "..tostring(  
        call( getResourceFromName("scoreboard"), "addScoreboardColumn", "Total Deaths",root,1, 0.5 ) 
    ) )  
end 
addEventHandler( "onResourceStart",resourceRoot,addScoreboardItems ) 

EDIT:I update upper post please read. :D

Oh god nothing at all no debug :S Is something wrong :S :S, um, btw my dxscoreboard is named Scoreboard :S... Idk whats wrong :|

Link to comment

Hi,

function addTotalKill(totalAmmo, killer, killerWeapon, bodypart, stealth) 
local account = getPlayerAccount (killer) 
if (account) and (killer) then 
setAccountData(account,"totalkillsdeaths.kills",getAccountData(account,"totalkillsdeaths.kills")+1) 
setElementData(killer, "Total Kills", getAccountData(account,"totalkillsdeaths.kills")) 
end 
end 
addEventHandler ("onPlayerWasted", getRootElement(), addTotalKill) 
  
function addTotalDeath(totalAmmo, killer, killerWeapon, bodypart, stealth) 
local account = getPlayerAccount (source) 
if (account) then 
setAccountData(account,"totalkillsdeaths.Deaths",getAccountData(account,"totalkillsdeaths.Deaths")+1) 
setElementData(source, "Total Deaths", getAccountData(account,"totalkillsdeaths.Deaths")) 
end 
end 
addEventHandler ("onPlayerWasted", getRootElement(), addTotalKill) 
  
function checkAccountKillsDeaths(thePreviousAccount, theCurrentAccount, autoLogin) 
if (getAccountData(theCurrentAccount,"totalkillsdeaths.kills") == nil) and (getAccountData(theCurrentAccount,"totalkillsdeaths.deaths") == nil) then 
setAccountData(theCurrentAccount,"totalkillsdeaths.kills",0) 
setAccountData(theCurrentAccount,"totalkillsdeaths.deaths",0) 
end 
end 
addEventHandler("onPlayerLogin",getRootElement(),checkAccountKillsDeaths) 
  
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), 
function() 
    call(getResourceFromName("scoreboard"), "addScoreboardColumn", "Total Kills",getRootElement(),1) 
    call(getResourceFromName("scoreboard"), "addScoreboardColumn", "Total Deaths",getRootElement(),2) 
end) 
  

120104053027515581.jpg

Edited by Guest
Link to comment

Named Scoreboard?

Remember case sensitive.

function addScoreboardItems( ) 
    outputDebugString( "add Total Kills to scoreboard Return: "..tostring(  
        call( getResourceFromName("Scoreboard"), "addScoreboardColumn", "Total Kills",root,1, 0.5 ) 
    ) )  
    outputDebugString( "add Total Deaths to scoreboard Return: "..tostring(  
        call( getResourceFromName("Scoreboard"), "addScoreboardColumn", "Total Deaths",root,1, 0.5 ) 
    ) )  
end 
addEventHandler( "onResourceStart",resourceRoot,addScoreboardItems ) 

Read my upper post i update.

Link to comment

omg, im the biggest retard! I just checked the meta :S Well now i know it creates the columns. The only thing not working is the kill data. Do you see any issues with it?

Ive changed it a bit more:

function addTotalKill(totalAmmo, killer, killerWeapon, bodypart, stealth) 
local account = getPlayerAccount (killer) 
if (account) and (killer) then 
setAccountData(account,"totalkillsdeaths.kills",getAccountData(account,"totalkillsdeaths.kills")+1) 
setElementData(killer, "T/K", getAccountData(account,"totalkillsdeaths.kills")) 
end 
end 
addEventHandler ("onPlayerWasted", getRootElement(), addTotalKill) 
  
function addTotalDeath(totalAmmo, killer, killerWeapon, bodypart, stealth) 
local account = getPlayerAccount (source) 
if (account) then 
setAccountData(account,"totalkillsdeaths.Deaths",getAccountData(account,"totalkillsdeaths.deaths")+1) 
setElementData(source, "T/K", getAccountData(account,"totalkillsdeaths.deaths")+1) 
end 
end 
addEventHandler ("onPlayerWasted", getRootElement(), addTotalDeath) 
  
function checkAccountKillsDeaths(thePreviousAccount, theCurrentAccount, autoLogin) 
if (getAccountData(theCurrentAccount,"totalkillsdeaths.kills") == nil) and (getAccountData(theCurrentAccount,"totalkillsdeaths.deaths") == nil) then 
setAccountData(theCurrentAccount,"totalkillsdeaths.kills",0) 
setAccountData(theCurrentAccount,"totalkillsdeaths.deaths",0) 
end 
end 
addEventHandler("onPlayerLogin",getRootElement(),checkAccountKillsDeaths) 
  
function addScoreboardItems( ) 
    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 
addEventHandler( "onResourceStart",resourceRoot,addScoreboardItems ) 

:S this doesnt work

function checkAccountKillsDeaths(thePreviousAccount, theCurrentAccount, autoLogin)

if (getAccountData(theCurrentAccount,"totalkillsdeaths.kills") == nil) and (getAccountData(theCurrentAccount,"totalkillsdeaths.deaths") == nil) then

setAccountData(theCurrentAccount,"totalkillsdeaths.kills",0)

setAccountData(theCurrentAccount,"totalkillsdeaths.deaths",0)

end

end

addEventHandler("onPlayerLogin",getRootElement(),checkAccountKillsDeaths)

Ok AFK...

Edited by Guest
Link to comment

try:

addEventHandler ( "onPlayerWasted", root,  
    function( totalAmmo, killer, killerWeapon, bodypart, stealth ) 
        local account = getPlayerAccount ( killer ) 
        if account and isElement( killer ) then 
            setAccountData( account,"totalkillsdeaths.kills",getAccountData( account,"totalkillsdeaths.kills" )+1 ) 
            setAccountData( account,"totalkillsdeaths.Deaths",getAccountData(account,"totalkillsdeaths.Deaths")+1) 
            setElementData( killer, "T/K", tonumber( getAccountData( account,"totalkillsdeaths.kills" ) or 0 ) ) 
            setElementData( killer, "T/D", tonumber( getAccountData( account,"totalkillsdeaths.Deaths" ) or 0 ) ) 
        end 
    end 
)        
  
addEventHandler( "onPlayerLogin",root, 
    function( thePreviousAccount, theCurrentAccount, autoLogin )  
        if not getAccountData( theCurrentAccount,"totalkillsdeaths.kills" ) and not getAccountData( theCurrentAccount,"totalkillsdeaths.deaths" ) then 
            setAccountData( theCurrentAccount,"totalkillsdeaths.kills",0) 
            setAccountData( theCurrentAccount,"totalkillsdeaths.deaths",0) 
        end  
    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 
)  
  

EDIT:code updated

EDIT2:if not getAccountData return false not nil

Edited by Guest
Link to comment

No ones is working and kenix :| I think u miss understand...!

addEventHandler ( "onPlayerWasted", root,

function( totalAmmo, killer, killerWeapon, bodypart, stealth )

local account = getPlayerAccount ( killer )

if account and isElement( killer ) then

setAccountData( account,"totalkillsdeaths.kills",getAccountData( account,"totalkillsdeaths.kills" )+1 )

setAccountData( account,"totalkillsdeaths.Deaths",getAccountData(account,"totalkillsdeaths.Deaths")+1)

setElementData( killer, "T/K", tonumber( getAccountData( account,"totalkillsdeaths.kills" ) or 0 ) )

setElementData( killer, "T/D", tonumber( getAccountData( account,"totalkillsdeaths.Deaths" ) or 0 ) )

end

end

)

Its meant to log kills and deaths separately, :| This adds 1 death and 1 kill. and it doesnt work :S

Link to comment

My bad -_-

I'm very tired

addEventHandler ( "onPlayerWasted", root,  
    function( totalAmmo, killer, killerWeapon, bodypart, stealth ) 
        local account = getPlayerAccount ( killer ) 
        local accountSource = getPlayerAccount ( source ) 
        if killer and killer ~= source then 
            setAccountData( account,"totalkillsdeaths.kills",getAccountData( account,"totalkillsdeaths.kills" )+1 ) 
            setElementData( killer, "T/K", tonumber( getAccountData( account,"totalkillsdeaths.kills" ) ) ) 
        else 
            setAccountData( accountSource,"totalkillsdeaths.Deaths",getAccountData(accountSource,"totalkillsdeaths.Deaths")+1) 
            setElementData( source, "T/D", tonumber( getAccountData( accountSource,"totalkillsdeaths.Deaths" ) ) ) 
        end 
    end 
)        
  
addEventHandler( "onPlayerLogin",root, 
    function( thePreviousAccount, theCurrentAccount, autoLogin )  
        if not getAccountData( theCurrentAccount,"totalkillsdeaths.kills" ) and not getAccountData( theCurrentAccount,"totalkillsdeaths.deaths" ) then 
            setAccountData( theCurrentAccount,"totalkillsdeaths.kills",0) 
            setAccountData( theCurrentAccount,"totalkillsdeaths.deaths",0) 
            setElementData( source,"T/D",0 ) 
            setElementData( source,"T/K",0 ) 
        else 
            setElementData( source,"T/D",getAccountData( theCurrentAccount,"totalkillsdeaths.kills" ) ) 
            setElementData( source,"T/K",getAccountData( theCurrentAccount,"totalkillsdeaths.deaths" ) ) 
        end 
    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 
)  
  

Edited by Guest
Link to comment

Almost kenix :| I keep relogging to get my total kills to 0... But Its not, so i think

addEventHandler( "onPlayerLogin",root, 
    function( thePreviousAccount, theCurrentAccount, autoLogin ) 
        if not getAccountData( theCurrentAccount,"totalkillsdeaths.kills" ) and not getAccountData( theCurrentAccount,"totalkillsdeaths.deaths" ) then 
            setAccountData( theCurrentAccount,"totalkillsdeaths.kills",0) 
            setAccountData( theCurrentAccount,"totalkillsdeaths.deaths",0) 
        end 
    end 

)

function is preventing everything else... Its a theory. Cause nothing is appearing in scoreboard in those columns.

Link to comment

It should work ( tested )

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 
)  
  

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