Jump to content

Playtime


AJXB

Recommended Posts

function loadPlayTime(account) 
    local minutes = getAccountData(account, "playTime") 
    if (tonumber(minutes)) then 
        minutes = tonumber(minutes) 
        local hours = math.floor(minutes / 60) 
        if (hours > 0) then 
            setElementData(source, "playTime", hours.." Hours") 
        else 
            setElementData(source, "playTime", minutes.." Minutes") 
        end 
    else 
        setAccountData(account, "playTime", 0) 
        setElementData(source, "playTime", "0 Minutes") 
    end 
    playTimeTimer[source] = setTimer(incrementPlayTime, 60000, 0, source) 
end 
addEventHandler("onPlayerLogin", root, loadPlayTime) 

Save side:

function incrementPlayTime(player) 
    if (not player or not isElement(player)) then return end 
    if (isGuestAccount(getPlayerAccount(player))) then return end 
    local account = getPlayerAccount(player) 
    local minutes = getAccountData(account, "playTime") or 1 
    minutes = tonumber(minutes) 
    minutes = minutes + 1 
    local hours = math.floor(minutes / 60) 
    if (hours > 0) then 
        setElementData(player, "playTime", hours.." Hours") 
    else 
        setElementData(player, "playTime", minutes.." Minutes") 
    end 
    setAccountData(account, "playTime", minutes) 
end 

What's wrong with this?

Link to comment
function loadPlayTime(account) 
    local minutes = getAccountData(account, "playTime") 
    if (tonumber(minutes)) then 
        minutes = tonumber(minutes) 
        local hours = math.floor(minutes / 60) 
        if (hours > 0) then 
            setElementData(source, "playTime", hours.." Hours") 
        else 
            setElementData(source, "playTime", minutes.." Minutes") 
       end 
    else 
        setAccountData(account, "playTime", 0) 
        setElementData(source, "playTime", "0 Minutes") 
    end 
    playTimeTimer[source] = setTimer(incrementPlayTime, 60000, 0, source) 
end 
addEventHandler("onPlayerLogin", root, loadPlayTime) 

Are you sure that are 3 end?

Link to comment
local playTimeTimer = {} 
  
function loadPlayTime(_,account) 
    local minutes = getAccountData(account, "playTime") 
    if (tonumber(minutes)) then 
        minutes = tonumber(minutes) 
        local hours = math.floor(minutes / 60) 
        if (hours > 0) then 
            setElementData(source, "playTime", hours.." Hours") 
        else 
            setElementData(source, "playTime", minutes.." Minutes") 
        end 
    else 
        setAccountData(account, "playTime", 0) 
        setElementData(source, "playTime", "0 Minutes") 
    end 
    playTimeTimer[source] = setTimer(incrementPlayTime, 60000, 0, source) 
end 
addEventHandler("onPlayerLogin", root, loadPlayTime) 
  
function stopPlayTime() 
    if (isTimer(playTimeTimer[source])) then killTimer(playTimeTimer[source]) end 
  
end 
addEventHandler("onPlayerLogout", root, stopPlayTime) 
addEventHandler("onPlayerQuit", root, stopPlayTime) 
  
function incrementPlayTime(player) 
    if (not player or not isElement(player)) then return end 
    if (isGuestAccount(getPlayerAccount(player))) then return end 
    local account = getPlayerAccount(player) 
    local minutes = getAccountData(account, "playTime") or 1 
    minutes = tonumber(minutes) 
    minutes = minutes + 1 
    local hours = math.floor(minutes / 60) 
    if (hours > 0) then 
        setElementData(player, "playTime", hours.." Hours") 
    else 
        setElementData(player, "playTime", minutes.." Minutes") 
    end 
    setAccountData(account, "playTime", minutes) 
end 
  

This is the code, somehow when the player is playing time adds, but when he reconnects, his time sets to 0 :S

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