trap door sequence

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
papazombie
Posts: 17
Joined: Sat Sep 15, 2012 1:00 am

trap door sequence

Post by papazombie »

I need help to create a sequence of trapdoors so that only one is open at a time and the group has to jump at a time to avoid falling rapidly. I've tried and I can´t do it using timers :(
thanks again :D
User avatar
Grimwold
Posts: 511
Joined: Thu Sep 13, 2012 11:45 pm
Location: A Dungeon somewhere in the UK

Re: trap door sequence

Post by Grimwold »

The following post by Antti may help with what you are trying to do

viewtopic.php?f=14&t=3213&hilit=tick

He describes using a timer that calls a function every interval and depending on the value it does something different... could be used to create a sequence puzzle with pits opening and closing.
User avatar
Grimwold
Posts: 511
Joined: Thu Sep 13, 2012 11:45 pm
Location: A Dungeon somewhere in the UK

Re: trap door sequence

Post by Grimwold »

Ok I had a go at this myself... did a short 5 pit sequence, with at most 2 pits open at a time (to allow for walking between them) and it seemed to work pretty well.

- Create a series of pits and call them sequence_pit_01, sequence_pit_02,sequence_pit_03... etc. (for the purpose of this version of the script we need 5 pits)
- note: it will help understanding the script if you name the pits in the order in which they are to be closed.
- Make sure each pit is a trapdoor!
- Add a timer, name it pit_sequence_timer and set the interval as the length of time between one pit and the next closing.
- Add a script entity, call it pit_sequence and paste in the following script:

Code: Select all

time = 0

function openAllPits()
  for i in allEntities(party.level) do
      if i.id:sub(1,13) == "sequence_pit_" then
         i:open()
      end
   end
end


function startSequence()
  openAllPits()
  pit_sequence_timer:deactivate()
  time = 0
  pit_sequence_timer:activate()
end

function tick()
  if 
    time == 1 
  then
      sequence_pit_01:close()
  elseif 
    time == 2
  then
      sequence_pit_02:close()
  elseif 
    time == 3 then
      sequence_pit_01:open()
      sequence_pit_03:close()
  elseif 
    time == 4 then
      sequence_pit_02:open()
      sequence_pit_04:close()
  elseif 
    time == 5 then
      sequence_pit_03:open()
      sequence_pit_05:close()
  elseif 
    time == 6 then
      sequence_pit_04:open()
  elseif 
    time == 7 then
      sequence_pit_05:open()
      pit_sequence_timer:deactivate()
  end
time = time + 1
end
CONNECTIONS:
- connect the button to the script with the action startSequence
- connect the timer to the script with the action tick



Note: This works for 5 pits, if you want to add more pits it is no problem just add more blocks of elseif time == x statements and refer to the relevant pit names like so:

Code: Select all

  elseif 
    time == 6 then
      sequence_pit_04:open()
      sequence_pit_06:close()
script notes -
* when the button is pushed it first runs a function to open all pits in the level called "sequence_pit_XX"... this is to allow for the situation where the player keeps pressing the button once the sequence has started and forces a reset.
* The initial deactivate of the timer in the start function may not be necessary, but does allow scope for adjusting the interval in the script by first stopping the timer and restarting it. just add a setTimerInterval() command in between.
User avatar
Grimwold
Posts: 511
Joined: Thu Sep 13, 2012 11:45 pm
Location: A Dungeon somewhere in the UK

Re: trap door sequence

Post by Grimwold »

Grimwold wrote: * The initial deactivate of the timer in the start function may not be necessary, but does allow scope for adjusting the interval in the script by first stopping the timer and restarting it. just add a setTimerInterval() command in between.
Just thinking, It may be possible to adjust the timer based on the number of attempts the player has... so each time he falls down a pit, a pad triggers that increases the interval slightly... making the puzzle easier with each failure.
User avatar
Komag
Posts: 3658
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: trap door sequence

Post by Komag »

Nice adaptation! I used it before to set up a sequence of teleporters, very fun!
Finished Dungeons - complete mods to play
papazombie
Posts: 17
Joined: Sat Sep 15, 2012 1:00 am

Re: trap door sequence

Post by papazombie »

WOW, it works. thanks :D
Post Reply