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!
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.
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:
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
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
Last edited by Isaac on Tue Apr 19, 2016 7:34 am, edited 5 times in total.
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
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
THOM formaly known as tschrage _______________________________________________ My MOD (LoG1):Castle RingfortThread My MOD (LoG2):Journey To JusticeThread | Download
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().