Back

### On Combat Round End Explanation

This script is fired automatically, such as the heartbeat, every 6 or 3 seconds (dependent upon haste). It causes the creature to pick a target, and attack it with spells, heal itself, heal allies and so on. If there is no valid targets (IE all dead or similar) at the end of combat, they will heal themselves to full health (if they have appropriate healing, and will not waste healing).

A word of warning is that this calls ClearAllActions before all actions. Note: There is also UDE_FLAG_COMBAT_ACTION_EVENT, and its pre-UDE version, which is a good way to makes sure some overriding action is taken rather then depending upon this script, which may not always fire when you want it to.

Also note that you could use a custom AI file, which will be fired as normal instead of the default AI file, which you can perform your own AI files. This is good to keep things running fast - boring sets of creatures can use some simple scripts and reduce CPU useage.

All Action's and ClearAllActions are probably the most useful. These are more AI ones:

- GetLastHostileActor() - Last person who cast a hostile spell, or attacked.
- GetLastKiller() - Get ours (or someone elses) last killer.
  (Helpful hint, if they are doing either of the below actions, the targets are valid. Use to stop re-initiating combat for creatures).
- GetAttemptedAttackTarget() - If we are attacking a target, and have not done so for more then 1 round, then this retuns the target. This, and the spell version, are cleared each round.
- GetAttemptedSpellTarget() - If we are casting a spell, this returns the target object.
- GetAttackTarget() - Returns who we are currently aiming for (spell or melee).
- GetLastAttacker() - Who last attacked us in melee.
- GetLastDamager() - Damaged us by a spell or HTH or trap etc.
- GetCurrentAction() - Good way to check for skill uses, or spell casting etc.
Script:

    /************************ [On Combat Round End] ********************************
        Filename: nw_c2_default3 or j_ai_oncombatrou
    ************************* [On Combat Round End] ********************************
        This is run every 3 or 6 seconds, if the creature is in combat. It is
        executed only in combat automatically.

        It runs what the AI should do, bascially.
    ************************* [History] ********************************************
        1.3 - Executes same script as the other parts of the AI to cuase a new action
    ************************* [Workings] *******************************************
        Calls the combat AI file using the J_INC_OTHER_AI include function,
        DetermineCombatRound.
    ************************* [Arguments] ******************************************
        Arguments: GetAttackTarget, GetLastHostileActor, GetAttemptedAttackTarget,
                   GetAttemptedSpellTarget (Or these are useful at least!)
    ************************* [On Combat Round End] *******************************/

    #include "j_inc_other_ai"

    void main()
    {
        // Pre-combat-round-event
        if(FireUserEvent(AI_FLAG_UDE_END_COMBAT_ROUND_PRE_EVENT, EVENT_END_COMBAT_ROUND_PRE_EVENT))
            // We may exit if it fires
            if(ExitFromUDE(EVENT_END_COMBAT_ROUND_PRE_EVENT)) return;

        // AI status check. Is the AI on?
        if(GetAIOff()) return;

        // It is our normal call (every 3 or 6 seconds, when we can change actions)
        // so no need to delete, and we fire the UDE's.

        // Determine combat round against an invalid target (as default)
        DetermineCombatRound();

        // Fire End of end combat round event
        FireUserEvent(AI_FLAG_UDE_END_COMBAT_ROUND_EVENT, EVENT_END_COMBAT_ROUND_EVENT);
    }