AJXB Posted April 5, 2014 Posted April 5, 2014 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.
Castillo Posted April 5, 2014 Posted April 5, 2014 If you don't explain the problem, how are we supposed to know? San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
AJXB Posted April 5, 2014 Author Posted April 5, 2014 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.
gghvcffcv Posted April 5, 2014 Posted April 5, 2014 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?
Castillo Posted April 5, 2014 Posted April 5, 2014 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. Education is the most powerful weapon which you can use to change the world.
AJXB Posted April 5, 2014 Author Posted April 5, 2014 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 ~ 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.
Castillo Posted April 5, 2014 Posted April 5, 2014 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. Education is the most powerful weapon which you can use to change the world.
AJXB Posted April 5, 2014 Author Posted April 5, 2014 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.
Castillo Posted April 5, 2014 Posted April 5, 2014 I would make a single timer to update the time of every player. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
AJXB Posted April 5, 2014 Author Posted April 5, 2014 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.
Castillo Posted April 5, 2014 Posted April 5, 2014 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. Education is the most powerful weapon which you can use to change the world.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now