Day/night cycle script for dungeon lights

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
Post Reply
User avatar
Phitt
Posts: 442
Joined: Tue Aug 14, 2012 9:43 am

Day/night cycle script for dungeon lights

Post 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.
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: Day/night cycle script for dungeon lights

Post 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.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
Drakkan
Posts: 1318
Joined: Mon Dec 31, 2012 12:25 am

Re: Day/night cycle script for dungeon lights

Post 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 ?
Breath from the unpromising waters.
Eye of the Atlantis
User avatar
Phitt
Posts: 442
Joined: Tue Aug 14, 2012 9:43 am

Re: Day/night cycle script for dungeon lights

Post 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).
User avatar
Ciccipicci
Posts: 154
Joined: Mon Oct 08, 2012 12:55 am

Re: Day/night cycle script for dungeon lights

Post 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?
User avatar
sapientCrow
Posts: 608
Joined: Sun Apr 22, 2012 10:57 am

Re: Day/night cycle script for dungeon lights

Post by sapientCrow »

That is a nice touch with that sort of detail for light changing based on actual cycles of light outdoors.
thanks
Post Reply