function fUpdatePlayerStats ( _, uAttacker, _, nBodypart )
if ( not uAttacker or uAttacker == source ) then
return
end
local uAccount = getPlayerAccount ( uAttacker )
if ( uAccount and not isGuestAccount ( uAccount ) ) then
local nKills = tonumber ( getAccountData ( uAccount, "kills" ) ) or 0
local nHeadshots = tonumber ( getAccountData ( uAccount, "headshots" ) ) or 0
setAccountData ( uAccount, "kills", nKills + 1 )
if ( nBodypart == 9 ) then
setAccountData ( uAccount, "headshots", nHeadshots + 1 )
end
end
local uAccountSource = getPlayerAccount ( source )
if ( uAccountSource and not isGuestAccount ( uAccountSource ) ) then
local nDeaths = tonumber ( getAccountData ( uAccountSource, "deaths" ) ) or 0
setAccountData ( uAccountSource, "deaths", nDeaths + 1 )
end
end
function fGetPlayerStats ( uPlayer )
local uAccount = getPlayerAccount ( uPlayer )
if ( uAccount and not isGuestAccount ( uAccount ) ) then
local nKills = getAccountData ( uAccount, "kills" ) or 0
local nHeadshots = getAccountData ( uAccount, "headshots" ) or 0
local nDeaths = getAccountData ( uAccount, "deaths" ) or 0
local nRatio = math.max( 0, math.min( 100, math.floor( nKills / ( nDeaths + nKills ) * 100 ) ) )
outputChatBox ( "[sTATS]".. getPlayerName ( uPlayer ) .."'s Stats: Kills: ".. tostring ( nKills ) .." (".. tostring ( nHeadshots ) .." Headshots), ".. tostring ( deaths ) .." Deaths, Ratio: ".. tostring ( nRatio ), root, 50, 255, 0 )
end
end
addEventHandler ( "onPlayerWasted", root, fUpdatePlayerStats )
addCommandHandler ( "stats", fGetPlayerStats )
addCommandHandler ( "st", fGetPlayerStats )
Updated.
SolidSnake14,Your code have syntax errors and ratio calculation wrong too.