OnCombatRoundEnd
The script attached to this event fires at the end of each "combat round", so you can queue up a new action (Especially a casting spell action) so it gets the full benefit of a round of attempting that action.
Trigger
This seems to be queued from two separate things:
- If a "combat round" period ends, every 6 seconds, it will fire another one of these. This is if the creature is considered in combat with GetIsInCombat. By default a creature with no scripts won't automatically fire this, it needs to respond to another event, such as OnPerception, with a combat action.
- If a spell is cast it will queue another Combat Round End to fire, meaning hasted creatures casting 2 spells per round fire this event twice (or similarly if a quickened spell spell is cast)
It is also fired if the end of a effect that stops the AI doing anything occurs (eg; being stunned, knocked down etc.).
Notes
Just prior to the combat round script firing the combat modes set by SetActionMode such as Power Attack, Parry, Counter Spell, Expertise, Defensive Stance etc. are cleared. This has ramifications on Defensive Stance usage since each time it is enabled it uses a feat usage, see SetActionMode for workarounds.
In addition two useful functions that have their values cleared each time OnCombatRoundEnd is fired are GetAttemptedAttackTarget and GetAttemptedSpellTarget which are used in the default AI to determine if they've got a combat action already in progress (thus not needing to call DetermineCombatRound in, say, the OnDamaged event).
Combat can be cancelled on a creature by ClearAllActions(TRUE) or with SurrenderToEnemies. It also can be cancelled if the creature stops performing actions that would consider it in combat. It's a little strange sometimes and there isn't a good hard or fast rule for when it is called or when it decides to stop calling it.
The best idea is to assume each combat round needs a new action adding to the action queue, and call ClearAllActions() before it. This is the safest and most predictable way to do combat actions.
Function(s)
DetermineCombatRound(object, int) for standard combat round actions, as long as NW_I0_GENERIC is included.
No other functions are script-specific, there are a multitude of information gathering and action functions to use to make the AI attack in combat.
Remarks
The usage of this script is much better than the OnHeartbeat or trying to use DelayCommand since it is timed in a way to say "If you try and cast a spell immediately it will queue properly". If you try to do it with the Heartbeat it might not be synced up to the creatures timing for spell usage and they'll stand around uselessly for a while.
If the AI does not respond with an action they might "time out" the combat rounds firing, meaning the AI stops firing this script. If you are going to perform some non-combat action (such as a valiant speech when still in range of enemies, or some kind of non-combat action like running away like Sir Robin) you might want to make it play out in the OnHeartbeat event to make sure it works and when it's done trigger combat by attacking again.
See Also
| functions: |