Page 1 of 1

Any way to query monster health or if monster is dead?

Posted: Thu Nov 08, 2012 3:28 am
by JohnWordsworth
I've got an iterator that runs using the allEntities() function but have run into a strange problem. If I kill a monster and it's still dying (the death animation is playing) and then call my method which iterates over the entities in the game world, then it will find the dying monster in the list.

This is a bit of a problem for me (not the end of the world, I can probably work around it by writing a hook for these monster types so that the IDs go into a big list of 'dying' monsters), but if there is an easy way to find out if a monster's health is 0 or below and/or if it's dead - that would be really useful!

Re: Any way to query monster health or if monster is dead?

Posted: Thu Nov 08, 2012 5:32 am
by Batty
I don't think there's an easy way because there's no monster:getHealth() function (even though we have setHealth()). A fun, complicated solution would be to use the onDamage hook to automatically decrease the monster's health (a global monster health table would be needed) then you could make your own getHealth(monster.id) function. Looks like you already thought of something like that.

You must be doing some heavy iterating to catch this limbo moment when the monster is dead but still in the game. Interesting to know that the monster persists until that death effect finishes.

Re: Any way to query monster health or if monster is dead?

Posted: Thu Nov 08, 2012 9:24 am
by Xanathar
If you go down Batty's route, beware of hard dificulty level: monsters have more health (I was looking for a getHealth exactly yesterday too, to understand exactly what the difficulty level gap is).

Re: Any way to query monster health or if monster is dead?

Posted: Thu Nov 08, 2012 12:47 pm
by Komag
does the difficulty simply raise the monster level? I've never actually paid attention, but if so, you could just check how much XP the kill gets you and check the info tables here:
viewtopic.php?f=14&t=3285

Re: Any way to query monster health or if monster is dead?

Posted: Thu Nov 08, 2012 1:10 pm
by JohnWordsworth
Thanks for the suggestions guys. I've got a reasonable solution going which, as I'm only concerned about a couple of specific monsters in my search, I've just updated their onDie method to 'registerAsDead' the monster which stores the monster's ID and the tick to delete the item at. I have a timer that ticks every second running anyway, so I've hooked that into my list of dead monsters, and it simply deletes entries in that table after they have been there for 8 seconds (just to keep it from getting large).

Suggestion to the devs though - it would be really useful if you could just do a 'isDead()' or 'getHealth()' call on the monster!

@Batty: Not too heavy, it's just triggered by a user action - so it's more than possible that the user decides to trigger this action just after killing a monster. Which then caused havoc with my room in the community dungeon!

Re: Any way to query monster health or if monster is dead?

Posted: Thu Nov 08, 2012 2:16 pm
by Kuningas
It could be that the monsters completely cease to exist on death, but an onDie hook and a variable should be a viable solution, I quess.

Re: Any way to query monster health or if monster is dead?

Posted: Thu Nov 08, 2012 5:42 pm
by petri
JohnWordsworth wrote:Suggestion to the devs though - it would be really useful if you could just do a 'isDead()' or 'getHealth()' call on the monster!
Thanks for the feedback! I'll add this to the todo list. Hopefully I'll get some time to actually do some work on the modding side soon.

Re: Any way to query monster health or if monster is dead?

Posted: Fri Nov 09, 2012 2:54 am
by Neikun
petri wrote:
JohnWordsworth wrote:Suggestion to the devs though - it would be really useful if you could just do a 'isDead()' or 'getHealth()' call on the monster!
Thanks for the feedback! I'll add this to the todo list. Hopefully I'll get some time to actually do some work on the modding side soon.
We miss you, Petri! <3
I'm sure whatever's taking up your time is equally spiffy.

Re: Any way to query monster health or if monster is dead?

Posted: Fri Nov 09, 2012 3:06 am
by JohnWordsworth
Great to hear Petri. I love the fact you're able to put the time in to keep up with the modding forums and notice posts like these regardless of how busy things seem to be with your office move and other exciting projects.

Re: Any way to query monster health or if monster is dead?

Posted: Sat Nov 24, 2012 2:09 pm
by Komag
Looks like this will be added in the next patch, very nice! Will be so much easier to do certain things :)