Author Topic: GetIsDead vs EffectDeath  (Read 325 times)

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
GetIsDead vs EffectDeath
« on: September 24, 2015, 02:23:50 pm »


               

I hit an interesting problem while trying to get my trolls to work right.  The basic gist is that it seems applying a death effect to a creature causes the OnDeath handler to run right then, but does not modify hitpoints until after that. It appears that, as the Lexicon implies, GetIs Dead relies on the creature's hit points.  My on death scripts have a GetIsDead check at the top because I read that creatures fleeing the map have their death scripts run and I did not want that. (I have not validated that that is indeed the case so the check may not be needed).  But what happens is the GetIsDead returns FALSE when the OnDeath handler runs but TRUE when tested in the line after the ApplyEffectToObject.


 


I can finagle a work around when I get back to it.  But I was wondering if anyone else had noticed this before.


 


This is basically what I'm doing (from the OnDamaged handler):



SendMessageToPC(OBJECT_SELF, "TROLL - kill troll called - removing immortal flag...");
SetImmortal(oTroll,FALSE);   
ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectDeath(), oTroll);
SendMessageToPC(OBJECT_SELF, "TROLL - killed dead = "+IntToString(GetIsDead(oTroll)));

And this is what it shows:


[CHAT WINDOW TEXT] [Wed Sep 23 22:09:59] TROLL - kill troll called - removing immortal flag...

[CHAT WINDOW TEXT] [Wed Sep 23 22:09:59] OnDeathHandler Fires for large humanoid

[CHAT WINDOW TEXT] [Wed Sep 23 22:09:59] tb_npc_death called, is dead = 0 hp = 1

[CHAT WINDOW TEXT] [Wed Sep 23 22:09:59] Andorian Fireblood killed large humanoid

[CHAT WINDOW TEXT] [Wed Sep 23 22:09:59] TROLL - killed dead = 1

 


The tb_npc_death script is called from the ondeath handler and stops because GetIsDead return 0.



               
               

               
            

Legacy_Proleric

  • Hero Member
  • *****
  • Posts: 1750
  • Karma: +0/-0
GetIsDead vs EffectDeath
« Reply #1 on: September 24, 2015, 04:06:55 pm »


               Rather than use EffectDeath, I apply EffectDamage (current HP + 1). That way, OnDeath fires reliably, and other functions like GetIsDead work normally. i can't think of a reason for using EffectDeath offhand, it definitely doesn't work as you'd expect.
               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
GetIsDead vs EffectDeath
« Reply #2 on: September 24, 2015, 04:24:05 pm »


               

Yes, I can work around it. That would have been my next move last night if I had more time. It's not completely as simple as just doing damage because this is being called from the on damaged handler so I'll have to set a variable to keep it from recursing. But that's easy enough.


 


But my point was more general.  The implication here is that any spells which kill with a death effect will fail to report GetIsDead when the ondeath handler runs. So independent of my specific issue checking for GetIsDead in the ondeath handler may be a mistake.


 


Do you know about creatures fleeing the map? Maybe that's an old caveat. I'm assuming it was referring to ActivateFleeToExit(). But that code seems to just use DestroyObject so I'm not sure what that was about. Maybe I'll just remove the check for isdead...


               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
GetIsDead vs EffectDeath
« Reply #3 on: September 24, 2015, 06:25:46 pm »


               

Thats... weird, try disable nwnx. Nwnx_fixes might have influence on that. Though, I didnt had a chance to test this in vanilla mod yet so maybe its vanilla issue...



               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
GetIsDead vs EffectDeath
« Reply #4 on: September 24, 2015, 06:58:15 pm »


               

Yeah, this is a single player test module.  It's got all my haks and cpp1.71 but no nwnx. I don't think there is anything in any of those that could effect this. Seems to be in the engine.  It is weird.