“creature_ai_scripts” table

The creature_ai_scripts table holds a simple set of scripts for each creature template allowing creatures to perform extended actions beyond simple spell casts.

Table structure

Field Type Null Key Default Extra
id int(11) unsigned NO PRI NULL auto_increment
creature_id int(11) unsigned NO   0  
event_type tinyint(5) unsigned NO   0  
event_inverse_phase_mask int(11) NO   0  
event_chance int(3) unsigned NO   100  
event_flags int(3) unsigned NO   0  
event_param1 int(11) NO   0  
event_param2 int(11) NO   0  
event_param3 int(11) NO   0  
event_param4 int(11) NO   0  
action1_type tinyint(5) unsigned NO   0  
action1_param1 int(11) NO   0  
action1_param2 int(11) NO   0  
action1_param3 int(11) NO   0  
action2_type tinyint(5) unsigned NO   0  
action2_param1 int(11) NO   0  
action2_param2 int(11) NO   0  
action2_param3 int(11) NO   0  
action3_type tinyint(5) unsigned NO   0  
action3_param1 int(11) NO   0  
action3_param2 int(11) NO   0  
action3_param3 int(11) NO   0  
comment varchar(255) NO      

Fields

id

The unique identifier for the AI script entry. To ease development, it has been defined that the identifier always equals creature_template.entry * 100.

creature_id

This references the “creature_template” table tables unique ID for which the entry is valid.

event_type

The event type determines when to perform an action and also modifies which of the parameters are used and what they mean. The following table shows all available event types:

Value Type Parameters Description
0 EVENT_T_TIMER_IN_COMBAT InitialMin, InitialMax, RepeatMin, RepeatMax Expires at first between (Param1) and (Param2) and then will repeat between every (Param3) and (Param4), EXPIRES ONLY IN COMBAT.
1 EVENT_T_TIMER_OOC InitialMin, InitialMax, RepeatMin, RepeatMax Expires at first between (Param1) and (Param2) and then will repeat between every (Param3) and (Param4), EXPIRES ONLY OUT OF COMBAT BUT NOT DURING EVADE.
2 EVENT_T_HP HPMax%, HPMin%, RepeatMin, RepeatMax Expires when the NPC’s HP% is between (Param1) and (Param2). Will repeat between every (Param3) and (Param4) If Event Conditions Are Still Met.
3 EVENT_T_MANA ManaMax%,ManaMin% RepeatMin, RepeatMax Expires when the NPC’s Mana% is between (Param1) and (Param2). Will repeat between every (Param3) and (Param4) If Event Conditions Are Still Met.
4 EVENT_T_AGGRO NONE Expires ONLY upon the NPC’s INITIAL Aggro at the Start of Combat (Does NOT Repeat) and Only Resets on Spawn or Evade.
5 EVENT_T_KILL RepeatMin, RepeatMax Expires upon Killing a Player. Will Repeat Check between (Param1) and (Param2). This Event Will Not Trigger Again Until Repeat Timer Expires
6 EVENT_T_DEATH NONE Expires on the NPC’s Death. (This Triggers At The Moment The NPC Dies)
7 EVENT_T_EVADE NONE Expires at the moment the Creature EnterEvadeMode() and Exits Combat.
8 EVENT_T_SPELLHIT SpellID, School, RepeatMin, RepeatMax Expires upon Spell Hit of the NPC. When (param1) is set, it is the specific Spell ID used as the trigger. With (param2) specified, the expiration is limited to specific spell schools (-1 for all) and Spell ID value is ignored. Will repeat Event Conditions Check between every (Param3) and (Param4). Only A Spell ID or Spell School may be Specified but NOT both.
9 EVENT_T_RANGE MinDist, MaxDist, RepeatMin, RepeatMax Expires when the Highest Threat Target Distance is Greater than (Param1) and Less than (Param2). Will repeat between every (Param3) and (Param4) if Event Conditions Are Still Met.
10 EVENT_T_OOC_LOS NoHostile, MaxRnage, RepeatMin, RepeatMax Expires when a unit moves within distance (MaxAllowedRange) of the NPC. If (Param1) is 0 it will expire only when unit is hostile, If (Param1) is 1 it will expire only when unit is friendly. This depends generally on faction relations. Will repeat every (Param3) and (Param4). Does NOT expire when the NPC is in combat.
11 EVENT_T_SPAWNED Condition, CondValue1 Expires on initial spawn and respawn of the NPC (Useful for setting Ranged Movement/Summoning Pets/Applying Buffs).
12 EVENT_T_TARGET_HP HPMax%, HPMin%, RepeatMin, RepeatMax Expires when current target’s HP% is between (Param1) and (Param2). Will repeat every (Param3) and (Param4)If Event Conditions Are Still Met.
13 EVENT_T_TARGET_CASTING RepeatMin, RepeatMax Expires when the current target is casting a spell. Will repeat every (Param1) and (Param2) If Event Conditions Are Still Met.
14 EVENT_T_FRIENDLY_HP HPDeficit, Radius, RepeatMin, RepeatMax Expires when a friendly unit in (Radius) has at least (Param1) HP points missing. Will repeat every (Param3) and (Param4) If Event Conditions Are Still Met.
15 EVENT_T_FRIENDLY_IS_CC DispelType, Radius, RepeatMin, RepeatMax Expires when a friendly unit is crowd controlled within the given Radius (Param2). Will repeat every (Param3) and (Param4).
16 EVENT_T_FRIENDLY_MISSING_BUFF SpellId, Radius, RepeatMin, RepeatMax Expires when a friendly unit is missing aura(s) given by a spell (Param1) within Radius (Param2). Will repeat every (Param3) and (Param4) If Event Conditions Are Still Met.
17 EVENT_T_SUMMONED_UNIT CreatureId, RepeatMin, RepeatMax Expires after creature with entry = (Param1) is spawned (Param1 = 0 means all spawns). Will repeat every (Param2) and (Param3).
18 EVENT_T_TARGET_MANA ManaMax%, ManaMin%, RepeatMin, RepeatMax Expires when current target’s Mana% is between (Param1) and (Param2). Will repeat every (Param3) and (Param4) If Event Conditions Are Still Met.
19 EVENT_T_QUEST_ACCEPT QuestID  
20 EVENT_T_QUEST_COMPLETE    
21 EVENT_T_REACHED_HOME NONE Expires when a creature reaches it’s home (spawn) location after evade. This is commonly used for NPC’s who Stealth once reaching their Spawn Location
22 EVENT_T_RECEIVE_EMOTE EmoteId, Condition, CondValue1, CondValue2 Expires when a creature receives an emote with emote text id (“enum TextEmotes” from SharedDefines.h in Mangos Source) in (Param1). Conditions can be defined (Param2) with optional values (Param3,Param4), see (enum ConditionType) in ObjectMgr.h (Mangos Source).
23 EVENT_T_AURA Param1 = SpellID, Param2 = Number of time stacked, Param3/4 Repeat Min/Max Expires when a creature has spell (Param1) auras applied in a stack greater or equal to value provided in (Param2). Will repeat every (Param3) and (Param4) If Event Conditions Are Still Met.
24 EVENT_T_TARGET_AURA Param1 = SpellID, Param2 = Number of time stacked, Param3/4 Repeat Min/Max Expires when a target unit has spell (Param1) auras applied in a stack greater or equal to value provided in (Param2). Will repeat every (Param3) and (Param4) If Event Conditions Are Still Met.
25 EVENT_T_SUMMONED_JUST_DIED CreatureId, RepeatMin, RepeatMax Expires after creature with entry = (Param1) is die (Param1 = 0 means all spawns). Will repeat every (Param2) and (Param3).
26 EVENT_T_SUMMONED_JUST_DESPAWN CreatureId, RepeatMin, RepeatMax Expires before creature with entry = (Param1) is despawn (Param1 = 0 means all spawns). Will repeat every (Param2) and (Param3).
27 EVENT_T_MISSING_AURA Param1 = SpellID, Param2 = Number of time stacked expected, Param3/4 Repeat Min/Max Expires when a creature not has spell (Param1) auras applied in a stack greater or equal to value provided in (Param2). Will repeat every (Param3) and (Param4).
28 EVENT_T_TARGET_MISSING_AURA Param1 = SpellID, Param2 = Number of time stacked expected, Param3/4 Repeat Min/Max Expires when a target unit not has spell (Param1) auras applied in a stack greater or equal to value provided in (Param2). Will repeat every (Param3) and (Param4).
29 EVENT_T_TIMER_GENERIC InitialMin, InitialMax, RepeatMin, RepeatMax Expires at first between (Param1) and (Param2) and then will repeat between every (Param3) and (Param4).
30 EVENT_T_RECEIVE_AI_EVENT AIEventType, Sender-Entry, unused, unused Expires when the creature receives an AIEvent of type (Param1), sent by creature (Param2 != 0). If (Param2 = 0) then sent by any creature

Time parameters are measured in milliseconds.

Note

Events will not repeat until the creature exits combat or unless EFLAG_REPEATABLE is set. Some events such as EVENT_T_AGGRO, EVENT_T_DEATH, EVENT_T_SPAWNED and EVENT_T_EVADE cannot repeat.

event_inverse_phase_mask

TODO: Document me.

event_chance

The chance for this event to happen. Values have to be between 1 and 100.

event_flags

Event flags allow you to modify how events are executed.

Value Type Description
1 EFLAG_REPEATABLE Event repeats (Does not repeat if this flag is not set)
2 EFLAG_RESERVED_1 Unused
4 EFLAG_RESERVED_2 Unused
8 EFLAG_RESERVED_3 Unused
16 EFLAG_RESERVED_4 Unused
32 EFLAG_RANDOM_ACTION At event occur execute one random action from event actions instead all actions.
64 EFLAG_RESERVED_6 Unused
128 EFLAG_DEBUG_ONLY Event only occurs in debug builds

event_param1

Depends on event_type. See the list of event types above.

event_param2

Depends on event_type. See the list of event types above.

event_param3

Depends on event_type. See the list of event types above.

event_param4

Depends on event_type. See the list of event types above.

action1_type

