local storageConsecutiveDays = 10001 -- storages to hold information
local storageLastLoginDay = 10002
function onLogin(player)
local currentDay = math.floor(os.time() / 86400) -- calculate the current day #
local lastLoginDay = player:getStorageValue(storageLastLoginDay)
local consecutiveDays = player:getStorageValue(storageConsecutiveDays)
-- if first time Login, these if's set initial values
if lastLoginDay <= 0 then
lastLoginDay = currentDay - 1
end
if consecutiveDays <= 0 then
consecutiveDays = 1
end
-- calculate day difference
local dayDifference = currentDay - lastLoginDay
consecutiveDays = dayDifference == 1 and consecutiveDays + 1 or dayDifference == 0 and consecutiveDays or 1 -- check to see if we want to add a day, do nothing, or reset
player:setStorageValue(storageConsecutiveDays, consecutiveDays)
player:setStorageValue(storageLastLoginDay, currentDay)
return true
end