[Script] Generic "Checkered Room" Plate Puzzle

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
User avatar
Grimwold
Posts: 511
Joined: Thu Sep 13, 2012 11:45 pm
Location: A Dungeon somewhere in the UK

[Script] Generic "Checkered Room" Plate Puzzle

Post by Grimwold »

This is number 5 in my puzzle framework series that can be added to your dungeon if you want this kind of puzzle.

The idea is that you can create something similar to the Checkered Room in the main game.. a series of pressure plates, some of which must be held down with items to open a door. There's nothing to say that the plates need to be anywhere near each other in this version however!

As usual you can use multiple copies of this script provided they go in separate script entities, and you change the counter variable to a unique name. You can even re-use some/all of the same plates and have multiple combinations opening different doors.

Firstly you'll need to place a door in your dungeon, along with a number of pressure plates. Then paste the following code into a script entity.

Code: Select all

counter_name = "plate_counter_1"
door_name = "checker_door_1"

function plateCheck()
  local plate_check = {
    plates = {"dungeon_pressure_plate_2","dungeon_pressure_plate_4","dungeon_pressure_plate_6","dungeon_pressure_plate_8","dungeon_pressure_plate_1", "dungeon_pressure_plate_3", "dungeon_pressure_plate_5","dungeon_pressure_plate_7","dungeon_pressure_plate_9"},
    states = {"down","down","down","down","up","up","up","up","up"}}
  if initialisation == 1 then
    for i=1,#plate_check["plates"] do
      local plate_entity = findEntity(plate_check["plates"][i])
      if plate_entity == nil then
        print(plate_check["plates"][i] .. " is missing")
        break
      else
        plate_entity:setActivateOnce(false)
        plate_entity:setTriggeredByParty(true)
        plate_entity:setTriggeredByMonster(false)
        plate_entity:setTriggeredByItem(true)
        plate_entity:addConnector("any",self.id,"plateCheck")
      end
    end
  end

  local range = math.min(#plate_check["plates"],#plate_check["states"])
  local counter_entity = findEntity(counter_name)
  local door_entity = findEntity(door_name)
  if counter_entity == nil then
    spawn("counter",self.level,self.x,self.y,self.facing,counter_name)
      :setInitialValue(range)
      :setValue(range)
      :addConnector("activate",door_entity.id,"open")
      :addConnector("deactivate",door_entity.id,"close")
  end
  local counter_entity = findEntity(counter_name)
  for i = 1,range do
    local plate_entity = findEntity(plate_check["plates"][i])
    if plate_entity ~= nil then
      if plate_check["states"][i] == "up" and plate_entity:isUp() then
        counter_entity:decrement()
      elseif plate_check["states"][i] == "down" and plate_entity:isDown() then
        counter_entity:decrement()
      end
    end
  end
-- if we get to here and the counter is not 0 we reset the counter
  if counter_entity:getValue() ~= 0 then
    counter_entity:reset()
  end
  if initialisation == 1 then
    initialisation = 0
  end
end

initialisation = 1

plateCheck()
Finally, change the variables in the first few lines of the script as follows:

counter_name = "plate_counter_1"
replace the text plate_counter_1 with a unique name for a counter. You do not need to place the counter in the dungeon, but you need to make sure that this ID is not used for anything else in your dungeon (and does not duplicate the ID of a counter in a subsequent copy of this script)

door_name = "checker_door_1"
replace the text checker_door_1 with the ID of the door you want to open with this puzzle. You must place this door somewhere in your dungeon.

plates = {"dungeon_pressure_plate_2","dungeon_pressure_plate_4","dungeon_pressure_plate_6","dungeon_pressure_plate_8","dungeon_pressure_plate_1", "dungeon_pressure_plate_3", "dungeon_pressure_plate_5","dungeon_pressure_plate_7","dungeon_pressure_plate_9"},
replace the entries in this list with the IDs of the pressure plates that you placed in your dungeon. You can add as many entries here as you want, but should avoid duplicates. As this is not a sequence puzzle, the order does not matter.

states = {"down","down","down","down","up","up","up","up","up"}}
replace the entries in this list with the corresponding states of the plates in the previous list. so in this case dungeon_pressure_plate_2 must be down (have an item (or party) on it), while dungeon_pressure_plate_1 must be up (no item/party)
Last edited by Grimwold on Thu Dec 20, 2012 5:15 pm, edited 2 times in total.
User avatar
Komag
Posts: 3659
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: [Script] Generic "Checkered Room" Plate Puzzle

Post by Komag »

These are nice, I've moved my links to the other ones and added a link to this one into the Script Repository instead of directly from the Editing Superthread, everything fits better now :)
Finished Dungeons - complete mods to play
Post Reply