Detect light level
Detect light level
Hi,
I was searching the forum but couldn't find an answer. Is there a way to detect the light level? I would like to trigger something if all lights go out, exactly like the weapon of power puzzle in Grimrock which appears in shadows.
More specifically, I'm thinking of a room with behind secret walls 1x1 rooms. If it gets completely dark, the walls open revealing monsters. If the player casts a light spell or puts a torch in the holder, walls close again.
I saw the thread for darkness zones, but I don't want to "impose" darkness for the puzzle I'm planning, I want the player to make it dark. I know I can trigger off torches being removed from and/or an onCast hook of darkness, but as players can simply choose not use the light or darkness spells that's not a reliable way. What if someone uses an all-fighter party?
I was searching the forum but couldn't find an answer. Is there a way to detect the light level? I would like to trigger something if all lights go out, exactly like the weapon of power puzzle in Grimrock which appears in shadows.
More specifically, I'm thinking of a room with behind secret walls 1x1 rooms. If it gets completely dark, the walls open revealing monsters. If the player casts a light spell or puts a torch in the holder, walls close again.
I saw the thread for darkness zones, but I don't want to "impose" darkness for the puzzle I'm planning, I want the player to make it dark. I know I can trigger off torches being removed from and/or an onCast hook of darkness, but as players can simply choose not use the light or darkness spells that's not a reliable way. What if someone uses an all-fighter party?
- Edsploration
- Posts: 104
- Joined: Wed Sep 19, 2012 4:32 pm
Re: Detect light level
I have a room in a dungeon I'm working on where I have something different happen inside lit areas than in darkness. I just put checks on equipped torches and the light or darkness spells on a fast tick timer. It works fairly well.
I don't think there are hooks available for everything that can change lighting. But if someone has a cleaner solution I'm all ears.
I don't think there are hooks available for everything that can change lighting. But if someone has a cleaner solution I'm all ears.
Open Project -> Community FrankenDungeon: viewtopic.php?f=14&t=4276
Re: Detect light level
detecting darkness with the tools we have available is very difficult, but doable. One of the challenges is that, as far as I know, you have to set up a system to keep track of any light spells cast (they last 600s) and be sure timer tracking is accurate (timer always on the current floor, moves to new current floor if change, etc), resets if player casts light again, is cancelled if player casts darkness.
Also, darkness spell first negates light spell, then if cast again will finally negate the light effect of torches and orb, so you'll have to track that properly.
Then you need to properly check all party hands for torches and orbs (that's the easy part really).
The only way to do all this and have it work and be detected is to run a tick timer that checks everything very often, such as a couple times a second or once a second at bare minimum I would think.
--------------------
(I'm curious Edsploration how you have it checking your light/darkness spells - have you found a way to detect whether they are currently running directly?)
Also, darkness spell first negates light spell, then if cast again will finally negate the light effect of torches and orb, so you'll have to track that properly.
Then you need to properly check all party hands for torches and orbs (that's the easy part really).
The only way to do all this and have it work and be detected is to run a tick timer that checks everything very often, such as a couple times a second or once a second at bare minimum I would think.
--------------------
(I'm curious Edsploration how you have it checking your light/darkness spells - have you found a way to detect whether they are currently running directly?)
Finished Dungeons - complete mods to play
Re: Detect light level
this -> precious as gold!they last 600s
Is the duration always in real time (that is not influenced by resting) ?
Thanks
Waking Violet (Steam, PS4, PSVita, Switch) : http://www.wakingviolet.com
The Sunset Gate [MOD]: viewtopic.php?f=14&t=5563
My preciousss: http://www.moonsharp.org
The Sunset Gate [MOD]: viewtopic.php?f=14&t=5563
My preciousss: http://www.moonsharp.org
Re: Detect light level
Right... We could just implement a global light tracker. A counter and scripts which follow all Light spells cast from the beginning to the end of the game. The counter would internally indicate light level and would be decreasing over time. Light spells would bring the counter to 100%, darkness to 0%.
Then any puzzles/scripts could refer to this main counter to trigger things even in twilight, 25%, whatever. This is something that would be worth scripting properly for everyone to use.
This could make programming "darkness zones" even more effective because they could simply check the global "light value", and as soon as it goes up, re-cast darkness. This would prevent any shenanigans players would do with throwing torches across zones, picking them up, etc.
A few questions: what's the decay rate of the light spell? We need to know this. We have to also "move" the timer with the party as the party switches levels to avoid timer speed issues. What's the easiest way to do that? Is there a hook for when the party changes level to destroy the original timer and spawn a new one on self.level?
EDIT: Komag you beat me to the answer.
Then any puzzles/scripts could refer to this main counter to trigger things even in twilight, 25%, whatever. This is something that would be worth scripting properly for everyone to use.
This could make programming "darkness zones" even more effective because they could simply check the global "light value", and as soon as it goes up, re-cast darkness. This would prevent any shenanigans players would do with throwing torches across zones, picking them up, etc.
A few questions: what's the decay rate of the light spell? We need to know this. We have to also "move" the timer with the party as the party switches levels to avoid timer speed issues. What's the easiest way to do that? Is there a hook for when the party changes level to destroy the original timer and spawn a new one on self.level?
EDIT: Komag you beat me to the answer.
Re: Detect light level
Hint: You don't need to move timers if you spawn a timer in each level and connect them all to same function. In the function you can ignore all activates except the one where timer.level == party.level.
Re: Detect light level
That's a piece of genius right there! Thanks Petri.petri wrote:Hint: You don't need to move timers if you spawn a timer in each level and connect them all to same function. In the function you can ignore all activates except the one where timer.level == party.level.
Puzzle Frameworks - http://www.grimrock.net/forum/viewtopic.php?f=14&t=4564
Magic Pack - https://www.nexusmods.com/grimrock/mods/70
Area of Effect Spell System - http://www.grimrock.net/forum/viewtopic ... 150#p44382
Magic Pack - https://www.nexusmods.com/grimrock/mods/70
Area of Effect Spell System - http://www.grimrock.net/forum/viewtopic ... 150#p44382
Re: Detect light level
Thank you very much petri, this helps a lot.
I know the trigger of an event gets passed as the function's first argument. It's a table, entity? Is it directly accessible, like:
I remember reading timers go x2 when resting. If this is true we wouldn't need to track that specifically it would be automatic.
Komag, what do you mean when you say Darkness spells turns off torches and orb? The ones in hand/inventory, or ones on the walls? I didn't experiment a lot with the darkness spell. If items get turned off, aren't they replaced by another version we can detect? Or does "darkness" also have a timeout (600s as well?) and then the torch/orb lits back up?
I know the trigger of an event gets passed as the function's first argument. It's a table, entity? Is it directly accessible, like:
Code: Select all
function trackLight(sourceTimer)
if sourceTimer.level == party.level then ...
endKomag, what do you mean when you say Darkness spells turns off torches and orb? The ones in hand/inventory, or ones on the walls? I didn't experiment a lot with the darkness spell. If items get turned off, aren't they replaced by another version we can detect? Or does "darkness" also have a timeout (600s as well?) and then the torch/orb lits back up?
Re: Detect light level
both spells are 600s, that's game time, so resting makes it go 5x faster (and the timer ticks 5x faster too, so it keeps up accurately). If you currently have one of them cast, the other just turns it off. If darkness is cast, any torch you hold or orb you hold won't shine, no effect on the wall though (so a torch in hand that doesn't shine could be placed on the wall and the room is now bright, and vice versa)
Finished Dungeons - complete mods to play
Re: Detect light level
Great, I think I have all I need, thanks so much. I'll write the code and post it here when I get it working.
