Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would you go by making twitter codes expire?

Asked by 5 years ago

I know how to make a twitter code GUI and how to make it detect if they already used it or not, but I want to know how many games make it so it expires at an exact date. Expiring isn't hard, but I don't know they make the code expire without having to shutdown all servers with editing the script. How do they make them expire without having to shutdown after updating?

I'm not asking for code, but at least some small examples or some links could help me out. Thanks.

0
DataStores User#19524 175 — 5y
0
That's such a vague response. Obviously it's something to do with datastores but how do you make it so you set it to expire, lets say after 24 hours or something? YabaDabaD0O 505 — 5y
1
such a vague question LostPast 253 — 5y

1 answer

Log in to vote
0
Answered by
tek_o 56
5 years ago

Using mathematical calculations, you can "expire" a code at a certain date by using the following. Simply adapt the code (I did an example of how to adapt it below) and go from there.

-- Calculating time
function CurrentDate(z)
    local z = math.floor(z / 86400) + 719468
    local era = math.floor(z / 146097)
    local doe = math.floor(z - era * 146097)
    local yoe = math.floor((doe - doe / 1460 + doe / 36524 - doe / 146096) / 365)
    local y = math.floor(yoe + era * 400)
    local doy = doe - math.floor((365 * yoe + yoe / 4 - yoe / 100))
    local mp = math.floor((5 * doy + 2) / 153)
    local d = math.ceil(doy - (153 * mp + 2) / 5 + 1)
    local m = math.floor(mp + (mp < 10 and 3 or -9))
    return y + (m <= 2 and 1 or 0), m, d
end

function CurrentTime(hoursOffset)
    local unixTime = math.floor(os.time()) - (60*60*(hoursOffset or 0))

    local hours = math.floor(unixTime / 3600 % 12)
    local minutes = math.floor(unixTime / 60 % 60)
    local seconds = math.floor(unixTime % 60)

    local year, month, day = CurrentDate(unixTime)

    return {
        year = year,
        month = month, 
        day = day,
        hours = hours,
        minutes = minutes < 10 and "0" .. minutes or minutes,
        seconds = seconds < 10 and "0" .. seconds or seconds
    }
end

local date = CurrentTime(-7)

print(date.month .. "/" .. date.day .. "/" .. date.year .. " " .. date.hours .. ":" .. date.minutes .. ":" .. date.seconds)

-- Codes
twitterCode = "TwitterYay"

if date.month == 3 and date.day == 5 and date.year == 2018 then
    twitterCode = "TwitterYay2"
end

Hopefully you get how I adapted it from the original time script, if not, here is a value directory:

date.month = month number
date.day = day of the month
date.year = number of the year
date.hours = hour of the day
date.minutes = minute of the day
date.seconds = second of the day
0
Can't you just use os.date() in a data store to do this a lot easier? YabaDabaD0O 505 — 5y
0
os.date() can't be used for this type of application tek_o 56 — 5y
Ad

Answer this question