Jump to content

Help in Stats System Bug !


E-mail

Recommended Posts

Hi all see The error!

server.lua :55 attempt to prefor arithmectic on a nill value

addEventHandler("onPlayerLogin",getRootElement(), 
function () 
    local account = getPlayerAccount(source) 
    local kills = getAccountData(account,"kills") 
    local deaths = getAccountData(account,"deaths") 
    local headshots = getAccountData(account,"headshots") 
    if not kills then setAccountData(account,"kills",0) end 
    if not deaths then setAccountData(account,"deaths",0) end 
    if not headshots then setAccountData(account,"headshots",0) end 
end) 
  
addEventHandler("onPlayerJoin",root, 
function () 
    bindKey(source,"F3","down",getPlayerStats) 
end) 
  
addEventHandler("onResourceStart",resourceRoot, 
function () 
    for index, player in pairs(getElementsByType("player")) do 
        bindKey(player,"F3","down",getPlayerStats) 
    end 
end) 
  
function updatePlayerStats(ammo, attacker, weapon, bodypart) 
    updateAccountData(getPlayerAccount(source), "deaths", 1) 
    if attacker or attacker == source then 
        local account = getPlayerAccount(attacker) 
        if account and attacker and getElementType(attacker) == "player" then 
            updateAccountData(account, "kills", 1) 
            if bodypart == 9 then 
                updateAccountData(account, "headshots", 1) 
            end 
        end 
    end 
end 
addEventHandler("onPlayerWasted",getRootElement(),updatePlayerStats) 
  
function getPlayerStats(thePlayer) 
    local account = getPlayerAccount(thePlayer) 
    if not isGuestAccount(account) then 
        local kills = getAccountData(account,"kills") or 0 
        local headshots = getAccountData(account,"headshots") or 0 
        local deaths = getAccountData(account,"deaths") or 0 
        local ratio = string.format("%.2f", kills / deaths) 
        outputChatBox("[sTATS]".. getPlayerName(thePlayer) .."'s Stats: Kills: ".. tostring(kills) .." (".. tostring(headshots) .." Headshots), ".. tostring(deaths) .." Deaths, Ratio: ".. tostring(ratio).."", getRootElement(), 255, 255, 0) 
    else 
       outputChatBox("[sTATS] You must be logged in able to see your stats.",thePlayer,255,0,0) 
    end 
end 
addCommandHandler("stats",getPlayerStats) 
  
function updateAccountData(account, dataName, toUpdate) 
    if account then 
        local oldData = getAccountData(account,dataName) 
        setAccountData(account,tostring(dataName),tonumber(oldData)+tonumber(toUpdate)) 
    end 
  
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...