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
return false;
elseif Now - LastPlayerd > 172800 then
return true;
elseif ((LastPlayed - 14400) % 86400) > ((LastPlayed - 14400) % 86400) then
return true;
end;
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.
I already got the data of the player I’m looking for detecting if player joined what we consider next day (not 24 hours) by the two dates given.
Also I’m porting this to Lua 5.3 too.
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.
Not really. There are two different approaches of solving this issue that I’ve seen:
Basing it on the utc timezone (os.time/os.date) and/or reducing the time from 24 hours to i.e. 18 hours to create a small window allowing to “shift” the day cycle, if that makes sense
Starting the 24h timer the first time the player joins the game or collects the reward after breaking the streak
In my opinion the first one is the best. If you’ve ever played minecraft you might know that Hypixel does exactly that ^^
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?