OnDamaged

From NWN Lexicon
Jump to: navigation, search

OnDamaged

The script attached to this event fires when the object is damaged.


Trigger

Creature, door, or placeable object has lost hit points, apart from instant death.


Function(s)

DetermineCombatRound(object, int) for standard combat actions.


Remarks

If a creature was hurt by someone they cannot see, they attempt to search for the attacker; if they can see their attacker, they locate the target and attack it.


Known Bugs

GetDamageDealtByType will only return damage amounts for EffectDamage, and so no physical attack damage will be picked up.


Example

// place in a creature's OnDamaged event
// when the creature loses more than half of his hit points, he 
// will retreat to a waypoint tagged "CAVE_EXIT" and disappear 
void main()
{
     int nEvent = GetUserDefinedEventNumber();
     if (nEvent = 1006) // OnDamaged event 
     {
          int nMaxHP = GetMaxHitPoints(); // OBJECT_SELF (the caller) is default
          int nCurHP = GetCurrentHitPoints(); // OBJECT_SELF (the caller) is default
          // if less than half of maximum
          if (nCurHP < (nMaxHP / 2))
          {
               // stop whatever the creature is doing
               ClearAllActions();
               // cry out in fear
               ActionSpeakString("I'm being violated!");
               // get the hell outta Dodge
               ActionMoveToObject(GetObjectByTag("CAVE_EXIT"), TRUE);
               // destroy itself (simulate a clean getaway)
               ActionDoCommand(DestroyObject(OBJECT_SELF));
               // accept no further AI commands (destroyed!)
               SetCommandable(FALSE);
          }
     }
}

See Also

functions: 

GetTotalDamageDealt()