Jump to content

Race Stats Again..


GanJaRuleZ

Recommended Posts

Posted (edited)

Hi allz, In the last week , i worked just on the race stats , but i can't make it working -.-'

Here is the script :

function DestructionWin() 
    local alivePlayers = getAlivePlayers() 
        if #alivePlayers == 1 then 
        local account = getPlayerAccount(alivePlayers[1]) 
        if isGuestAccount(account) then return end 
            local playername = getPlayerName(alivePlayers[1]) 
            setAccountData(account,"Race Wins",tostring(raceWins)+1) 
            outputChatBox ( "#FFA824The player " .. playername .. " won!", getRootElement(), 255, 255, 255, true ) 
end 
  
addEventHandler("onPlayerWasted", getRootElement(), 
function() 
        local account = getPlayerAccount(alivePlayers[1]) 
        if isGuestAccount(account) then return end 
        setAccountData(account,"Race Loses",tostring(raceLoses)+1) 
end) 
  
  
function updateTimePlayed() 
    setTimer(updateTimePlayed,1000,1) 
    if isGuestAccount(account) then return end 
        local account = getPlayerAccount(source) 
        local timePlayed = getAccountData(account, "Time played") 
        if (not timePlayed) then setAccountData(account, "Time played","0:0:0") end 
        local hours, mins, secs = unpack(split(timePlayed, ":")) 
        local hours = tonumber(hours) 
        local mins = tonumber(mins) 
        local secs = tonumber(secs) 
        if (hours and mins and secs) then 
            local newsec = secs + 1 
            if ( newsec >= 60 ) then 
                newsec = 0 
                mins = mins + 1 
            end 
            if ( mins >= 60 ) then 
                mins = 0 
                hours = hours + 1 
            end 
            setAccountData ( account, "Time played", tostring(hours) ..":".. tostring(mins) ..":".. tostring(newsec)) 
        end 
    end 
end 
setTimer(updateTimePlayed,1000,1) 
  
function ratioCalculator() 
     local KDR_DECIMAL_PLACES = 2 
    local account = getPlayerAccount(source) 
    local raceLoses = getAccountData(account,"Race Loses") 
    if raceLoses == 0 then 
        setAccountData(account, "Ratio", "-") 
    else 
        local kdr = round(getAccountData(account, "Race Wins") / raceLoses, KDR_DECIMAL_PLACES) 
        setAccountData(account, "Ratio", tostring(kdr)) 
    end 
end 
  
  
addEventHandler("onPlayerLogin",root, 
function () 
    local account = getPlayerAccount(source) 
    if isGuestAccount(account) then return end 
    local raceWins = getAccountData(account,"Race Wins") 
    local raceLoses = getAccountData(account,"Race Loses") 
    local timePlayed = getAccountData(account, "Time played") 
    local ratio = getAccountData(account, "Ratio") 
    if raceWins then 
        setAccountData(account,"Race Wins",tostring(raceWins)) 
    else 
        setAccountData(account,"Race Wins",0)     
    if raceLoses then 
        setAccountData(account,"Race Loses",tostring(raceLoses)) 
    else 
        setAccountData(account,"Race Loses",0) 
    if timePlayed then 
        setAccountData ( account, "Time played", tostring(hours) ..":".. tostring(mins) ..":".. tostring(newsec)) 
    else 
        setAccountData(account, "Time played","0:0:0")  
    if ratio then 
        setAccountData(account,"Ratio",tostring(ratio)) 
    else 
        setAccountData(account,"Ratio",0) 
  
end) 
  
