Day/night cycle script for dungeon lights
Posted: Fri Nov 28, 2014 1:43 am
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.
Here is a video of the script in action. I made the days and night shorter compared to dusk and dawn for testing purposes.
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