Page 1 of 1

Day/night cycle script for dungeon lights

Posted: Fri Nov 28, 2014 1:43 am
by Phitt
Compared to all the fancy stuff people are scripting here this may be a very simple script, but I thought it may help some of the less experienced scripters anyway (plus it has already RGB settings included, so you don't have to test those if you like what you see in the video below). I wanted my dungeon ceiling lights to change their color depending on the time of day in the outside world, so I made this script. Works pretty well imo, even though there may be a better solution (since the time only advances when the party moves onMove and onTurn may be better than a timer?). But I doubt this has any noticeable effect on performance anyway, so whatever. With a timer setting of 0.5 I couldn't see any sudden light changes, so that should be fine.

Code: Select all

rcol = 0
gcol = 0
bcol = 0
tme = 0

function lightcycle()

tme = GameMode.getTimeOfDay()

	if tme >= 1.0 and tme <= 1.1 then
		rcol = 2.6 - (tme - 1) * 16
		gcol = 1.2 + (tme - 1) * 2
		bcol = 1.1 + (tme - 1) * 6
	elseif tme > 1.1 and tme < 1.9 then
		rcol = 1
		gcol = 1.4
		bcol = 1.7
	elseif tme >= 1.9 then
		rcol = 1 + (tme - 1.9) * 13
		gcol = 1.4 + (tme - 1.9) * 1
		bcol = 1.7 - (tme - 1.9) * 2
	elseif tme <= 0.1 then
		rcol = 2.3 + tme * 7
		gcol = 1.5 + tme * 15
		bcol = 1.5 + tme * 9
	elseif tme > 0.1 and tme < 0.9 then
		rcol = 3.0
		gcol = 3.0
		bcol = 2.4
	elseif tme >= 0.9 and tme < 1.0 then
		rcol = 3.0 - (tme - 0.9) * 4
		gcol = 3.0 - (tme - 0.9) * 18
		bcol = 2.4 - (tme - 0.9) * 13
	end
	
	sky01.light:setColor(vec(rcol,gcol,bcol))

end
Here is a video of the script in action. I made the days and night shorter compared to dusk and dawn for testing purposes.

Re: Day/night cycle script for dungeon lights

Posted: Fri Nov 28, 2014 1:54 am
by minmay
Phitt wrote:(since the time only advances when the party moves onMove and onTurn may be better than a timer?).
You want onWakeUp as well.

Re: Day/night cycle script for dungeon lights

Posted: Fri Nov 28, 2014 10:05 am
by Drakkan
seems cool. I wonder if possible to make some similar automated script which will for example lit all fireflies lights during night and disable them during day in one particular level ?

Re: Day/night cycle script for dungeon lights

Posted: Fri Nov 28, 2014 10:56 am
by Phitt
Sure, you could add something like

firefly01.light:fadeIn(10)
firefly01.particle:fadeIn(10)

at nightfall (1.0 - 1.05) and

firefly01.light:fadeOut(10)
firefly01.particle:fadeOut(10)

during daybreak (1.95 - 0.0).

Looks like this with a fake sky (use forest_day_sky as base object and setfogRange = ({0}), then turn off light, ambient and lensflare).

Re: Day/night cycle script for dungeon lights

Posted: Fri Nov 28, 2014 7:23 pm
by Ciccipicci
Nice touch! How it works? I'll have just copy paste the code in a script and just leave in the level without linking to anything?

Re: Day/night cycle script for dungeon lights

Posted: Fri Nov 28, 2014 9:10 pm
by sapientCrow
That is a nice touch with that sort of detail for light changing based on actual cycles of light outdoors.
thanks