Page 1 of 1

Check Monster Dead? Help!

Posted: Sat Apr 16, 2016 6:55 am
by Mysterious
Hello all.

I have tried a few methods of finding out if a Monster is dead or not, but have failed badly :( I don't know how to do the Coding for this at all as I have discovered.

What I need is to find out if eg: forest_ogre_1 is dead, if he is then it runs a script function. If he is still alive then it would run a different script function.

I basically want to use this code for a couple of quests. Any help on this please, thank you.

Re: Check Monster Dead? Help!

Posted: Sat Apr 16, 2016 7:55 am
by minmay
MonsterComponent:isAlive() returns true if the monster is alive, and false if the monster is dead.

Re: Check Monster Dead? Help!

Posted: Sun Apr 17, 2016 7:30 am
by Isaac
Mysterious wrote:What I need is to find out if eg: forest_ogre_1 is dead, if he is then it runs a script function. If he is still alive then it would run a different script function.
Just as minmay said above; the general solution.

In your case, for your monster, it should probably be the following:

Code: Select all

function deadCheck()
  if findEntity("forest_ogre_1") and forest_ogre_1.monster and not forest_ogre_1.monster:isAlive() then
     print("forest_ogre_1 is dead!")
    else
     print("forest_ogre_1 is alive!")
   end
end
SpoilerShow
Alternatively:

Code: Select all

function deadCheck(monster_id)
 local target = findEntity(monster_id)
  if target ~= nil then
     if target.monster and not target.monster:isAlive() then
       print(monster_id.." is dead!")
      else
       print(monster_id.." is alive!")
       return false --not dead
     end
  end
 return true --dead	
end

script_entity_1.script.deadCheck("zarchton_1")
*Edited to swap target for findEntity

Re: Check Monster Dead? Help!

Posted: Mon Apr 18, 2016 8:27 am
by Eleven Warrior
Thxs matey this is cool I was looking for something like this the other day. Thxs :)

Re: Check Monster Dead? Help!

Posted: Mon Apr 18, 2016 10:37 pm
by Zo Kath Ra
How about this:

Code: Select all

function monsterIsAlive(monster_id)
	local entity = findEntity(monster_id)
	
	if (entity) and (entity.monster) and (entity.monster:isAlive()) then
		return true
	else
		return false
	end
end

Re: Check Monster Dead? Help!

Posted: Mon Apr 18, 2016 10:54 pm
by THOM
I don't understand, why you all are asking for the monster-component? And the isAlive could be important if the monster was killed a few seconds before the query of the script. But isn't it in most cases enough to ask simply

if ogre_1 ~= nil then :?:

Re: Check Monster Dead? Help!

Posted: Mon Apr 18, 2016 11:21 pm
by minmay
No. The parent object hangs around for a few seconds after the monster is killed, to handle the death particle effect and so on. You must use MonsterComponent:isAlive().