onDie hook/counter problem

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
haffhedd
Posts: 6
Joined: Wed May 21, 2014 5:49 pm

onDie hook/counter problem

Post by haffhedd »

Hey there,

Once again, I have hit a brick wall with my dungeon.

I've searched a few similar threads about the onDie function, specifically:
viewtopic.php?f=14&t=3239
viewtopic.php?f=14&t=3784#p38693
viewtopic.php?f=14&t=3885

These were helpful for steering me in the right direction but most of these related to having a single monster trigger a door to open.

What I would like is a little different. I'd like a door to open only after 3 monsters have been killed.

I could take the easy route and just have one of the monsters trigger the door on death, but then I don't learn anything and it's a bit awkard.

Here are the steps I took:
SpoilerShow
1) I set up a counter in my dungeon with an initial value of 3. I named the counter monsterDoor
2) I placed a door. I set its ID as: monsterdeadDoor
3) I cloned a snail in the monsters.lua document with the code below. 3 of these cloned snails were added to my dungeon.

Code: Select all

cloneObject{
   name="SnailDoor",
   baseObject="snail",
        onDie=function(monster)
        monsterDoor:decrement()
   end
}
4) Created a script_entity in the dungeon*.

Code: Select all

function monsterOpen()
	monsterDoor:getValue()
	if monsterDoor == 0 then
		monsterdeadDoor:open()
		else
		monsterdeadDoor:close()
	end
end
5) I also created a pressure plate connected to another script entity to verify that the counter value was decreasing with each monster death.

Code: Select all

function printCounter()
print(monsterDoor:getValue())
end

*I have also tried connecting this script to a button and a timer that triggers every 1 second. Doesn't make a difference.
With this approach, I can verify that monsterDoor is decreasing with each cloned snail death. For whatever reason, when monsterDoor reaches 0, the door doesn't open.

It doesn't matter if I use a connector from the counter to the door without the script_entity, a button/timer to trigger the script_entity, or any other combination, the door refuses to open.

Any insights or advice would be appreciated.

Thanks.
User avatar
msyblade
Posts: 792
Joined: Fri Oct 12, 2012 4:40 am
Location: New Mexico, USA
Contact:

Re: onDie hook/counter problem

Post by msyblade »

You may try to add this into the hook:

Code: Select all

      if (monsterDoor:getValue() == 0) then
monsterDeadDoor:Open()
If it doesnt work, try "getValue() == 1", because it is possible the script will check the get value before the decrement. Might work, might not, but only one way to find out!

Hope this helps!
Currently conspiring with many modders on the "Legends of the Northern Realms"project.

"You have been captured by a psychopathic diety who needs a new plaything to torture."
Hotel Hades
haffhedd
Posts: 6
Joined: Wed May 21, 2014 5:49 pm

Re: onDie hook/counter problem

Post by haffhedd »

^
That did the trick.

My hook now looks like this:

Code: Select all

cloneObject{
   name="SnailDoor",
   baseObject="snail",
      onDie=function(monster)
      monsterDoor:decrement()
         if (monsterDoor:getValue() == 0) then
             monsterdeadDoor:open()
             else
             monsterdeadDoor:close()
          end
      end
}
For whatever reason, the game would crash if I didn't have an else argument. Just thought I'd point that out.

Also nice to know that you have to get the value before comparing it to 0. I sort of tried that in my above code but before the if. Whoops haha.

Seems to work fine now. Thanks for the help.
User avatar
msyblade
Posts: 792
Joined: Fri Oct 12, 2012 4:40 am
Location: New Mexico, USA
Contact:

Re: onDie hook/counter problem

Post by msyblade »

Yaaay, I helped someone with minimum hair pulling! No really, I'm glad it worked out, and am also glad you were savvy enough to add the "else" lines and try it on your own. :D
Currently conspiring with many modders on the "Legends of the Northern Realms"project.

"You have been captured by a psychopathic diety who needs a new plaything to torture."
Hotel Hades
User avatar
Eleven Warrior
Posts: 752
Joined: Thu Apr 18, 2013 2:32 pm
Location: Australia

Re: onDie hook/counter problem

Post by Eleven Warrior »

Hi Haffhed :)

I was a little curious about what you were doing. When the Monster dies a door open I can see that, but the counter you may not need just for one cloned Monster. The code below does the same thing as your code but no Counter needed. When the Mummy dies all sorts of things can happen (see below)

Code: Select all

cloneObject{
name = "boss_mummy_1",
baseObject = "mummy_grunt",
	healthIncrement = 25,
	attackPowerIncrement = 10,
	protectionIncrement = 10,

onDie = function(self) -- The onDie Hook --

	delay_shala_door:activate()
            death_timer:activate()
	       playSound("scream_of_death")
	          dm_wall_secret_window_6:open()

HiddenRoom1.DoorScript()  --- Script function Activates ---

hudPrint("NNOOOOOOooooooooooo!!")
hudPrint("")
hudPrint("")
hudPrint("Eldra Mummy Boss defeated: Gained 250 Xp.")

	spawn("dm_floor_skeleton", self.level, self.x, self.y, self.facing)
		for i = 1,4 do party:getChampion(i):gainExp(300) end
		   end
}
Post Reply