function publicstatsinfo() 
    local account = getPlayerAccount(source) 
    if isGuestAccount(account) then return end 
    local askdname = getPlayerName(source) 
    local wins = getAccountData(account, "Race Wins") 
    local loses = getAccountData(account, "Race Loses") 
    local ratio = getAccountData(account, "Ratio") 
    local timePlayed = getAccountData(account, "Time played") 
    if loses and wins then 
    outputChatBox("#FFA824*" .. askdname .. " won " .. wins .. " times and he losed " .. loses .. " times ,his ratio is " .. ratio  " and the total time he played is : " .. timePlayed .. ", getRootElement(), 255, 12, 15,true) 
    else 
    setAccountData(account, "RaceWins" , 0) 
    setAccountData(account, "RaceLoses" , 0) 
   end 
end 
addEvent("stats", true) 
addEventHandler("stats", getRootElement(), publicstatsinfo) 
  
function checkCommand(message, messageType) 
    if (messageType == 0) then 
        if (message == "!stats") then 
            cancelEvent() 
            setTimer(triggerEvent, 100, 1, "stats", source) 
        end 
    end 
end 
addEventHandler("onPlayerChat", getRootElement(), checkCommand) 
  
 

And the error is :

SCRIPT ERROR: stats\stats.lua:83: unexpected symbol near ')' 

Btw : The time played belongs to Solidsnake

Thank you.

Edited by Guest
Posted

You have forget "end"...

  
addEventHandler("onPlayerLogin",root, 
function () 
    local account = getPlayerAccount(source) 
    if isGuestAccount(account) then return end 
    local raceWins = getAccountData(account,"Race Wins") 
    local raceLoses = getAccountData(account,"Race Loses") 
    local timePlayed = getAccountData(account, "Time played") 
    local ratio = getAccountData(account, "Ratio") 
    if raceWins then 
        setAccountData(account,"Race Wins",tostring(raceWins)) 
    else 
        setAccountData(account,"Race Wins",0)     
    if raceLoses then 
        setAccountData(account,"Race Loses",tostring(raceLoses)) 
    else 
        setAccountData(account,"Race Loses",0) 
    if timePlayed then 
        setAccountData ( account, "Time played", tostring(hours) ..":".. tostring(mins) ..":".. tostring(newsec)) 
    else 
        setAccountData(account, "Time played","0:0:0") 
    if ratio then 
        setAccountData(account,"Ratio",tostring(ratio)) 
    else 
        setAccountData(account,"Ratio",0) 
    end 
end) 
  

Posted

You also forgot something here:

outputChatBox("#FFA824*" .. askdname .. " won " .. wins .. " times and he losed " .. loses .. " times ,his ratio is " .. ratio  " and the total time he played is : " .. timePlayed .. ", getRootElement(), 255, 12, 15,true)

  
function publicstatsinfo() 
    local account = getPlayerAccount(source) 
    if isGuestAccount(account) then return end 
    local askdname = getPlayerName(source) 
    local wins = getAccountData(account, "Race Wins") 
    local loses = getAccountData(account, "Race Loses") 
    local ratio = getAccountData(account, "Ratio") 
    local timePlayed = getAccountData(account, "Time played") 
    if loses and wins then 
    outputChatBox("#FFA824*" .. askdname .. " won " .. wins .. " times and he losed " .. loses .. " times ,his ratio is " .. ratio  " and the total time he played is : " .. timePlayed, getRootElement(), 255, 12, 15,true) 
   else 
   setAccountData(account, "RaceWins" , 0) 
   setAccountData(account, "RaceLoses" , 0) 
  end 
end 
addEvent("stats", true) 
addEventHandler("stats", getRootElement(), publicstatsinfo) 
  

Posted
function publicstatsinfo() 
    local account = getPlayerAccount(source) 
    if isGuestAccount(account) then return end 
    local askdname = getPlayerName(source) 
    local wins = getAccountData(account, "Race Wins") 
    local loses = getAccountData(account, "Race Loses") 
    local ratio = getAccountData(account, "Ratio") 
    local timePlayed = getAccountData(account, "Time played") 
    if loses and wins then 
        outputChatBox("#FFA824*" .. askdname .. " won " .. wins .. " times and he/she lost " .. loses .. " times, his/her ratio is " .. ratio .. " and the total time played he/she is: " .. timePlayed, getRootElement(), 255, 12, 15, true) 
    else 
        setAccountData(account, "RaceWins" , 0) 
        setAccountData(account, "RaceLoses" , 0) 
    end 
end 
addEvent("stats", true) 
addEventHandler("stats", getRootElement(), publicstatsinfo) 

Posted

Use myonlake script plus use this:

addEventHandler("onPlayerLogin",root, 
function () 
    local account = getPlayerAccount(source) 
    if isGuestAccount(account) then return end 
    local raceWins = getAccountData(account,"Race Wins") 
    local raceLoses = getAccountData(account,"Race Loses") 
    local timePlayed = getAccountData(account, "Time played") 
    local ratio = getAccountData(account, "Ratio") 
    if raceWins then 
        setAccountData(account,"Race Wins",tostring(raceWins)) 
    else 
        setAccountData(account,"Race Wins",0)     
    end 
    if raceLoses then 
        setAccountData(account,"Race Loses",tostring(raceLoses)) 
    else 
        setAccountData(account,"Race Loses",0) 
    end 
    if timePlayed then 
        setAccountData ( account, "Time played", tostring(hours) ..":".. tostring(mins) ..":".. tostring(newsec)) 
    else 
        setAccountData(account, "Time played","0:0:0") 
    end 
    if ratio then 
        setAccountData(account,"Ratio",tostring(ratio)) 
    else 
        setAccountData(account,"Ratio",0) 
    end 
  
end) 
  
 

You forgot to close of the if's!

Posted

Well , i had a bit of free time and i tested it , it gives the following error :

WARNING: stats\stats.lua:43: Bad argument @ 'setTimer' [Expected function at argument 1 , got nil] 

New script

function DestructionWin() 
    local alivePlayers = getAlivePlayers() 
        if #alivePlayers == 1 then 
        local account = getPlayerAccount(alivePlayers[1]) 
        if isGuestAccount(account) then return end 
            local playername = getPlayerName(alivePlayers[1]) 
            setAccountData(account,"Race Wins",tostring(raceWins)+1) 
            outputChatBox ( "#FFA824The player " .. playername .. " won!", getRootElement(), 255, 255, 255, true ) 
end 
  
addEventHandler("onPlayerWasted", getRootElement(), 
function() 
        local account = getPlayerAccount(alivePlayers[1]) 
        if isGuestAccount(account) then return end 
        setAccountData(account,"Race Loses",tostring(raceLoses)+1) 
end) 
  
  
function updateTimePlayed() 
    setTimer(updateTimePlayed,1000,1) 
    if isGuestAccount(account) then return end 
        local account = getPlayerAccount(source) 
        local timePlayed = getAccountData(account, "Time played") 
        if (not timePlayed) then setAccountData(account, "Time played","0:0:0") end 
        local hours, mins, secs = unpack(split(timePlayed, ":")) 
        local hours = tonumber(hours) 
        local mins = tonumber(mins) 
        local secs = tonumber(secs) 
        if (hours and mins and secs) then 
            local newsec = secs + 1 
            if ( newsec >= 60 ) then 
                newsec = 0 
                mins = mins + 1 
            end 
            if ( mins >= 60 ) then 
                mins = 0 
                hours = hours + 1 
            end 
            setAccountData ( account, "Time played", tostring(hours) ..":".. tostring(mins) ..":".. tostring(newsec)) 
        end 
    end 
end 
setTimer(updateTimePlayed,1000,1) 
  
function ratioCalculator() 
     local KDR_DECIMAL_PLACES = 2 
    local account = getPlayerAccount(source) 
    local raceLoses = getAccountData(account,"Race Loses") 
    if raceLoses == 0 then 
        setAccountData(account, "Ratio", "-") 
    else 
        local kdr = round(getAccountData(account, "Race Wins") / raceLoses, KDR_DECIMAL_PLACES) 
        setAccountData(account, "Ratio", tostring(kdr)) 
    end 
end 
  
  
addEventHandler("onPlayerLogin",root, 
function () 
    local account = getPlayerAccount(source) 
    if isGuestAccount(account) then return end 
    local raceWins = getAccountData(account,"Race Wins") 
    local raceLoses = getAccountData(account,"Race Loses") 
    local timePlayed = getAccountData(account, "Time played") 
    local ratio = getAccountData(account, "Ratio") 
    if raceWins then 
        setAccountData(account,"Race Wins",tostring(raceWins)) 
    else 
        setAccountData(account,"Race Wins",0)     
    end 
    if raceLoses then 
        setAccountData(account,"Race Loses",tostring(raceLoses)) 
    else 
        setAccountData(account,"Race Loses",0) 
    end 
    if timePlayed then 
        setAccountData ( account, "Time played", tostring(hours) ..":".. tostring(mins) ..":".. tostring(newsec)) 
    else 
        setAccountData(account, "Time played","0:0:0") 
    end 
    if ratio then 
        setAccountData(account,"Ratio",tostring(ratio)) 
    else 
        setAccountData(account,"Ratio",0) 
    end 
end) 
  
  
function publicstatsinfo() 
    local account = getPlayerAccount(source) 
    if isGuestAccount(account) then return end 
    local askdname = getPlayerName(source) 
    local wins = getAccountData(account, "Race Wins") 
    local loses = getAccountData(account, "Race Loses") 
    local ratio = getAccountData(account, "Ratio") 
    local timePlayed = getAccountData(account, "Time played") 
    if loses and wins then 
        outputChatBox("#FFA824*" .. askdname .. " won " .. wins .. " times and he/she lost " .. loses .. " times, his/her ratio is " .. ratio .. " and the total time played he/she is: " .. timePlayed, getRootElement(), 255, 12, 15, true) 
    else 
         outputChatBox("*You don't losed or won" , getRootElement(), 255, 12, 15, true) 
    end 
end 
addEvent("stats", true) 
addEventHandler("stats", getRootElement(), publicstatsinfo) 
  
function checkCommand(message, messageType) 
    if (messageType == 0) then 
        if (message == "!stats") then 
            cancelEvent() 
            setTimer(triggerEvent, 100, 1, "stats", source) 
        end 
    end 
end 
addEventHandler("onPlayerChat", getRootElement(), checkCommand) 

Posted

GanJa, actually it was an error.

function DestructionWin() 
    local alivePlayers = getAlivePlayers() 
        if #alivePlayers == 1 then 
        local account = getPlayerAccount(alivePlayers[1]) 
        if isGuestAccount(account) then return end 
            local playername = getPlayerName(alivePlayers[1]) 
            setAccountData(account,"Race Wins",tostring(raceWins)+1) 
            outputChatBox ( "#FFA824The player " .. playername .. " won!", getRootElement(), 255, 255, 255, true ) 
end 
  
addEventHandler("onPlayerWasted", getRootElement(), 
function() 
        local account = getPlayerAccount(alivePlayers[1]) 
        if isGuestAccount(account) then return end 
        setAccountData(account,"Race Loses",tostring(raceLoses)+1) 
end) 
  
  
function updateTimePlayed() 
    if isGuestAccount(account) then return end 
        local account = getPlayerAccount(source) 
        local timePlayed = getAccountData(account, "Time played") 
        if (not timePlayed) then setAccountData(account, "Time played","0:0:0") end 
        local hours, mins, secs = unpack(split(timePlayed, ":")) 
        local hours = tonumber(hours) 
        local mins = tonumber(mins) 
        local secs = tonumber(secs) 
        if (hours and mins and secs) then 
            local newsec = secs + 1 
            if ( newsec >= 60 ) then 
                newsec = 0 
                mins = mins + 1 
            end 
            if ( mins >= 60 ) then 
                mins = 0 
                hours = hours + 1 
            end 
            setAccountData ( account, "Time played", tostring(hours) ..":".. tostring(mins) ..":".. tostring(newsec)) 
        end 
    end 
end 
setTimer(updateTimePlayed,1000,1) 
  
function ratioCalculator() 
     local KDR_DECIMAL_PLACES = 2 
    local account = getPlayerAccount(source) 
    local raceLoses = getAccountData(account,"Race Loses") 
    if raceLoses == 0 then 
        setAccountData(account, "Ratio", "-") 
    else 
        local kdr = round(getAccountData(account, "Race Wins") / raceLoses, KDR_DECIMAL_PLACES) 
        setAccountData(account, "Ratio", tostring(kdr)) 
    end 
end 
  
  
addEventHandler("onPlayerLogin",root, 
function () 
    local account = getPlayerAccount(source) 
    if isGuestAccount(account) then return end 
    local raceWins = getAccountData(account,"Race Wins") 
    local raceLoses = getAccountData(account,"Race Loses") 
    local timePlayed = getAccountData(account, "Time played") 
    local ratio = getAccountData(account, "Ratio") 
    if raceWins then 
        setAccountData(account,"Race Wins",tostring(raceWins)) 
    else 
        setAccountData(account,"Race Wins",0)     
    end 
    if raceLoses then 
        setAccountData(account,"Race Loses",tostring(raceLoses)) 
    else 
        setAccountData(account,"Race Loses",0) 
    end 
    if timePlayed then 
        setAccountData ( account, "Time played", tostring(hours) ..":".. tostring(mins) ..":".. tostring(newsec)) 
    else 
        setAccountData(account, "Time played","0:0:0") 
    end 
    if ratio then 
        setAccountData(account,"Ratio",tostring(ratio)) 
    else 
        setAccountData(account,"Ratio",0) 
    end 
end) 
  
  
function publicstatsinfo() 
    local account = getPlayerAccount(source) 
    if isGuestAccount(account) then return end 
    local askdname = getPlayerName(source) 
    local wins = getAccountData(account, "Race Wins") 
    local loses = getAccountData(account, "Race Loses") 
    local ratio = getAccountData(account, "Ratio") 
    local timePlayed = getAccountData(account, "Time played") 
    if loses and wins then 
        outputChatBox("#FFA824*" .. askdname .. " won " .. wins .. " times and he/she lost " .. loses .. " times, his/her ratio is " .. ratio .. " and the total time played he/she is: " .. timePlayed, getRootElement(), 255, 12, 15, true) 
    else 
         outputChatBox("*You don't losed or won" , getRootElement(), 255, 12, 15, true) 
    end 
end 
addEvent("stats", true) 
addEventHandler("stats", getRootElement(), publicstatsinfo) 
  
function checkCommand(message, messageType) 
    if (messageType == 0) then 
        if (message == "!stats") then 
            cancelEvent() 
            setTimer(triggerEvent, 100, 1, "stats", source) 
        end 
    end 
end 
addEventHandler("onPlayerChat", getRootElement(), checkCommand) 

Posted

Try:

function DestructionWin() 
    local alivePlayers = getAlivePlayers() 
        if #alivePlayers == 1 then 
        local account = getPlayerAccount(alivePlayers[1]) 
        if isGuestAccount(account) then return end 
            local playername = getPlayerName(alivePlayers[1]) 
            setAccountData(account,"Race Wins",tostring(raceWins)+1) 
            outputChatBox ( "#FFA824The player " .. playername .. " won!", getRootElement(), 255, 255, 255, true ) 
end 
  
addEventHandler("onPlayerWasted", getRootElement(), 
function() 
        local account = getPlayerAccount(alivePlayers[1]) 
        if isGuestAccount(account) then return end 
        setAccountData(account,"Race Loses",tostring(raceLoses)+1) 
end) 
  
setTimer( function() 
    if isGuestAccount(account) then return end 
        local account = getPlayerAccount(source) 
        local timePlayed = getAccountData(account, "Time played") 
        if (not timePlayed) then setAccountData(account, "Time played","0:0:0") end 
        local hours, mins, secs = unpack(split(timePlayed, ":")) 
        local hours = tonumber(hours) 
        local mins = tonumber(mins) 
        local secs = tonumber(secs) 
        if (hours and mins and secs) then 
            local newsec = secs + 1 
            if ( newsec >= 60 ) then 
                newsec = 0 
                mins = mins + 1 
            end 
            if ( mins >= 60 ) then 
                mins = 0 
                hours = hours + 1 
            end 
            setAccountData ( account, "Time played", tostring(hours) ..":".. tostring(mins) ..":".. tostring(newsec)) 
        end 
    end 
end ,1000,1) 
  
function ratioCalculator() 
     local KDR_DECIMAL_PLACES = 2 
    local account = getPlayerAccount(source) 
    local raceLoses = getAccountData(account,"Race Loses") 
    if raceLoses == 0 then 
        setAccountData(account, "Ratio", "-") 
    else 
        local kdr = round(getAccountData(account, "Race Wins") / raceLoses, KDR_DECIMAL_PLACES) 
        setAccountData(account, "Ratio", tostring(kdr)) 
    end 
end 
  
  
addEventHandler("onPlayerLogin",root, 
function () 
    local account = getPlayerAccount(source) 
    if isGuestAccount(account) then return end 
    local raceWins = getAccountData(account,"Race Wins") 
    local raceLoses = getAccountData(account,"Race Loses") 
    local timePlayed = getAccountData(account, "Time played") 
    local ratio = getAccountData(account, "Ratio") 
    if raceWins then 
        setAccountData(account,"Race Wins",tostring(raceWins)) 
    else 
        setAccountData(account,"Race Wins",0)     
    end 
    if raceLoses then 
        setAccountData(account,"Race Loses",tostring(raceLoses)) 
    else 
        setAccountData(account,"Race Loses",0) 
    end 
    if timePlayed then 
        setAccountData ( account, "Time played", tostring(hours) ..":".. tostring(mins) ..":".. tostring(newsec)) 
    else 
        setAccountData(account, "Time played","0:0:0") 
    end 
    if ratio then 
        setAccountData(account,"Ratio",tostring(ratio)) 
    else 
        setAccountData(account,"Ratio",0) 
    end 
end) 
  
  
function publicstatsinfo() 
    local account = getPlayerAccount(source) 
    if isGuestAccount(account) then return end 
    local askdname = getPlayerName(source) 
    local wins = getAccountData(account, "Race Wins") 
    local loses = getAccountData(account, "Race Loses") 
    local ratio = getAccountData(account, "Ratio") 
    local timePlayed = getAccountData(account, "Time played") 
    if loses and wins then 
        outputChatBox("#FFA824*" .. askdname .. " won " .. wins .. " times and he/she lost " .. loses .. " times, his/her ratio is " .. ratio .. " and the total time played he/she is: " .. timePlayed, getRootElement(), 255, 12, 15, true) 
    else 
         outputChatBox("*You don't losed or won" , getRootElement(), 255, 12, 15, true) 
    end 
end 
addEvent("stats", true) 
addEventHandler("stats", getRootElement(), publicstatsinfo) 
  
function checkCommand(message, messageType) 
    if (messageType == 0) then 
        if (message == "!stats") then 
            cancelEvent() 
            setTimer(triggerEvent, 100, 1, "stats", source) 
        end 
    end 
end 
addEventHandler("onPlayerChat", getRootElement(), checkCommand) 

Posted (edited)

Few missing ends there.

Edited.

function DestructionWin() 
    local alivePlayers = getAlivePlayers() 
    if #alivePlayers == 1 then 
        local account = getPlayerAccount(alivePlayers[1]) 
        if isGuestAccount(account) then return end 
        local playername = getPlayerName(alivePlayers[1]) 
        setAccountData(account,"Race Wins",tostring(raceWins)+1) 
        outputChatBox("#FFA824The player " .. playername .. " won!", getRootElement(), 255, 255, 255, true) 
    end 
end 
  
addEventHandler("onPlayerWasted", getRootElement(), 
function() 
    local account = getPlayerAccount(alivePlayers[1]) 
    if isGuestAccount(account) then return end 
    setAccountData(account, "Race Loses", tostring(raceLoses) + 1) 
end) 
  
setTimer(function() 
    if isGuestAccount(account) then return end 
    local account = getPlayerAccount(source) 
    local timePlayed = getAccountData(account, "Time played") 
    if (not timePlayed) then setAccountData(account, "Time played", "0:0:0") end 
    
    local hours, mins, secs = unpack(split(timePlayed, ":")) 
    local hours = tonumber(hours) 
    local mins = tonumber(mins) 
    local secs = tonumber(secs) 
    
    if (hours and mins and secs) then 
        local newsec = secs + 1 
         
        if (newsec >= 60) then 
            newsec = 0 
            mins = mins + 1 
        end 
         
        if (mins >= 60) then 
            mins = 0 
            hours = hours + 1 
        end 
         
        setAccountData(account, "Time played", tostring(hours) .. ":" .. tostring(mins) .. ":" .. tostring(newsec)) 
    end 
end, 1000, 1) 
  
function ratioCalculator() 
    local KDR_DECIMAL_PLACES = 2 
    local account = getPlayerAccount(source) 
    local raceLoses = getAccountData(account, "Race Loses") 
     
    if raceLoses == 0 then 
        setAccountData(account, "Ratio", "-") 
    else 
        local kdr = round(getAccountData(account, "Race Wins") / raceLoses, KDR_DECIMAL_PLACES) 
        setAccountData(account, "Ratio", tostring(kdr)) 
    end 
end 
  
addEventHandler("onPlayerLogin",root, 
function () 
    local account = getPlayerAccount(source) 
    if isGuestAccount(account) then return end 
    local raceWins = getAccountData(account,"Race Wins") 
    local raceLoses = getAccountData(account,"Race Loses") 
    local timePlayed = getAccountData(account, "Time played") 
    local ratio = getAccountData(account, "Ratio") 
     
    if raceWins then 
        setAccountData(account,"Race Wins", tostring(raceWins)) 
    else 
        setAccountData(account,"Race Wins", 0)     
    end 
     
    if raceLoses then 
        setAccountData(account,"Race Loses", tostring(raceLoses)) 
    else 
        setAccountData(account,"Race Loses", 0) 
    end 
     
    if timePlayed then 
        setAccountData(account, "Time played", tostring(hours) .. ":" .. tostring(mins) .. ":" .. tostring(newsec)) 
    else 
        setAccountData(account, "Time played", "0:0:0") 
    end 
     
    if ratio then 
        setAccountData(account,"Ratio", tostring(ratio)) 
    else 
        setAccountData(account,"Ratio", 0) 
    end 
end) 
  
function publicstatsinfo() 
    local account = getPlayerAccount(source) 
    if isGuestAccount(account) then return end 
    local askdname = getPlayerName(source) 
    local wins = getAccountData(account, "Race Wins") 
    local loses = getAccountData(account, "Race Loses") 
    local ratio = getAccountData(account, "Ratio") 
    local timePlayed = getAccountData(account, "Time played") 
    if loses and wins then 
        outputChatBox("#FFA824*" .. askdname .. " won " .. wins .. " times and he/she lost " .. loses .. " times, his/her ratio is " .. ratio .. " and the total time played he/she is: " .. timePlayed, getRootElement(), 255, 12, 15, true) 
    else 
         outputChatBox("*You don't losed or won" , getRootElement(), 255, 12, 15, true) 
    end 
end 
addEvent("stats", true) 
addEventHandler("stats", getRootElement(), publicstatsinfo) 
  
function checkCommand(message, messageType) 
    if (messageType == 0) then 
        if (message == "!stats") then 
            cancelEvent() 
            setTimer(triggerEvent, 100, 1, "stats", source) 
        end 
    end 
end 
addEventHandler("onPlayerChat", getRootElement(), checkCommand) 

Edited by Guest
Posted (edited)

try

addEventHandler( "onResourceStart",resourceRoot, 
    function( ) 
        exports.scoreboard:addScoreboardColumn( "Race Loses" ) 
        exports.scoreboard:addScoreboardColumn( "Race Wins" ) 
        exports.scoreboard:addScoreboardColumn( "Ratio" ) 
        exports.scoreboard:addScoreboardColumn( "Time played" ) 
        -- add to scoreboard 
    end 
)    
  
function DestructionWin( ) 
    local alivePlayers = getAlivePlayers( ) 
    if #alivePlayers == 1 then 
        local playername 
        local account = getPlayerAccount( alivePlayers[1] ) 
        if account then 
            if isGuestAccount( account ) then return end 
            setAccountData( account,"Race Wins",tostring( getAccountData( account,"Race Wins" ) or 0 ) +1 ) 
        end  
        playername = getPlayerName( alivePlayers[1] ) 
        outputChatBox ( "#FFA824The player " .. playername .. " won!", root, 255, 255, 255, true ) 
    end  
end 
  
addEventHandler( "onPlayerWasted", root, 
    function( ) 
        local account = getPlayerAccount( source ) 
        if account then 
            if isGuestAccount( account ) then return end 
            setAccountData( account,"Race Loses",tostring( getAccountData( account,"Race Loses" ) or 0 )+1 ) 
        end  
    end 
) 
  
function ratioCalculator( player ) 
    local KDR_DECIMAL_PLACES = 2 
    local account = getPlayerAccount( player ) 
    if account then 
        if isGuestAccount( account ) then return end 
        local raceLoses = getAccountData( account,"Race Loses" ) 
        if raceLoses == 0 then 
            setAccountData( account, "Ratio", "-") 
        else 
            local kdr = round( getAccountData( account, "Race Wins" ) / raceLoses, KDR_DECIMAL_PLACES ) 
            setAccountData( account, "Ratio", tostring(kdr)) 
        end 
    end  
end 
  
  
addEventHandler( "onPlayerLogin",root, 
    function ( ) 
        local account = getPlayerAccount( source ) 
        if account then 
            if isGuestAccount( account ) then return end 
            local raceWins = getAccountData( account,"Race Wins" ) or 0 
            local raceLoses = getAccountData( account,"Race Loses" ) or 0 
            local ratio = getAccountData( account, "Ratio" ) or 0 
             
            setElementData( account,"Race Wins",tostring( raceWins ) ) 
            setElementData( account,"Race Loses",tostring( raceLoses ) ) 
            setElementData( account,"Ratio",tostring( ratio ) ) 
        end  
        setTimer( function( player ) 
            local account = getPlayerAccount( player ) 
            if account then 
                if isGuestAccount( account ) then return end 
                local timePlayed = getAccountData( account, "Time played" ) 
                if not timePlayed then setElementData( player, "Time played","0:0:0" ) end 
                local hours, mins, secs = unpack( split( timePlayed, ":" ) ) 
                local hours = tonumber( hours ) 
                local mins = tonumber( mins ) 
                local secs = tonumber( secs ) 
                if hours and mins and secs then 
                    local newsec = secs + 1 
                    if ( newsec >= 60 ) then 
                        newsec = 0 
                        mins = mins + 1 
                    end 
                    if ( mins >= 60 ) then 
                        mins = 0 
                        hours = hours + 1 
                    end 
                    setElementData ( player, "Time played", tostring( hours ) ..":".. tostring( mins ) ..":".. tostring( newsec ) ) 
                end 
            end  
        end ,1000,1, source ) 
    end 
) 
  
  
function publicstatsinfo( ) 
    local account = getPlayerAccount( source ) 
    if isGuestAccount( account ) then return end 
    local askdname = getPlayerName( source ) 
    local wins = getAccountData( account, "Race Wins" )  
    local loses = getAccountData( account, "Race Loses" )  
    local ratio = getAccountData( account, "Ratio" ) 
    local timePlayed = getAccountData( account, "Time played" ) 
    if loses and wins then 
        outputChatBox("#FFA824*" .. askdname .. " won " .. wins .. " times and he/she lost " .. loses .. " times, his/her ratio is " .. ratio .. " and the total time played he/she is: " ..tostring( timePlayed ), root, 255, 12, 15, true) 
    else 
         outputChatBox("*You don't losed or won" , root, 255, 12, 15, true) 
    end 
end 
addEvent( "stats", true ) 
addEventHandler( "stats", root, publicstatsinfo ) 
  
function checkCommand( message, messageType ) 
    if (messageType == 0) then 
        if (message == "!stats") then 
            cancelEvent() 
            setTimer(triggerEvent, 100, 1, "stats", source) 
        end 
    end 
end 
addEventHandler( "onPlayerChat", root, checkCommand ) 

Edited by Guest
Posted

Copy my code again, saw something.

@All: Why do you all need to reply here with your codes. It's better if you let the first helper help to the end. Not that everybody just strikes in.

Posted (edited)
  
  
function DestructionWin( ) 
    local alivePlayers = getAlivePlayers( ) 
    if #alivePlayers == 1 then 
        local account = getPlayerAccount( alivePlayers[1] ) 
        if account then 
            if isGuestAccount( account ) then return end 
            setAccountData( account,"Race Wins",tostring( getAccountData( account,"Race Wins" ) or 0 ) +1 ) 
        end  
        local playername = getPlayerName( alivePlayers[1] ) 
        outputChatBox ( "#FFA824The player " .. playername .. " won!", root, 255, 255, 255, true ) 
    end  
end 
  
addEventHandler( "onPlayerWasted", root, 
    function( ) 
        local account = getPlayerAccount( source ) 
        if account then 
            if isGuestAccount( account ) then return end 
            setAccountData( account,"Race Loses",tostring( getAccountData( account,"Race Loses" ) or 0 )+1 ) 
        end  
    end 
) 
  
function ratioCalculator( player ) 
    local KDR_DECIMAL_PLACES = 2 
    local account = getPlayerAccount( player ) 
    if account then 
        if isGuestAccount( account ) then return end 
        local raceLoses = getAccountData( account,"Race Loses" ) 
        if raceLoses == 0 then 
            setAccountData( account, "Ratio", "-") 
        else 
            local kdr = round( getAccountData( account, "Race Wins" ) / raceLoses, KDR_DECIMAL_PLACES ) 
            setAccountData( account, "Ratio", tostring(kdr)) 
        end 
    end  
end 
  
addEventHandler( "onPlayerQuit",root, 
    function ( ) 
        local account = getPlayerAccount( source ) 
        if account then 
            if isGuestAccount( account ) then return end 
            local timePlayed = getElementData( source, "Time played" ) 
            if not timePlayed then setAccountData( account, "Time played","0:0:0" ) end 
            local hours, mins, secs = unpack( split( timePlayed, ":" ) ) 
            setAccountData( account, "Time played", tostring( hours or 0 ) ..":".. tostring( mins or 0 ) ..":".. tostring( secs or 0 ) ) 
        end  
    end 
) 
     
addEventHandler( "onPlayerLogin",root, 
    function ( ) 
        local account = getPlayerAccount( source ) 
        if account then 
            if isGuestAccount( account ) then return end 
            local raceWins = getAccountData( account,"Race Wins" ) or 0 
            local raceLoses = getAccountData( account,"Race Loses" ) or 0 
            local ratio = getAccountData( account, "Ratio" ) or 0 
             
            setElementData( source,"Race Wins",tostring( raceWins ) ) 
            setElementData( source,"Race Loses",tostring( raceLoses ) ) 
            setElementData( source,"Ratio",tostring( ratio ) ) 
        end  
        setTimer( function( player ) 
            local account = getPlayerAccount( player ) 
            if account then 
                if isGuestAccount( account ) then return end 
                local timePlayed = getAccountData( account, "Time played" ) 
                if not timePlayed then setElementData( player, "Time played","0:0:0" ) end 
                local hours, mins, secs = unpack( split( timePlayed, ":" ) ) 
                local hours = tonumber( hours ) or 0 
                local mins = tonumber( mins ) or 0 
                local secs = tonumber( secs ) or 0 
                local newsec 
                if hours and mins and secs then 
                    newsec = secs + 1 
                    if ( newsec >= 60 ) then 
                        newsec = 0 
                        mins = mins + 1 
                    end 
                    if ( mins >= 60 ) then 
                        mins = 0 
                        hours = hours + 1 
                    end 
                    setElementData ( player, "Time played", tostring( hours ) ..":".. tostring( mins ) ..":".. tostring( newsec ) ) 
                end 
            end  
        end ,1000,1, source ) 
    end 
) 
  
  
function publicstatsinfo( ) 
    local account = getPlayerAccount( source ) 
    if account then 
        if isGuestAccount( account ) then return end 
        local askdname = getPlayerName( source ) 
        local wins = getAccountData( account, "Race Wins" )  
        local loses = getAccountData( account, "Race Loses" )  
        local ratio = getAccountData( account, "Ratio" ) 
        local timePlayed = getAccountData( account, "Time played" ) 
        if loses and wins then 
            outputChatBox("#FFA824*" .. askdname .. " won " .. wins .. " times and he/she lost " .. loses .. " times, his/her ratio is " .. ratio .. " and the total time played he/she is: " ..tostring( timePlayed ), root, 255, 12, 15, true) 
        else 
             outputChatBox("*You don't losed or won" , root, 255, 12, 15, true) 
        end 
    end  
end 
addEvent( "stats", true ) 
addEventHandler( "stats", root, publicstatsinfo ) 
  
function checkCommand( message, messageType ) 
    if messageType == 0 then 
        if message == "!stats" then 
            cancelEvent( ) 
            setTimer( triggerEvent, 100, 1, "stats", source ) 
        end 
    end 
end 
addEventHandler( "onPlayerChat", root, checkCommand ) 

Try it.

P.S update code

Edited by Guest
Posted

There are some errors :

  
WARNING: stats\stats.lua:72: Bad argument @ 'setElementData' [Expected element at argument 1] 
WARNING: stats\stats.lua:73: Bad argument @ 'setElementData' [Expected element at argument 1] 
WARNING: stats\stats.lua:74: Bad argument @ 'setElementData' [Expected element at argument 1] 
  

Btw , i don't want to add them on scoreboard .

Posted

Try

  
  
function DestructionWin( ) 
    local alivePlayers = getAlivePlayers( ) 
    if #alivePlayers == 1 then 
        local account = getPlayerAccount( alivePlayers[1] ) 
        if account then 
            if isGuestAccount( account ) then return end 
            setAccountData( account,"Race Wins",tostring( getAccountData( account,"Race Wins" ) or 0 ) +1 ) 
        end  
        local playername = getPlayerName( alivePlayers[1] ) 
        outputChatBox ( "#FFA824The player " .. playername .. " won!", root, 255, 255, 255, true ) 
    end  
end 
  
addEventHandler( "onPlayerWasted", root, 
    function( ) 
        local account = getPlayerAccount( source ) 
        if account then 
            if isGuestAccount( account ) then return end 
            setAccountData( account,"Race Loses",tostring( getAccountData( account,"Race Loses" ) or 0 )+1 ) 
        end  
    end 
) 
  
function ratioCalculator( player ) 
    local KDR_DECIMAL_PLACES = 2 
    local account = getPlayerAccount( player ) 
    if account then 
        if isGuestAccount( account ) then return end 
        local raceLoses = getAccountData( account,"Race Loses" ) 
        if raceLoses == 0 then 
            setAccountData( account, "Ratio", "-") 
        else 
            local kdr = round( getAccountData( account, "Race Wins" ) / raceLoses, KDR_DECIMAL_PLACES ) 
            setAccountData( account, "Ratio", tostring(kdr)) 
        end 
    end  
end 
  
addEventHandler( "onPlayerQuit",root, 
    function ( ) 
        local account = getPlayerAccount( source ) 
        if account then 
            if isGuestAccount( account ) then return end 
            local timePlayed = getElementData( source, "Time played" ) 
            if not timePlayed then setAccountData( account, "Time played","0:0:0" ) end 
            local hours, mins, secs = unpack( split( timePlayed, ":" ) ) 
            setAccountData( account, "Time played", tostring( hours or 0 ) ..":".. tostring( mins or 0 ) ..":".. tostring( secs or 0 ) ) 
        end  
    end 
) 
     
addEventHandler( "onPlayerLogin",root, 
    function ( ) 
        local account = getPlayerAccount( source ) 
        if account then 
            if isGuestAccount( account ) then return end 
            local raceWins = getAccountData( account,"Race Wins" ) or 0 
            local raceLoses = getAccountData( account,"Race Loses" ) or 0 
            local ratio = getAccountData( account, "Ratio" ) or 0 
             
            setElementData( source,"Race Wins",tostring( raceWins ) ) 
            setElementData( source,"Race Loses",tostring( raceLoses ) ) 
            setElementData( source,"Ratio",tostring( ratio ) ) 
        end  
        setTimer( function( player ) 
            local account = getPlayerAccount( player ) 
            if account then 
                if isGuestAccount( account ) then return end 
                local timePlayed = getAccountData( account, "Time played" ) 
                if not timePlayed then setElementData( player, "Time played","0:0:0" ) end 
                local hours, mins, secs = unpack( split( timePlayed, ":" ) ) 
                local hours = tonumber( hours ) or 0 
                local mins = tonumber( mins ) or 0 
                local secs = tonumber( secs ) or 0 
                local newsec 
                if hours and mins and secs then 
                    newsec = secs + 1 
                    if ( newsec >= 60 ) then 
                        newsec = 0 
                        mins = mins + 1 
                    end 
                    if ( mins >= 60 ) then 
                        mins = 0 
                        hours = hours + 1 
                    end 
                    setElementData ( player, "Time played", tostring( hours ) ..":".. tostring( mins ) ..":".. tostring( newsec ) ) 
                end 
            end  
        end ,1000,1, source ) 
    end 
) 
  
  
function publicstatsinfo( ) 
    local account = getPlayerAccount( source ) 
    if account then 
        if isGuestAccount( account ) then return end 
        local askdname = getPlayerName( source ) 
        local wins = getAccountData( account, "Race Wins" ) or 0 
        local loses = getAccountData( account, "Race Loses" ) or 0 
        local ratio = getAccountData( account, "Ratio" ) or 0 
        local timePlayed = getAccountData( account, "Time played" ) 
        local hours, mins, secs = unpack( split( timePlayed, ":" ) ) 
        if loses and wins then 
            outputChatBox("#FFA824*" .. tostring( askdname ) .. " won " .. tostring( wins ) .. " times and he/she lost " ..tostring( loses ).. " times, his/her ratio is " .. tostring( ratio ) .. " and the total time played he/she is: " .. tostring( hours or 0 ) ..":".. tostring( mins or 0 ) ..":".. tostring( secs or 0 ), root, 255, 12, 15, true) 
        else 
             outputChatBox("*You don't losed or won" , root, 255, 12, 15, true) 
        end 
    end  
end 
addEvent( "stats", true ) 
addEventHandler( "stats", root, publicstatsinfo ) 
  
function checkCommand( message, messageType ) 
    if messageType == 0 then 
        if message == "!stats" then 
            cancelEvent( ) 
            triggerEvent( "stats", source ) 
        end 
    end 
end 
addEventHandler( "onPlayerChat", root, checkCommand ) 

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