
Check if spawned monster is dead [Solved]
Check if spawned monster is dead [Solved]
I was trying to check if the monster spawned by spawner is dead but with no success, can anyone help? 

Last edited by Jouki on Sat Nov 01, 2014 1:36 am, edited 2 times in total.
Re: Check if spawned monster is dead
It looks like a spawned entity still exists for a few seconds, at least, after it is killed. You can probably put a hook into a cloned monster using onDie or something, but if you don't mind waiting a few seconds (according to my testing anyway), you can just use the findEntity method. This script demonstrates what I found:
Attach a pressure plate to the spawnIt function (making sure there is a space to the south as per the c.y + 1 code). It will spawn a turtle if one hasn't already been spawned and it runs the checkIt function every second to see if the creature still exists. In my testing, the hudPrint triggers about 3 - 4 seconds after the turtle is killed. Now, this may be because it is actually destroyed or because the garbage collection got it. You'll just have to play with this idea to see if it meets your needs or not. If not, the cloning monster approach should work... not that I've tried it yet.
I hope this helps, -Lark
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
I hope this helps, -Lark
Re: Check if spawned monster is dead
I'd say this delay is because editor has a long tick before next update. hmm actaully this could be fatal for me, thank you though it's a good start. I was thinking about doing via bossfight but without music and health bar but idk how to remove health bar.
Re: Check if spawned monster is dead
Mouahahaha Lark, since modders seen that delayedCall function is here, everybody use it :p Gratz and thanks for help 

Re: Check if spawned monster is dead
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.
Steven Seagal of gaming industry
Re: Check if spawned monster is dead
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.
edit:
ok I figured out a little bit but it's not completed. I need fix the condition when I start checking before I spawn the turtle. variable "yourFoe" is not declared in that situation. How could I declare this variable (instead of using counter)
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

Re: Check if spawned monster is dead
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
Links to my YouTube playlist of "tutorials" and to my forum thread.
Re: Check if spawned monster is dead
Thanks Prozail! I knew onDie should work, but I just hadn't had time to try it yet. This is a much better solution! Thanks again, -Lark
Re: Check if spawned monster is dead
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

Re: Check if spawned monster is dead
ok I hope I have the last question. What does exactly mean c=c.go and why function has this variable in parameter? does the pressure plate send any parameter?
edit: and wth?!
why is this not working but this yeah
Only change is the second one is not pair but classic trooper. I guess it's about "pair" monsters are not "monster" but something else, but what...
ok I'm starting to think I'm the dumbest modder ever xD problem was pair is "monstergroup"
edit: and wth?!
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")
ok I'm starting to think I'm the dumbest modder ever xD problem was pair is "monstergroup"