Jump to content

Race Stats help..


GanJaRuleZ

Recommended Posts

function start() 
    executeSQLCreateTable("RaceStats", "serial STRING, RaceWins INT, RaceLoses INT") 
end 
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), start) 
  
function onPlayerJoinLoadStats() 
    local serial = getPlayerSerial(source) 
    local result = executeSQLSelect("RaceStats", "*", "serial = '" .. tostring(serial) .. "'") 
    if (type(result) == "table" and #result == 0) or not result then 
        setElementData(source, "Race Wins", tonumber(re[1]["RaceWins"]) or 0) 
        setElementData(source, "Race Loses", tonumber(re2[1]["RaceLoses"]) or 0) 
    else 
        executeSQLInsert("RaceStats", "'" .. tostring(serial) .. "', '0', '0', '0', '0'") 
    end 
end 
addEventHandler("onPlayerJoin", getRootElement(), onPlayerJoinLoadStats) 
  
function publicstatsinfo() 
    local askdname = getPlayerName(source) 
    local wins = getElementData(source, "Race Wins") 
    local loses = getElementData(source, "Race Loses") 
    outputChatBox("* You won " .. wins .. " times and you losed " .. loses .. " times", source, 255, 12, 15) 
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) 

function DestructionMoney2() 
    local alivePlayers = getAlivePlayers() 
    if info == "Destruction derby" then 
        if #alivePlayers == 1 then 
            local playername = getPlayerName(alivePlayers[1]) 
            local serial = getPlayerSerial(alivePlayers[1]) 
            local oldData = executeSQLSelect( "RaceStats", "RaceWins","serial = '" .. serial .. "'") 
            local oldData = executeSQLSelect( "RaceStats", "RaceWins","serial = '" .. serial .. "'") 
            newData = tonumber(oldData[1]["RaceWins"]) + 1 
            setElementData(alivePlayers[1], "Race Wins", tonumber(getElementData(alivePlayers[1], "Race Wins")) + 1)   
            executeSQLUpdate("RaceStats", "RaceWins = '" .. newData .. "'","serial = '" .. serial .. "'") 
            outputChatBox(getPlayerName(alivePlayers[1] ) .. " is the last player alive!", rootElement, 0, 255, 0) 
        end 
    end 
end 
  
addEventHandler("onPlayerWasted", getRootElement(), 
function() 
    local serial = getPlayerSerial(source) 
    local oldData = executeSQLSelect("RaceStats", "RaceLoses", "serial = '" .. serial .. "'") 
    setElementData(source, "Race Loses", tonumber(getElementData(source, "Race Loses")) + 1) 
    newData = tonumber(oldData[1]["RaceWins"]) + 1 
    executeSQLUpdate("RaceStats", "RaceLoses = '" .. newData.. "'","serial = '" .. serial .. "'")    
end) 

Link to comment
Hai , thank you but it give me the following error :

ERROR: userpnael/Stats.lua:22: attempt to concatenate local 'loses; < a boolean value > (here the line is 21 )

This error gives in the following script

function start() 
    executeSQLCreateTable("RaceStats", "serial STRING, RaceWins INT, RaceLoses INT") 
end 
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), start) 
  
function onPlayerJoinLoadStats() 
    local serial = getPlayerSerial(source) 
    local result = executeSQLSelect("RaceStats", "*", "serial = '" .. tostring(serial) .. "'") 
    if (type(result) == "table" and #result == 0) or not result then 
        setElementData(source, "RaceWins", tonumber(re[1]["RaceWins"]) or 0) 
        setElementData(source, "RaceLoses", tonumber(re2[1]["RaceLoses"]) or 0) 
    else 
        executeSQLInsert("RaceStats", "'" .. tostring(serial) .. "', '0', '0', '0', '0'") 
    end 
end 
addEventHandler("onPlayerJoin", getRootElement(), onPlayerJoinLoadStats) 
  
function publicstatsinfo() 
    local askdname = getPlayerName(source) 
    local wins = getElementData(source, "RaceWins") 
    local loses = getElementData(source, "RaceLoses") 
    outputChatBox("* You won " .. wins .. " times and you losed " .. loses .. " times", source, 255, 12, 15) 
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) 

Thanks in advance

Then the source doesn't have that data.

Make a check like this:

if loses and wins then 
     -- stuff here 
     else 
     -- stuff here 
end 

Link to comment

Can you give me a example?

Im pretty new in scripting :)

Thank you...

@EDIT : yeap , i made it working , i remove all the scripts , cuz i dont want someone to steal it until the final version

P.S: The final version will be released as public resource in community tab!

Thanks all , i will put special thanks , with ur names guys , thank you once more!

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