Jump to content

Why this isn't working?


Feche1320

Recommended Posts

I made this script:

  
local p_Wins = {} 
local p_Deaths = {} 
local p_Joins = {} 
local p_MPlayed = {} 
  
addEventHandler("onPlayerLogin", g_Root, 
    function(thePreviousAccount, theCurrentAccount, autoLogin) 
        if theCurrentAccount then 
            p_Wins[source] = tonumber(getAccountData(theCurrentAccount, "wins.stats")) 
            p_Deaths[source] = tonumber(getAccountData(theCurrentAccount, "deaths.stats")) 
            p_Joins[source] = tonumber(getAccountData(theCurrentAccount, "joins.stats")) 
            p_MPlayed[source] = tonumber(getAccountData(theCurrentAccount, "mapsp.stats")) 
            if not p_Joins[source] then 
                p_Joins[source] = 1 
            else 
                p_Joins[source] = p_Joins[source]+1 
            end 
            outputChatBox("Your stats have been succesfully loaded, welcome back " ..getPlayerName(source).."!", source, 46, 154, 254) 
        end 
    end 
) 
  
addEventHandler("onPlayerLogout", g_Root, 
    function() 
        local acc = getPlayerAccount(source) 
        if acc then 
            setAccountData(acc, "wins.stats", tostring(p_Wins[source])) 
            setAccountData(acc, "deaths.stats", tostring(p_Deaths[source])) 
            setAccountData(acc, "joins.stats", tostring(p_Joins[source])) 
            setAccountData(acc, "mapsp.stats", tostring(p_MPlayed[source])) 
            outputChatBox("Your stats have been succesfully saved.", source, 46, 154, 254) 
        end 
    end 
) 
  
addEventHandler("onPlayerQuit", g_Root, 
    function() 
        local acc = getPlayerAccount(source) 
        if acc then 
            setAccountData(acc, "wins.stats", tostring(p_Wins[source])) 
            setAccountData(acc, "deaths.stats", tostring(p_Deaths[source])) 
            setAccountData(acc, "joins.stats", tostring(p_Joins[source])) 
            setAccountData(acc, "mapsp.stats", tostring(p_MPlayed[source])) 
        end 
    end 
) 
  
addEvent("onPostFinish") 
addEventHandler("onPostFinish", g_Root, 
    function() 
        for i, player in ipairs(getElementsByType('player')) do 
            if getElementData(player, "State") == "alive" then 
                if not p_Wins[source] then 
                    p_Wins[source] = 1 
                else 
                    p_Wins[source] = p_Wins[source]+1 
                end 
            end 
        end 
    end 
) 
  
addEventHandler("onPlayerWasted", g_Root, 
    function() 
        if not p_Deaths[source] then 
            p_Deaths[source] = 1 
        else 
            p_Deaths[source] = p_Deaths[source]+1 
        end 
    end 
) 
  
addEvent("onMapStarting") 
addEventHandler("onMapStarting", g_Root, 
    function() 
        for i, player in ipairs(getElementsByType('player')) do 
            if not p_MPlayed[player] then 
                p_MPlayed[player] = 1 
            else 
                p_MPlayed[player] = p_MPlayed[player]+1 
            end 
        end 
    end 
) 
  
addCommandHandler("stats", 
    function(source) 
        local acc = getPlayerAccount(source) 
        if isGuestAccount(acc) then 
            outputChatBox("You must be logged to view your stats.", source, 46, 154, 254) 
        else 
            outputChatBox(getPlayerName(source).." stats:") 
            if not p_Wins[source] or p_Wins[source] < 5 then 
                outputChatBox("Visits: " ..tostring(p_Joins[source]).. " Wins: " ..tostring(p_Wins[source]).. "(0.0%) Deaths: " ..tostring(p_Deaths[source]).. " Maps played: " ..tostring(p_MPlayed[source]), source, 46, 154, 254) 
            else 
                outputChatBox("Visits: " ..tostring(p_Joins[source]).. " Wins: " ..tostring(p_Wins[source]).. "("..tostring(p_Wins[source]/p_MPlayed[source]*100).."%) Deaths: " ..tostring(p_Deaths[source]).. " Maps played: " ..tostring(p_MPlayed[source]), source, 46, 154, 254) 
            end 
            outputChatBox("Cash: $"..getPlayerMoney(source), source, 46, 154, 254) 
        end 
    end 
) 

But when I quit or log out and then log in again, the stats are 0 again, it doesn't get saved.

Thanks

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