Check if spawned monster is dead [Solved]

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
User avatar
Jouki
Posts: 127
Joined: Fri Oct 24, 2014 12:57 pm

Check if spawned monster is dead [Solved]

Post by Jouki »

I was trying to check if the monster spawned by spawner is dead but with no success, can anyone help? :cry:
Last edited by Jouki on Sat Nov 01, 2014 1:36 am, edited 2 times in total.
User avatar
Lark
Posts: 178
Joined: Wed Sep 19, 2012 4:23 pm
Location: Springfield, MO USA

Re: Check if spawned monster is dead

Post by Lark »

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:

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
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
User avatar
Jouki
Posts: 127
Joined: Fri Oct 24, 2014 12:57 pm

Re: Check if spawned monster is dead

Post by Jouki »

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.
User avatar
Doridion
Posts: 256
Joined: Tue Jun 10, 2014 9:23 pm

Re: Check if spawned monster is dead

Post by Doridion »

Mouahahaha Lark, since modders seen that delayedCall function is here, everybody use it :p Gratz and thanks for help ;)
User avatar
antti
Posts: 688
Joined: Thu Feb 23, 2012 1:43 pm
Location: Espoo, Finland
Contact:

Re: Check if spawned monster is dead

Post by antti »

Jouki wrote:I'd say this delay is because editor has a long tick before next update.
Editor updates every frame as usual. The object needs to exist as long as it does anything, including the death sound and particles.
Steven Seagal of gaming industry
User avatar
Jouki
Posts: 127
Joined: Fri Oct 24, 2014 12:57 pm

Re: Check if spawned monster is dead

Post by Jouki »

antti wrote:
Jouki wrote:I'd say this delay is because editor has a long tick before next update.
Editor updates every frame as usual. The object needs to exist as long as it does anything, including the death sound and particles.
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)

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
by the way maybe it would be easier use the specify spawner just removing some of components but there's one problem. when I do this on undead their animation of spawning starts notwithstanding what I deactivate in components. It wouldnt be fatal for me but idk how to re-launch this animation of spawning undead :D
User avatar
Prozail
Posts: 158
Joined: Mon Oct 27, 2014 3:36 pm

Re: Check if spawned monster is dead

Post by Prozail »

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

User avatar
Lark
Posts: 178
Joined: Wed Sep 19, 2012 4:23 pm
Location: Springfield, MO USA

Re: Check if spawned monster is dead

Post by Lark »

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
User avatar
Jouki
Posts: 127
Joined: Fri Oct 24, 2014 12:57 pm

Re: Check if spawned monster is dead

Post by Jouki »

Prozail 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

perfect that's exactly what I need :P
User avatar
Jouki
Posts: 127
Joined: Fri Oct 24, 2014 12:57 pm

Re: Check if spawned monster is dead

Post by Jouki »

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?!

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")
why is this not working but this yeah

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")
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"
Post Reply