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

How would I make lighting time of day same for every server?

Asked by 6 years ago

Like for exampe if one server is day the rest of the server in the game is day if its night the whole game server is night

2
DataStores or web servers Rare_tendo 3000 — 6y

1 answer

Log in to vote
2
Answered by
Vathriel 510 Moderation Voter
6 years ago
Edited 6 years ago

I would personally use a calculation off of tick, as both web services and datastore can be unreliable and take time to update.

Using tick() we can get the current unix time in seconds. Assume we want to start our day at unix time of 1544547289. (I chose this number based on tick() when I started writing this answer.)

Then we could ask how many seconds would be in our day/night cycle, as a reference there are 1200 seconds in 20 minutes which is what I'll use for this.

Knowing this we can do tick()-1544547289 to get how many seconds have passed since our time cycle start. If we use the mod operator we can get the remainder of seconds relative to 20 minutes. (math.floor(tick()) - 1544547289)00

This will give us our number of seconds into our "day night cycle"

On a 24 hour clock this would look like

math.floor(((math.floor(tick()) - 1544547289)00)/(1200/24))

Thus this would let you know it's the nth hour into your time scale.

Next using our lua we can do this:

Hour = math.floor(((math.floor(tick()) - 1544547289)00)/(1200/24))
game.Lighting:SetMinutesAfterMidnight(Hour*60)

As a note you can also do this for minutes half hours, quarter hours etc by multiplying the 24 to what you need.

Half hour:

HalfHour = math.floor(((math.floor(tick()) - 1544547289)00)/(1200/48))
game.Lighting:SetMinutesAfterMidnight(HalfHour*30)

you can update this code either in some sort of loop or event if you want, but that's the general idea.

0
I'd like to apologize the modulus operator got removed for security reasons, it's the percent sign, replace the 00s after the 1544547289)  with percent 1200 Vathriel 510 — 6y
Ad

Answer this question