GetAttemptedSpellTarget()

From NWN Lexicon
Revision as of 21:06, 21 October 2021 by Jasperre (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Determines the creature a spell was attempted to be cast at.

Description

Return the target at which the caller attempted to cast a spell. This value is set every time a spell is cast and is reset at the end of combat. The spell itself may not be actually being cast - the NPC may be moving towards the target to get in range to cast at the time.

If ActionCastSpellAtObject is used it will return the target object (usually a creature, placeable or door). Interestingly if ActionCastSpellAtLocation is used the target object is the area the target location is (usually the same are the NPC is in).

Returns OBJECT_INVALID if the caller is not a valid creature or no spell is being attempted.


Remarks

Set by attempting to attack somebody with ActionCastSpell functions and talent variants. It is used in AI scripts such as OnPerception or OnDamaged to determine if the AI is currently validly attacking something (so no need to call AI to do a combat decision against the aggressor).

Combine it with GetAttemptedAttackTarget to cover most combat actions. The default AI is usually based around causing ActionAttack or ActionCastSpell so it works well for it. Custom AI might need to take into account other actions or acknowledgement it is already in combat.

If you want to check what target another creature is casting against, well you're out of luck unless you use ExecuteScript to gather this value from them. You can still find out if they're casting a spell with GetCurrentAction.

Note it is better to use this compared to GetIsInCombat since the combat state usually is already TRUE before the events even fire.


Version

1.22

See Also

functions: 

ActionCastSpellAtObject GetAttackTarget GetAttemptedAttackTarget



 author: Jody Fletcher