Creature ai scripts SF

From Project Skyfire
Jump to navigation Jump to search

Back to world database list of tables.

The `creature_ai_scripts` table

A full description is in the How to EventAI guide.


Field Type Attributes Key Null Default Extra Comment
id int(11) unsigned PRI NO NULL Auto Increment Identifier
creature_id int(11) unsigned NO 0 Creature Template
event_type tinyint(5) unsigned NO 0 Event Type
event_inverse_phase_mask int(11) signed NO 0 Mask which phases
event_chance int(3) unsigned NO 100
event_flags int(3) unsigned NO 0
event_param1 int(11) signed NO 0
event_param2 int(11) signed NO 0
event_param3 int(11) signed NO 0
event_param4 int(11) signed NO 0
action1_type tinyint(5) unsigned NO 0 Action Type
action1_param1 int(11) signed NO 0
action1_param2 int(11) signed NO 0
action1_param3 int(11) signed NO 0
action2_type tinyint(5) unsigned NO 0 Action Type
action2_param1 int(11) signed NO 0
action2_param2 int(11) signed NO 0
action2_param3 int(11) signed NO 0
action3_type tinyint(5) unsigned NO 0 Action Type
action3_param1 int(11) signed NO 0
action3_param2 int(11) signed NO 0
action3_param3 int(11) signed NO 0
comment varchar(255) signed NO NULL Event Comment

Description of the fields


creature_id * 100 Example: creature_id = 28600 -> id = 2860000


entry of the creature.


A list of event types EventAI is able to handle. Each event type has its own specific interpretation of the params that accompany it. Params are always read in the ascending order (from Param1 to Param3). 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.

Value Coment


Mask with phases this event should NOT trigger in*

Working with Phases

Working with phases requires a certain amount of math. You will have to know a few things before we begin.

  1. You should have an idea of how many phases the NPC will have.
  2. You will have to know Binary Addition. Don't worry, I'll show you how to do it.

- Binary Addition -

  • 0110 = 6 (base 10)
  • 0111 = 7 (base 10)
  • ____ = __
  • 1101 = 13 (base 10)

  • 07 06 05 04 03 02 01 00 <-- The place values.
  • 64 32 16 08 04 02 01 00 <-- Note how it doubles in size. This is what you add.


  • _1 __ 1 __ 1
  • 04 + 02 + 01 = 07.


  • _1 __ 0 __ 1 __ 1 __ 0 <-- Note how place 1, 2, and 4 are 1, but place 3 is not.
  • 08 + 04 + 02 + 01 + 00 = 11.

So you add 1, 2, and 8 together to get 11. You do not add the 4, because its bit was a 0.

__ __ __

Now back to Phases.

The overall concept (not method, just yet!) of a phase, is a "section" of activities that the NPC will act on. Hypothetically speaking, if a boss uses Attack "X" only when above 50% health, and only uses attack "Y" only when below 50% health, the boss will be using two different phases.

The concept: The "event_inverse_phase_mask" field is the field controlling phase information. Read the following sentence very carefully and memorize it. The number in this field represents the phases that this action will not be initiated in, including up to and less than the NPC's total number of phases. Keep this in the back of your head. The reason for this is because this number also casually tells the script how many phases the NPC has. It's surprisingly ingenious.

This is where the Binary Addition comes into play. Suppose your NPC has three phases. It will start off in phase 1. (*) It will remain in phase 1 unless specifically told to by Action Types 22, 23, 30, and 31, which control phases mid-game once the script is already running.

* (I should mention right here that anything with an event_inverse_phase_mask of 0 will happen in all phases.)

Suppose we wanted to have an attack that is only used in the NPC's first phase. You know that the NPC will have three phases. You would set up the attack as usual, but in the event_inverse_phase_mask field, you would put a 6. Why the six? Let's take a look.

We have three phases. We will represent these like this:

  • _3__2__1__<-- Represents the Phase Number and the bit.
  • 04 02 01

Phase 1's bit is 1. Phase 2's bit is 2. Phase 3's bit is 4. (If we had a phase 4, it would be 8, and phase 5 would be 16, etc.) To get 6, we have added the 2 and the 4 from the 2nd and 3rd phases. As was mentioned above, the number that goes into that field represents the bitmask of the phases that the action will not take place in.

Quick Phase Reference

