I'm just wondering if this would be possible. You enter a level and are given a warning not to wander off the path a clue to enter the next level under a specific time. Of course as explorers we wander off to find treasures, hidden buttons and fight mobs hoping for good loot. When the time almost runs out you get a warning to hurry to the exit and when the time does run out you are teleported into a prison cell without the recent loot. A note tells you to hurry and soon after the cell door opens leading to a teleporter that sends you to the beginning of the level with everything in the level reset. At a certain time you might run out of food failing several times.
I guess technically this wouldn't be easy.
- a timed teleport from an unknown location
- destroying new loot from inventory and equiped items
- restoring starter equipment [added later]
- resetting the whole level (buttons, loot, doors)
- stopping the timer after reaching the exit
- continue in a loop if failing till starvation
Is a timed level possible?
Is a timed level possible?
Last edited by Frenchie on Tue Jan 27, 2015 7:42 am, edited 4 times in total.
Re: Is a timed level possible?
Seems to me like a mass of scripting work but possible.
Re: Is a timed level possible?
- - a timed teleport from an unknown location
Use a [one time] floor trigger at the spot where the party arrives. This can trigger the level script and start the timer. - - destroying new loot from inventory and equipped items
Define all the loot on the level with a custom id; [append a custom suffix to the id, and write a function that deletes any item that has that it]. - - resetting the whole level (buttons, loot, doors)
We did similar to this in ORRR2 for performance reasons. In that mod most of the level outside the current room is erased, and bits of it are put back as the player approaches them. But for what you are suggesting... a table of items and their initial positions, and a table of the door states could be used to 'reset' the map to its default. Alas... the :setDoorState() function would have made this easy, but it doesn't work as smoothly in LoG2 as it did in LoG1; in LoG2 it is not meant to be used in user scripts.
So in your case you will just have to call the regular open()/close() methods; optionally you could set the open/close/lock sounds to a custom "silence" sound effect; then restore their default sounds after they've been reset.
For the items... rather than individually checking their locations, just destroy any item native to the level, and respawn each at its default position. In the case of chests and surfaces... spawn them and add to them a table of their initial contents. - - stopping the timer after reaching the exit
Another floor trigger could be used, same as the first, but place this one on the next map. - - continue in a loop if failing till starvation
Timer that runs a "teleport party to jail" script, and the level reset script after the time is up.
Re: Is a timed level possible?
I was thinking if it is not practical maybe we could set the number of attempts to 5 before 'starvation' after which you would need to reload. Instead of resetting all we make 5 equal levels with same layout, buttons etc. but perhaps with lesser loot. Starvation might not be the right condition and maybe 'radiation' might be better. Too much radiation and you die. After exiting to next level a decontamination chamber will heal you.- resetting the whole level (buttons, loot, doors)
In another post of mine I was told that setDoorState() was bugged.
Re: Is a timed level possible?
Make the level, then copy/paste the level's dungeon.lua code into a function in a script entity. Then when you want to reset the level you can just delete all the entities and call that function to re-create them in their initial state, same ID and everything. As far as I know the only objects this won't work for are objects with ScriptComponents, which are rare enough that you can deal with them individually.
To deal with champions' inventory just save the ID of the parent object of the item in every inventory slot (remember containers). Before you destroy the level, iterate through the champions' inventories (remember containers) and remove anything not the aforementioned list. Then use findEntity() to locate any that aren't in the inventory, and move them to the inventory (or maybe you'll have to just move them in front of the party, I don't remember if you can cleanly move items from the ground into the inventory). When you do iterate through all entities in the level to destroy them, check inside any containers for remaining items that are unaccounted for (player could have picked up one of your containers, put one of their original items in it, and dropped it again).
To deal with champions' inventory just save the ID of the parent object of the item in every inventory slot (remember containers). Before you destroy the level, iterate through the champions' inventories (remember containers) and remove anything not the aforementioned list. Then use findEntity() to locate any that aren't in the inventory, and move them to the inventory (or maybe you'll have to just move them in front of the party, I don't remember if you can cleanly move items from the ground into the inventory). When you do iterate through all entities in the level to destroy them, check inside any containers for remaining items that are unaccounted for (player could have picked up one of your containers, put one of their original items in it, and dropped it again).
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.
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Re: Is a timed level possible?
'arrives' as in where the party ends up after the timer runs out? This location would be unknown. Hence you can't use a floor trigger. Or do you mean I should put in multiple strategic floor triggers spread through the level checking the timer?- a timed teleport from an unknown location
Use a [one time] floor trigger at the spot where the party arrives. This can trigger the level script and start the timer.
I've been thinking this might create another problem. If the party replaces their weapons with new loot and leaves the old ones behind. By resetting the party will be weaponless in that situation. I'll add it to the top list in green. Meaning I would need to store the starter equipment.- destroying new loot from inventory and equiped items
- resetting the whole level (buttons, loot, doors)
Re: Is a timed level possible?
To do a real reset might be a bit involved... perhaps a lever at the start of the map could work instead? One that resets itself after the time limit; requiring the party to travel back and pull it again, before being able to leave. Or is it that you want them to pick some ~but not all of the rooms on the map? If that's the case, then it would be easier to have all of the doors locked and restrict the amount of keys that they have.Frenchie wrote:'arrives' as in where the party ends up after the timer runs out? This location would be unknown. Hence you can't use a floor trigger. Or do you mean I should put in multiple strategic floor triggers spread through the level checking the timer?- a timed teleport from an unknown location
Use a [one time] floor trigger at the spot where the party arrives. This can trigger the level script and start the timer.
I've been thinking this might create another problem. If the party replaces their weapons with new loot and leaves the old ones behind. By resetting the party will be weaponless in that situation. I'll add it to the top list in green. Meaning I would need to store the starter equipment.- destroying new loot from inventory and equiped items
- resetting the whole level (buttons, loot, doors)
A floor trigger where they arrive ~for the first time on the map could run a script that records all of their initial equipment (as you mention), but should also include the slots those items are located in, and ~to avoid easy exploit~ it really should record their initial experience points and skill ranks; reverting it all to the initial values upon reset. Otherwise they might enter the map with a tome of wisdom (for instance) and use it on the map ~and get it back when the map resets.
*Although... for a partial reset, one could account for missing/used equipment by checking for it, and only returning it to the inventory if exists on the map.