OnDamaged
The script attached to this event fires when the object is damaged.
Trigger
Creature, door, or placeable object has had damage potentially applied, apart from cases of instant death (EffectDeath or similar).
The damage may have been resisted - in which case GetTotalDamageDealt may be even 0.
The function should always fire for cases of EffectDamage even if the target is completely immune.
The function will trigger for weapons but only if the weapon causes some kind of damage (where GetTotalDamageDealt would be a positive number). Use DAMAGE_TYPE_BASE_WEAPON with GetDamageDealtByType to determine this has occurred. However the OnPhysicalAttacked event fires regardless of if damage is applied or not (or even if the target hits).
Function(s)
These functions can be used on this event specifically:
- GetLastDamager - Who triggered the damage. Note that in many use cases this may be OBJECT_INVALID, see definition.
- GetTotalDamageDealt - The total amount of damage that triggered this event. This may be 0 if the damage was all resisted.
- GetDamageDealtByType - Check what damage was done of different kinds
The AI usually runs DetermineCombatRound(object, int) for standard combat actions.
Remarks
This relays information into the AI scripts, the Bioware AI may search for the person who dealt it damage or swap targets to someone who damaged it highly.
This event may fire before or after OnPhysicalAttacked so to get the weapon used that dealt the damage is sometimes difficult. You can determine if it was a ranged weapon by checking the creatures right hand weapon if DAMAGE_TYPE_BASE_WEAPON is not -1.
Known Bugs
Weapons which have dealt no damage may cause this script to not fire, even though other cases of resisting damage causes it to fire. Given it fires the OnPhysicalAttacked script in either case it will still trigger an AI to attack back correctly.
Note: Previously GetDamageDealtByType could not pick up physical attacks at all but this has now been fixed.
Example
// 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: |