Page 1 of 1

Trapdoor-sequence puzzle script

Posted: Tue Oct 30, 2012 8:01 am
by Ahmyo
I had the idea to use a trapdoor sequence puzzle in my dungeon and went looking for resources on how to script one but did not find one in the useful scripts repository. I found the one Komag put together and just thought it should be more easy to find, and put into the useful scripts repo, If that's alright.

Code: Select all

    steps = 9 -- CUSTOMIZE: HOW MANY STEPS YOU HAVE
    namepart = "pitpuz" -- CUSTOMIZE: PARTIAL ID OF PITS (WITHOUT THE NUMBER)

    time = 1
    function pitSequence()
      local thetimer = pitpuztimer -- CUSTOMIZE: ID OF THE TIMER
      local sequence = { pitpuz7, pitpuz4, pitpuz1, pitpuz2, pitpuz3, pitpuz6, pitpuz5, pitpuz8, pitpuz9 } -- CUSTOMIZE: IDS OF THE PITS YOU WANT TO CLOSE, IN ORDER
      if levercount == 2 then
        if time < steps + 1 then
          sequence[time]:deactivate() --close a pit in the sequence
        end
        if time > 2 then
          sequence[time-2]:activate() --and then open a pit again two steps behind
        end
        time = time + 1
        if time == steps + 3 then
          time = 1
          thetimer:deactivate()
        end
      elseif levercount == 1 then
        if time > 2 then
          sequence[time-2]:deactivate() --close a pit in the sequence
        end
        if time < steps + 1 then
          sequence[time]:activate() --and then open a pit again two steps behind
        end
        time = time - 1
        if time == 0 then
          time = steps + 2
          thetimer:deactivate()
        end
      end
    end

    levercount = 2
    function leverPull()
      local thetimer = pitpuztimer -- CUSTOMIZE: ID OF THE TIMER
      local thelever1 = pitpuzlever1 -- CUSTOMIZE: ID OF THE FIRST LEVER
      local thelever2 = pitpuzlever2 -- CUSTOMIZE: ID OF THE SECOND LEVER
      if thelever1:getLeverState() == "activated" and
        thelever2:getLeverState() == "activated" then
          levercount = 2
          time = 1
      elseif thelever1:getLeverState() == "deactivated" and
        thelever2:getLeverState() == "deactivated" then
          levercount = 2
          time = 1
      else
        levercount = 1
        time = steps + 2
      end
      for i=1,steps do
        local pit = findEntity(namepart..i)
        if pit then
          pit:activate()
        end
      end
      thetimer:deactivate()
    end
And of course, I don't take credit for the script.

Source:

viewtopic.php?f=14&t=3381&start=10#p34279

Re: Trapdoor-sequence puzzle script

Posted: Tue Oct 30, 2012 8:08 am
by Ahmyo
My question is, how would one replace the levers with pressure plates?

Re: Trapdoor-sequence puzzle script

Posted: Tue Oct 30, 2012 11:19 am
by Komag

Code: Select all

      if thelever1:getLeverState() == "activated" and
        thelever2:getLeverState() == "activated" then
          levercount = 2
          time = 1
      elseif thelever1:getLeverState() == "deactivated" and
        thelever2:getLeverState() == "deactivated" then
becomes...

Code: Select all

      if thePlate1:isDown() and
        thePlate2:isDown() then
          platecount = 2
          time = 1
      elseif thePlate1:isUp() and
        thePlate2:isUp() then
and it's already in the repository, under 2.1.13 :)

Re: Trapdoor-sequence puzzle script

Posted: Tue Oct 30, 2012 9:24 pm
by Ahmyo
OH okay thanks! I missed it :mrgreen: