Jump to content

Playtime


AJXB

Recommended Posts

Posted
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?

~ This has to be the worst board post I have ever read. It simply makes no sense. You start off by talking about space or something, then you randomly start babbling about cupcakes, and you end off with random fish names.

~ Don't listen to this guy, any board with the categories 'dinosaurs, spaceships, fried foods, wild animals, alien abductions, business casual, robots, and fireworks' has true potential.

 

Posted

If you don't explain the problem, how are we supposed to know?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

It won't save/load

The time adds to ElementData

But when I reconnect the time is gone.

~ This has to be the worst board post I have ever read. It simply makes no sense. You start off by talking about space or something, then you randomly start babbling about cupcakes, and you end off with random fish names.

~ Don't listen to this guy, any board with the categories 'dinosaurs, spaceships, fried foods, wild animals, alien abductions, business casual, robots, and fireworks' has true potential.

 

Posted
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?

Posted

The first argument of "onPlayerLogin" is the previous account, try changing this:

function loadPlayTime(account) 

to:

function loadPlayTime ( _, account ) 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
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

~ This has to be the worst board post I have ever read. It simply makes no sense. You start off by talking about space or something, then you randomly start babbling about cupcakes, and you end off with random fish names.

~ Don't listen to this guy, any board with the categories 'dinosaurs, spaceships, fried foods, wild animals, alien abductions, business casual, robots, and fireworks' has true potential.

 

Posted

Try debugging the script, add outputs to see what is not working.

Also, using a timer for each player is a really bad idea, timers are inefficient.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
Try debugging the script, add outputs to see what is not working.

Also, using a timer for each player is a really bad idea, timers are inefficient.

What do you think I should do with the timers?

~ This has to be the worst board post I have ever read. It simply makes no sense. You start off by talking about space or something, then you randomly start babbling about cupcakes, and you end off with random fish names.

~ Don't listen to this guy, any board with the categories 'dinosaurs, spaceships, fried foods, wild animals, alien abductions, business casual, robots, and fireworks' has true potential.

 

Posted

I would make a single timer to update the time of every player.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

I couldn't find a way to fix the current script, can you try to fix it before I change the timers?

~ This has to be the worst board post I have ever read. It simply makes no sense. You start off by talking about space or something, then you randomly start babbling about cupcakes, and you end off with random fish names.

~ Don't listen to this guy, any board with the categories 'dinosaurs, spaceships, fried foods, wild animals, alien abductions, business casual, robots, and fireworks' has true potential.

 

Posted

Did you do what I said? add outputs in the saving/loading, etc. That will make it a lot easier to spot the problem.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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