Page 1 of 5

how to "action" when monster dies.

Posted: Wed Sep 19, 2012 1:57 pm
by roachburn
I am looking for a way to do something such as open a door after a monster dies. How would I go about doing this? something along the lines of
if skeleton_patrol:isDead() then
trapdoor1:activate()

Re: how to "action" when monster dies.

Posted: Wed Sep 19, 2012 2:16 pm
by petri
You can implement a custom onDie hook or just check if the id is non-existant, for example, in a script connected to a pressure plate. For example, if not findEntity("skeleton_patrol_1") then print("skeleton_patrol_1 not found in the dungeon") end. Of course with the latter the check is only executed when the pressure plate is activated.

Re: how to "action" when monster dies.

Posted: Wed Sep 19, 2012 2:29 pm
by roachburn
Interesting, I don't think that will work in my case though. What I have is a room that closes the door behind when a pressure plate is stepped on. A skeleton patrol is teleported to the room as well. I want the door behind and a door leading further ahead to open when the patrol is killed.

Re: how to "action" when monster dies.

Posted: Wed Sep 19, 2012 2:33 pm
by petri
How about setting up a timer with frequency, say, 1 second. Then when the timer activates check for the id and if it does not exist, open the door (you could also disable the timer at this point because it's not needed anymore and just wasted CPU cycles)?

Or you could make a custom monster with onDie.

Re: how to "action" when monster dies.

Posted: Wed Sep 19, 2012 2:47 pm
by Komag
ah, the classic Zelda fight - kill the baddies to open the doors

Re: how to "action" when monster dies.

Posted: Wed Sep 19, 2012 3:19 pm
by Montis
When the player is trapped like you described, the following scriptless approach should also work (might need testing):
  • Place hidden pressure plates all over the room that are only triggered by monsters.
  • Connect all pressure plates twice to a counter that has an initial value of 0. Set the events to activate -> increment, deactivate -> decrement.
  • Connect the counter to all doors with deactivate -> close.
  • Place a timer with an interval set to 1 with an a connection to all the doors activate -> open.
  • Connect the timer also to itself with activate -> deactivate (so the timer stops and doesn't try to open the doors constantly).
  • Connect the counter with the timer: any -> toggle.
What you also should do is put blockers in the tunnels leading to the room so that no wandering monster accidentally traps itself and blocks your path if you want to backtrack.

Also, In theory a much simpler approach might even work to just connect each plate to the doors on the "any" event to "toggle", but it will probably just play the door open and door close sound a lot of times when the monsters move through the room.

Re: how to "action" when monster dies.

Posted: Wed Sep 19, 2012 11:24 pm
by pulpum
Montis wrote:When the player is trapped like you described, the following scriptless approach should also work (might need testing):
  • Place hidden pressure plates all over the room that are only triggered by monsters.
I was thinking the same thing as you. hidden pressure plates are very powerful tool !

Re: how to "action" when monster dies.

Posted: Thu Sep 20, 2012 7:58 am
by roachburn
Interesting. I used your idea with the hidden pressure plates, and it works great! Thanks a bunch guys! I think I am going to try the other ideas also just for learning purposes. I could'nt figure out how to do an ondie trigger, but I am sure I can figure it out eventually. I just really don't know much about programming. The only programming I have ever done was with My Arduino microcontroller, which in most cases I would just copy someone else's code for the project I was working on hehe. I sure am learning though and its tons of fun :D . The one thing I think is really cool about programming is that there are so many different ways to do the same thing, and some can be very efficient and others not so much but get the job done.

Re: how to "action" when monster dies.

Posted: Mon Sep 24, 2012 1:22 am
by Daovala
not sure if this is much help, but maybe someone will find this useful. I needed a system to spawn a monster to replace one that died in a room for my dungeon so that there will always be one monster to work with heres the basics of it:
exit are filled with blockers to stop monster from leaving,
the whole room is filled with pressure plates (hidden and only activate by monsters) set to
-on deactivate start spawntimer
-on activate start resettimer
resettimer is set to 1 second and deactivates itself and the spawn timer
spawntimer is set to 3 seconds or more and tiggers the spawner and turns itself off
(and if desired connect it too a counter to count spawns/kills) the counter could be hooked up to any number of things to be useful (stop spawns, open doors etc...)
by default all timers need to be off and require an external kickstart on the spawntimer so far

Re: how to "action" when monster dies.

Posted: Sat Sep 29, 2012 8:56 pm
by Komag
I want to use the onDie hook, but I don't know what to do, how to use it, how to set things up or make any connection.