This list is for an easy reference of what phase equates to what number, if you're not very phase-savvy. The "Value" column is what goes into the "event_inverse_phase_mask" field. The "Phase" column indicates the phase number that the hypothetical mob or boss is in that the event WILL happen in. This field relies on the next field, the "Max Phases" field. That is the amount of total phases the mob has. (I.e. my boss has 2 phases, or my boss has 4 phases.) Then there is a description field for any numerical work involved. It is the least important field, and can safely be ignored.

Remember, anything with "0" as a phase will occur in all phases. It is 0 by default.

Again, this is based on the following number patterns:

00 + 01 + 02 + 03 + 04 + 05 + 06 + 07 + 008 - Represents Phases.

00 + 01 + 02 + 04 + 08 + 16 + 32 + 64 + 128 - The numerical representations of those phases.

And, once again, how this works, is:

  1. You look at the total number of phases. Suppose it's 3.
  2. You cover up all the numbers to the right of phase 3, which corresponds to the 04 right below it.
  3. Then you decide which phase you want the event to occur in.
  4. Then you look at all other phases, and add up the number beneath them.
  5. The number you come up with goes in the "Value" field below in that chart, and what will go into the event_inverse_phase_mask field.


Chance to done this event, it's shuld be bettwen 1-100.


Bit / Value Name Description
0 / 1 EFLAG_REPEATABLE Event repeats (Does not repeat if this flag is not set)
1/2 EFLAG_NORMAL Event only occurs in Normal instance difficulty
2/4 EFLAG_HEROIC Event only occurs in Heroic instance difficulty
7/128 EFLAG_DEBUG_ONLY Not yet impletmented!


This field has no description. You can help wiki by clicking here to describe this field, if you have permissions.


This field has no description. You can help wiki by clicking here to describe this field, if you have permissions.


This field has no description. You can help wiki by clicking here to describe this field, if you have permissions.


This field has no description. You can help wiki by clicking here to describe this field, if you have permissions.


A list of action types that EventAI can handle. Each event type has its own specific interpretation of it's params, like every event type.

