Forum

> > CS2D > Scripts > Day and Night Script
Forums overviewCS2D overview Scripts overviewLog in to reply

English Day and Night Script

6 replies
To the start Previous 1 Next To the start

old Day and Night Script

Mami Tomoe
User Off Offline

Quote
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 √

old Re: Day and Night Script

Cebra
User Off Offline

Quote
Here, I had this lying around, maybe you can use it.

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

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

old Re: Day and Night Script

Mami Tomoe
User Off Offline

Quote
@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 Cebra: 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

old Re: Day and Night Script

Cebra
User Off Offline

Quote
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]
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
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview