Torquemada wrote:Here's my simple question, I hope the answer is as simple
I want a door to open when a monster group is dead. It's simple with a single monster but the group doesn't have onDie hook
A quick—but not scrupulously accurate way, is to track the monsters with a set, and consider them dead as you mark them off the list.
(This doesn't actually check to see if they're dead, but they shouldn't be alive either. There are cases in Grimrock where a dead monster can still exist.)
Code: Select all
--List the monsters in the set here
set = { "zarchton_1",
"zarchton_2",
"zarchton_3",
"zarchton_4",
}
--Adds onDie hooks at load
for x = 1, #set do
local monster = findEntity(set[x])
if monster then
monster.monster:addConnector("onDie", self.go.id, "deadCheck")
end
end
--Gets called by each monster as they die
function deadCheck(caller)
--No entries, means they are all dead
if #set <= 1 then
dungeon_door_wooden_1.door:open()
return
end
--removes the dying monster from the set
for k,v in pairs(set) do
if v == caller.go.id then
table.remove(set, k)
break
end
end
end
Fill the list at the top with your own monster id strings, and change the id of the door to match yours.
*I just did a very minor update, that bypasses the table operation for the last monster. You can use the updated script, but the previous script would still work fine.