# Internal name action*_param1 action*_param2 action*_param3 Description
0 ACTION_T_NONE No Action Does nothing.
1 ACTION_T_TEXT -TextId1 -TextId2 -TextId3 Simply displays the specified -TextId. When -TextId2 and -TextId3 are specified, the selection will be randomized. Text types are defined, along with other options for the text, in a table below. All values needs to be negative.
2 ACTION_T_SET_FACTION FactionId Changes faction for a creature. When param1 is zero, creature will revert to it's default faction.
3 ACTION_T_MORPH_TO_ENTRY_OR_MODEL CreatureEntry ModelId Set either model from creature_template.entry (Param1) OR explicit modelId (Param2). If (Param1) AND (Param2) are both 0, demorph and revert to the default model.
4 ACTION_T_SOUND SoundId Plays a sound
5 ACTION_T_EMOTE moteId Does an emote
9 ACTION_T_RANDOM_SOUND SoundId1 SoundId2 SoundId3 Plays a random sound *
10 ACTION_T_RANDOM_EMOTE EmoteId1 EmoteId2 EmoteId3 Emotes a random emote
11 ACTION_T_CAST SpellId Target CastFlags Casts spell (Param1) on a target (Param2) using cast flags (specified below).
12 ACTION_T_SUMMON CreatureID Target Duration Summons a creature (Param1) for (Param3) duration and orders it to attach (Param2) target. Spawns on top of current creature.
13 ACTION_T_THREAT_SINGLE_PCT Threat% Target Modifies a threat by (Param1) percent on a target (Param2).
14 ACTION_T_THREAT_ALL_PCT Threat% Modifies a threat by (Param1) on all targets in the threat list (using -100% here will result in full aggro dump).
15 ACTION_T_QUEST_EVENT QuestID, Target Calls AreaExploredOrEventHappens with (Param1) for a target in (Param2).
16 ACTION_T_QUEST_CASTCREATUREGO CreatureID SpellId Target Sends CastCreatureOrGo for a creature specified by CreatureId (Param1) with provided spell id (Param2) for a target in (Param3).
17 ACTION_T_SET_UNIT_FIELD Field_Number Value Target Sets a unit field (Param1) to provided value (Param2) on a target in (Param3).
18 ACTION_T_SET_UNIT_FLAG Flags Target Sets flag (flags can be used together to modify multiple flags at once) on a target (Param2).
19 ACTION_T_REMOVE_UNIT_FLAG Flags Target Removes flag on a target (Param2).
20 ACTION_T_AUTO_ATTACK AllowAutoAttack Stop melee attack when (Param1) is zero, otherwise continue attacking / allow melee attack.
21 ACTION_T_COMBAT_MOVEMENT AllowCombatMovement Stop combat based movement when (Param1) is zero, otherwise continue/allow combat based movement (targeted movement generator).
22 ACTION_T_SET_PHASE Phase Sets the current phase to (Param1).
23 ACTION_T_INC_PHASE Value Increments the phase by (Param1). May be negative to decrement, but should not be zero.
24 ACTION_T_EVADE No Params Forces the creature to evade, wiping all threat and dropping combat.
25 ACTION_T_FLEE_FOR_ASSIST No Params Causes the creature to flee for assistence (often at low health).
26 ACTION_T_QUEST_EVENT_ALL QuestId Calls GroupEventHappens with (Param1). Only used if it's _expected_ event should call quest completion for all players in a current party.
27 ACTION_T_CASTCREATUREGO_ALL QuestId SpellId Calls CastedCreatureOrGo for all players on the threat list with quest id specified in (Param1) and spell id in (Param2).
28 ACTION_T_REMOVEAURASFROMSPELL Target Spellid Removes all auras on a target (Param1) caused by a spell (Param2).
29 ACTION_T_RANGED_MOVEMENT Distance Angle Changes the movement generator to a ranged type. (note: default melee type can still be set by using 0 as angle and 0 as distance).
30 ACTION_T_RANDOM_PHASE PhaseId1 PhaseId2 PhaseId3 Sets a phase to a specified id(s)*
31 ACTION_T_RANDOM_PHASE_RANGE PhaseMin PhaseMax Sets a phase to a random id (Phase = PhaseMin + rnd % PhaseMin-PhaseMax). PhaseMax must be greater than PhaseMin.
32 ACTION_T_SUMMON CreatureID Target SummonID Summons a creature (Param1) to attack target (Param2) at location specified by EventAI_Summons (Param3).
33 ACTION_T_KILLED_MONSTER CreatureID Target Calls KilledMonster (Param1) for a target (Param2).
34 ACTION_T_SET_INST_DATA Field Data Calls ScriptedInstance::SetData with field (Param1) and data (Param2).
35 ACTION_T_SET_INST_DATA64 Field Target Calls ScriptedInstance::SetData64 with field (Param1) and target's GUID (Param2).
36 ACTION_T_UPDATE_TEMPLATE TemplateId Team Changes a creature's template to (Param1) with team = Alliance or Horde when (Param2) is either false or true respectively.
37 ACTION_T_DIE No Params Kills the creature
38 ACTION_T_ZONE_COMBAT_PULSE No Params Puts all players within an instance into combat with the creature. Only works when a creature is already in combat. Doesn't work outside instances.
39 ACTION_T_CALL_FOR_HELP Radius Call any friendly out-of-combat creatures in a radius (Param1) to attack current creature's target.
40 ACTION_T_SET_SHEATH Sheath Sets sheath state for a creature (0 = no weapon, 1 = melee weapon, 2 = ranged weapon).
41 ACTION_T_FORCE_DESPAWN No Params Despawns the creature
42 ACTION_T_SET_INVINCIBILITY_HP_LEVEL hp_level is_percent Set min. health level for creature that can be set at damage as flat value or percent from max health

Cast Flags

Bit / Value Name Description
0 / 1 CAST_INTURRUPT_PREVIOUS Interrupts any previous spell casting.
1 / 2 CAST_TRIGGERED Forces the cast to be instant and ignores any mana/reagents requirements.
2 / 4 CAST_FORCE_CAST Forces spell to cast even if the target is possibly out of range or the creature is possibly out of mana
3 / 8 CAST_NO_MELEE_IF_OOM Prevents creature from entering melee if out of mana or out of range
4 / 16 CAST_FORCE_TARGET_SELF Forces the target to cast this spell on itself
5 / 32 CAST_AURA_NOT_PRESENT Only casts the spell on the target if the target does not have the aura from that spell on itself already.
  • = Use -1 where the param is expected to do nothing. Random constant is generated for each event, so if you have a random yell and a random sound, they will be linked up with each other (ie. param2 with param2).


Depends on action_type


Depends on action_type


Depends on action_type


Comment as to what should this one script do.

  • Style should be something like this: 'Creature (or Gameobject) name - Cast Spellname'

Read some real scripts for more info.

Return to world database structure