Say a player joins the game at 19.00, then at 5.00 joined the game after waking up, here’s what I tried.
The LastPlayed value is in Unix time.
Bascially I want it to detect whether player has joined after 4.00 every day BUT if the player last joined at time at most 4 hours earlier than that, wait until 8.00 and if the player didn’t join between the day range ignore it too.
local Now = os.time();
-- 4 hours and day starting at 04.00, BUT if the user last played at time is 4 hours closer then that 04.00, ignore it until 8.00, if the player joined the day after, ignore it too.
if Now - LastPlayed < 14400 then
elseif Now - LastPlayerd > 172800 then
elseif ((LastPlayed - 14400) % 86400) > ((LastPlayed - 14400) % 86400) then
Never done this before so I might go on a limb with a guess here. After researching a bit I came to the conclusion that you can try using DataStore and os.time() to check for it. You can try checking out some of the daily rewards system to help you derive a script from it.
Example is -
This is as far as I could go in terms of helping with this. Hope it helps.
As it’s unpredictable what we actually consider a day. e.g. Some wake up at 11.00 while others wake up at 05.00 it’s best to consider the start of the day at 4.00, actually doing it is too much work I’m not going to do.
Again, you can’t really get the “next day” for all machines, it’s best to stick with UTC so you don’t get “time machined” (they can just change the local machine time and skip a day).
Lua 5.3 has os.date("*t") and so does Lua 5.1.
Rather than doing math for no reason at all why don’t you just use that?
However, what you can do is ask for for their timezone and compensate for that when checking for the day but, if this is an online game it’ll just be a huge mess.
Australia is 12 hours ahead, I don’t want it to detect as 12.00 for Australia users.
I prefer working in unix time. os.date seems redundant for this. Also I don’t want to detect if the player joins the day after. I’ll implement a timezone detector and check if the user has changed the time.
I mean actually detecting for when’s a person waking up and what considered a day for a person.
And I qoute : " I’m looking for detecting if player joined what we consider next day ( not 24 hours) by the two dates given."
How is os.date “redundant” for this? It couldn’t be any better for this specific use, it won’t check if “24 hours” passed, it’ll check if a day has passed, yes that means if they logged in at 11:59 and left, then relog at 12:01 or 12:00 it would be a different day (which is exactly what you said you’re trying to do).
Could you please explain what you’re “REALLY” trying to do if what I said wasn’t actually what you meant?