Check if spawned monster is dead [Solved]
Posted: Fri Oct 31, 2014 12:18 am
I was trying to check if the monster spawned by spawner is dead but with no success, can anyone help? 

Official Legend of Grimrock Forums
http://almosthumangames.com/forum/
Code: Select all
function spawnIt(c)
c = c.go
if not findEntity("turtle_guy") then
spawn("turtle", c.level, c.x, c.y + 1, c.facing, c.elevation, "turtle_guy")
delayedCall(self.go.id, 1, "checkIt")
end
end
function checkIt()
if not findEntity("turtle_guy") then
hudPrint("Your foe is no more!")
else
delayedCall(self.go.id, 1, "checkIt")
end
end
Editor updates every frame as usual. The object needs to exist as long as it does anything, including the death sound and particles.Jouki wrote:I'd say this delay is because editor has a long tick before next update.
actaully I can see when I spawn him in editor (I dont know how to say specify spawner with other component features as handlight 1 and handlight2 or summoning undead etc... at skeleton commander for example) there's a method "isAlive()" that returns boolean and I guess it was immediate. (not sure)antti wrote:Editor updates every frame as usual. The object needs to exist as long as it does anything, including the death sound and particles.Jouki wrote:I'd say this delay is because editor has a long tick before next update.
Code: Select all
function spawnIt(c)
c = c.go
if not findEntity("turtle_guy") then
yourFoe = spawn("turtle", c.level, c.x, c.y + 1, c.facing, c.elevation, "turtle_guy")
end
end
function checkIt()
if yourFoe.monster:isAlive() ~= true then
hudPrint("Your foe is no more!")
else end
end
Code: Select all
function spawnIt(c)
c = c.go
if not findEntity("turtle_guy") then
yourFoe = spawn("turtle", c.level, c.x, c.y + 1, c.facing, c.elevation, "turtle_guy")
-- add this line to catch the "onDie" event on the spawned monster
yourFoe.monster:addConnector("onDie",self.go.id,"nowimdead")
end
end
-- now this function gets alot simpler.
function nowimdead()
hudPrint("Your foe is no more!")
end
perfect that's exactly what I needProzail wrote:i would do something like this instead.
Code: Select all
function spawnIt(c) c = c.go if not findEntity("turtle_guy") then yourFoe = spawn("turtle", c.level, c.x, c.y + 1, c.facing, c.elevation, "turtle_guy") -- add this line to catch the "onDie" event on the spawned monster yourFoe.monster:addConnector("onDie",self.go.id,"nowimdead") end end -- now this function gets alot simpler. function nowimdead() hudPrint("Your foe is no more!") end
Code: Select all
enemySkeleton1 = spawn("skeleton_trooper", c.level, c.x + 1, c.y, c.facing + 2, c.elevation, "skeletonTroop")
enemySkeleton2 = spawn("skeleton_trooper_pair", c.level, c.x + 2, c.y + 2, c.facing + 2, c.elevation, "skeletonPair")
enemySkeleton1.monster:addConnector("onDie",self.go.id,"deadCheckerSkeleton")
enemySkeleton2.monster:addConnector("onDie",self.go.id,"deadCheckerSkeleton")
Code: Select all
enemySkeleton1 = spawn("skeleton_trooper", c.level, c.x + 1, c.y, c.facing + 2, c.elevation, "skeletonTroop")
enemySkeleton2 = spawn("skeleton_trooper", c.level, c.x + 2, c.y + 2, c.facing + 2, c.elevation, "skeletonPair")
enemySkeleton1.monster:addConnector("onDie",self.go.id,"deadCheckerSkeleton")
enemySkeleton2.monster:addConnector("onDie",self.go.id,"deadCheckerSkeleton")