So i am working on an incremental game, and i want to make something similar in grass cutting where if you join within 10pm one day and 10pm other day (in my timezone) you are able to claim 100 flowers, anyone know how it can be done?
I do not want that you need to wait 24h since you collected first time rather it resets at fix time.
Look into using DateTime | Documentation.
From this i can just save up the stats of year, month and day last time the player claimed, and from then check if the new date is higher and allow it, thanks.
No need to save the year, month, and day. You can calculate the elapsed days with some simple math on the server and client. All you need to do is store the previous timestamp for when they claimed the daily reward. Assuming you’re using DateTime.now().UnixTimestamp, it’s as simple as the below:
local ONE_MINUTE = 60
local ONE_HOUR = 60 * ONE_MINUTE
local ONE_DAY = 24 * ONE_HOUR
local dailyRewardTimestamp -- stored Unix timestamp (seconds since epoch)
local daysElapsed = (DateTime.now().UnixTimestamp - dailyRewardTimestamp) / ONE_DAY
if daysElapsed >= 1 then
-- player is eligible
end
From what i see this will be reenabled 24hours after the claim, but i wanted it to rather reset at fixed time, i may be wwrong as i did not sue time functions yet.