The action type defines what kind of action should be taken and depending on the action taken, different parameters are requried to perform the action. The following table lists all available actions including their parameters.

Value Type Parameters
0 ACTION_T_NONE No action
1 ACTION_T_TEXT TextId1, optionally -TextId2, optionally -TextId3(if -TextId2 exist). If more than just -TextId1 is defined, randomize. Neg$
2 ACTION_T_SET_FACTION FactionId (or 0 for default)
3 ACTION_T_MORPH_TO_ENTRY_OR_MODEL Creature_template entry(param1) OR ModelId (param2) (or 0 for both to demorph)
4 ACTION_T_SOUND SoundId
5 ACTION_T_EMOTE EmoteId
6 ACTION_T_RANDOM_SAY UNUSED
7 ACTION_T_RANDOM_YELL UNUSED
8 ACTION_T_RANDOM_TEXTEMOTE UNUSED
9 ACTION_T_RANDOM_SOUND SoundId1, SoundId2, SoundId3 (-1 in any field means no output if randomed that field)
10 ACTION_T_RANDOM_EMOTE EmoteId1, EmoteId2, EmoteId3 (-1 in any field means no output if randomed that field)
11 ACTION_T_CAST SpellId, Target, CastFlags
12 ACTION_T_SUMMON CreatureID, Target, Duration in ms
13 ACTION_T_THREAT_SINGLE_PCT Threat%, Target
14 ACTION_T_THREAT_ALL_PCT Threat%
15 ACTION_T_QUEST_EVENT QuestID, Target
16 ACTION_T_CAST_EVENT QuestID, SpellId, Target - must be removed as hack?
17 ACTION_T_SET_UNIT_FIELD Field_Number, Value, Target
18 ACTION_T_SET_UNIT_FLAG Flags (may be more than one field OR’d together), Target
19 ACTION_T_REMOVE_UNIT_FLAG Flags (may be more than one field OR’d together), Target
20 ACTION_T_AUTO_ATTACK AllowAttackState (0 = stop attack, anything else means continue attacking)
21 ACTION_T_COMBAT_MOVEMENT AllowCombatMovement (0 = stop combat based movement, anything else continue attacking)
22 ACTION_T_SET_PHASE Phase
23 ACTION_T_INC_PHASE Value (may be negative to decrement phase, should not be 0)
24 ACTION_T_EVADE No Params
25 ACTION_T_FLEE_FOR_ASSIST No Params
26 ACTION_T_QUEST_EVENT_ALL QuestID
27 ACTION_T_CAST_EVENT_ALL CreatureId, SpellId
28 ACTION_T_REMOVEAURASFROMSPELL Target, Spellid
29 ACTION_T_RANGED_MOVEMENT Distance, Angle
30 ACTION_T_RANDOM_PHASE PhaseId1, PhaseId2, PhaseId3
31 ACTION_T_RANDOM_PHASE_RANGE PhaseMin, PhaseMax
32 ACTION_T_SUMMON_ID CreatureId, Target, SpawnId
33 ACTION_T_KILLED_MONSTER CreatureId, Target
34 ACTION_T_SET_INST_DATA Field, Data
35 ACTION_T_SET_INST_DATA64 Field, Target
36 ACTION_T_UPDATE_TEMPLATE Entry, Team
37 ACTION_T_DIE No Params
38 ACTION_T_ZONE_COMBAT_PULSE No Params
39 ACTION_T_CALL_FOR_HELP Radius
40 ACTION_T_SET_SHEATH Sheath (0-passive,1-melee,2-ranged)
41 ACTION_T_FORCE_DESPAWN Delay (0-instant despawn)
42 ACTION_T_SET_INVINCIBILITY_HP_LEVEL MinHpValue, format(0-flat,1-percent from max health)
43 ACTION_T_MOUNT_TO_ENTRY_OR_MODEL Creature_template entry(param1) OR ModelId (param2) (or 0 for both to unmount)
44 ACTION_T_CHANCED_TEXT Chance to display the text, TextId1, optionally TextId2. If more than just -TextId1 is defined, randomize. Negative values.
45 ACTION_T_THROW_AI_EVENT EventType, Radius, unused
46 ACTION_T_SET_THROW_MASK EventTypeMask, unused, unused
47 ACTION_T_SUMMON_UNIQUE CreatureID, Target, SummonID

action1_param1

See action1_type for a list of parameters required for a specific action.

action1_param2

See action1_type for a list of parameters required for a specific action.

action1_param3

See action1_type for a list of parameters required for a specific action.

action2_type

See action1_type for a list of available actions.

action2_param1

See action1_type for a list of parameters required for a specific action.

action2_param2

See action1_type for a list of parameters required for a specific action.

action2_param3

See action1_type for a list of parameters required for a specific action.

action3_type

See action1_type for a list of available actions.

action3_param1

See action1_type for a list of parameters required for a specific action.

action3_param2

See action1_type for a list of parameters required for a specific action.

action3_param3

See action1_type for a list of parameters required for a specific action.

comment

Documents what an event script is supposed to do. It has been defined that comments should use the form: ‘Creature/GameObject name - Cast Spellname’.