Grimwold's Grimrock Puzzle Frameworks

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
User avatar
Eightball
Posts: 48
Joined: Thu Jan 09, 2014 8:21 am

Re: Grimwold's Grimrock Puzzle Frameworks

Post by Eightball »

Wow, Komag! Thanks so much. Your script is much more compact and easy to reuse and customize than mine was going to be.
If you don't mind, I'll post it here as another standard framework.

THE STARING CONTEST FRAMEWORK
SpoilerShow

Code: Select all

-- Staring at the south wall opens the secret doors there.
-- Changing direction or moving from the plate will deactivate the event.
-- by Komag in "Legend of Grimrock: Remake"
stareCounter = 0

function stareCheck()
  if party.facing ~= 2 then
    stareCounter = 0
    return
  end
  if party.facing == 2 then
    stareCounter = stareCounter + 1
  end
  if stareCounter == 120 then
    stareDoor_1:open()
    stareDoor_2:open()
    stareDoor_3:open()
  end
end

function stareReset()  
-- set the starePlate to call this function and
-- to deactivate the timer when the party moves off of it 
-- (i.e. when the plate deactivates).
  if starePlate:isUp() then
    stareCounter = 0
  end
end
The timer is set to do the stareCheck every 0.1 second (counter is now part of the script, so no need to create one via the editor).
Then the door opens when the in-script counter reaches a certain number of unbroken and successful stareChecks. It should be noted that as it stands, this counter total is not in seconds, but in number of times the timer hits 0.1 seconds. So setting the counter total to 10 would be just one second of staring.

Komag uses two pressure plates, one hidden (the real one) and one normal (just for show), though I didn't need to. One reason to do this is if a monster activates the plate and sits on it long enough while the party faces the right direction (anywhere in the level), the stareDoor(s) will open. Also, for the same reason, it is important to make the real plate (or your only one) to be unresponsive to items placed on it. Unless of course, you want to have a mobile staring contest?
hyteria
Posts: 266
Joined: Sat Dec 29, 2012 8:22 pm

Re: Grimwold's Grimrock Puzzle Frameworks

Post by hyteria »

hey , great thread

by the way this is working with grimrock 2?

thx
User avatar
Grimwold
Posts: 511
Joined: Thu Sep 13, 2012 11:45 pm
Location: A Dungeon somewhere in the UK

Re: Grimwold's Grimrock Puzzle Frameworks

Post by Grimwold »

hyteria wrote: Sun Nov 01, 2020 12:25 am hey , great thread

by the way this is working with grimrock 2?

thx
I recently spent a few hours trying to get some of these working in Grimrock 2 and unfortunately had no luck.. The problems stemmed from how I spawned in the timers etc. needed by these scripts.. this appears to have changed in LOG2 and I could not work out how to fix it.
DeckerZ
Posts: 2
Joined: Mon Apr 17, 2017 3:57 am

Re: Grimwold's Grimrock Puzzle Frameworks

Post by DeckerZ »

Hi, I love this MOD - Just wanted to know, if I can use it to open multiple doors. I have tried to add the additional door to the script, but not really knowing how scripts are meant to look I have not been successful. Any help is much appreciated.

Here is what I have so far.

Code: Select all

counter_name = "alcove_counter_4"
door_name = "dungeon_secret_door_9"
door_name = "dungeon_secret_door_10"

function newItemCheck()
  local item_check = {
    alcoves = {"dungeon_alcove_6","dungeon_alcove_17"}, 
    items = {"red_gem", "red_gem"}}
  if initialisation == 1 then
    for i=1,#item_check["alcoves"] do
      local alcove_entity = findEntity(item_check["alcoves"][i])
      if alcove_entity == nil then
        print(item_check["alcoves"][i] .. " is missing")
        break
      else
        alcove_entity:setActivateAlways(true)
        alcove_entity:addConnector("any",self.id,"newItemCheck")
      end
    end
  end
  local range = math.min(#item_check["alcoves"],#item_check["items"])
  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 alcove_entity = findEntity(item_check["alcoves"][i])
    if alcove_entity ~= nil and containsItem(alcove_entity, item_check["items"][i]) then
      counter_entity:decrement()
    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

-- This function returns true if the entity contains a given item.
-- It works for any entity that implements the containedItems() method.
function containsItem(entity, item)
  for i in entity:containedItems() do
    if i.name == item then
      return true
    end
  end
-- if we get here the item was not found
  return false
end

initialisation = 1

newItemCheck()
Post Reply

Return to “Modding”