English Day and Night Script

6 replies
Goto Page
To the start Previous 1 Next To the start
24.04.20 04:28:55 pm
Up
Mami Tomoe
User
Offline Off
Hey, I've been trying to make a day and night script using the light engine a while ago, I still have it.

But I didn't like it because I couldn't set a max darkness or brightness on it and I couldn't control how fast the nights or days are.

Mostly because math is hard

Can someone make a good day and night script that follows these problems I posted above?

You will be credited

> thx √
24.04.20 05:14:16 pm
Up
Joghurt
User
Offline Off
Here, I had this lying around, maybe you can use it.

(it is really old, so you have to test it)

Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Time config, on what "time" should the server start
hour = 12
min = 0

// how many in-game-minutes are a real second
speed = 1

// this will map the start time to the corresponding lightlevel
lightlevel = (90 + (hour * 60 + min) * speed / 4) % 360 

// the speed / 4 comes from the fact that a day have 24 * 60 = 1440 min
// and the lightlevel can be between 0 and 360 => you have a ratio from 1/4

addhook("second","time")
function time()
     lightlevel = lightlevel + speed / 4
     parse("sv_daylighttime "..lightlevel)
     if lightlevel >= 360 then
          lightlevel = 0
     end
     min = min + speed
     if min >= 60 then
          hour = hour + 1
          min = 0
          if hour >= 24 then
               hour = 0
          end
     end
end


EDIT/btw: there are already some files in ther archive e.g. this one or click here to look in the search-results
loading...
24.04.20 06:57:17 pm
Up
BcY
Reviewer
Offline Off
Why not using sys/lua/samples/daycycle.lua , man?
Kgb2d Community - Since 2012
25.04.20 07:22:43 pm
Up
Mami Tomoe
User
Offline Off
@user BcY: I did, which led me to creating this topic which probably means it was insufficient, luckily I posted why it was insufficient for me.


@user Joghurt: that works, but how do I set a max day duration and max night duration?
And max darkness during the night as well?
edited 1×, last 25.04.20 08:36:37 pm
25.04.20 09:27:54 pm
Up
Joghurt
User
Offline Off
The maximum day and night duration can be set indirectly with the variable
speed
.
The day/night cycle duration can be calculated in seconds with
t=1440/speed
or in minutes with
t=24/speed
.
But you can not define two different values for the day and night duration.
now you can: use the
night
- and
dayspeed
var

and you cannot set a maximum darkness because
sv_daylighttime
works like a circle. If you "cut away" something, there would be a jump in the shadow casting.

edit:
[untested]
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Time config, on what "time" should the server start
hour = 12
min = 0

// how many in-game-minutes are a real second
dayspeed = 1
nightspeed = 1

// this will map the start time to the corresponding lightlevel
lightlevel = (90 + (hour * 60 + min) * speed / 4) % 360 

// the speed / 4 comes from the fact that a day have 24 * 60 = 1440 min
// and the lightlevel can be between 0 and 360 => you have a ratio from 1/4

addhook("second","time")
function time()
     speed = dayspeed
     if hour < 6 or hour > 18 then
          speed = nightspeed
     lightlevel = (lightlevel + speed / 4) % 360
     parse("sv_daylighttime "..lightlevel)
     end
     min = min + speed
     if min >= 60 then
          hour = (hour + 1) % 24
          min = 0
     end
end
loading...
25.04.20 10:12:01 pm
Up
Mami Tomoe
User
Offline Off
Thanks, I think that'll do.
27.04.20 09:35:14 am
Up
Gaios
Security Supporter
Offline Off
I did day/night cycle wrapper for CS2D, and I reduced the length of the night for Minecraft 2D.
> https://youtu.be/5Uz7yMeLJ5E
To the start Previous 1 Next To the start