Boss Script
In this tutorial, I will teach you one of the ways to make a Boss Script using C++ & SQL for TrinityCore.
I will talk about the following points:
1. Casting Spells
2. Spawning Creatures
3. Phases
4. Talking and Emoting
Template for a Boss Script
This is how a basic template for a boss script would look.
Spells - Part 1
I will show you how to make the creature cast spells, but first you will need to define the spells in the “enum Spells” showed in the basic Boss Template.
You will be giving each spell a name, so we can use that later in the code instead of the numbers. This will make it easier for us to keep track of the spells. In this example, we are using the spells Lightning Bolt, Healing Wave and Flame Shock.
“SPELL_” is not needed, but it is used to keep track of the spells easier.
Now we need to define some events that we will use later in the script. In addition to “enum Spells” I have created one called “enum Events” which is shown in the Boss Template.
We are using a switch later in the script and it will switch between numbers, but to keep track of it better, we will also give the numbers a name, similar to what we did with the spell ids.
Again, “EVENT_” is not needed, but it makes it easier to keep track of them. The numbers should just start from 1 and count up for each event you add like shown.
We can now move on with the script.
Now go to “void EnterCombat” in the Boss Template.
We will now create a timed event for each of our spells.
This will execute our event after the defined time has passed. 8000 is how many milliseconds it will take before the event will be executed. 1000 milliseconds are equal to 1 second.
We will now go down to our switch shown in the Boss Template.
I will now add the three cases for my events.
Right now, the events will not do anything when they are executed, so we will have to add that too.
It will now cast spells in the different cases and repeat the event after the set time.
In the EVENT_LIGHTNINGBOLT
In the EVENT_HEALINGWAVE
In the EVENT_FLAMESHOCK
To target different groups of random players you will have to change the red number shown above in “EVENT_FLAMESHOCK”.
List of the different groups.
The Complete Boss Script Part 1
In this tutorial, I will teach you one of the ways to make a Boss Script using C++ & SQL for TrinityCore.
I will talk about the following points:
1. Casting Spells
2. Spawning Creatures
3. Phases
4. Talking and Emoting
Template for a Boss Script
This is how a basic template for a boss script would look.
Code:
#include "ScriptPCH.h"
enum Spells
{
};
enum Events
{
};
class example : public CreatureScript
{
public:
example() : CreatureScript("example") { }
struct exampleAI : public BossAI
{
exampleAI(Creature* creature) : BossAI(creature, 0)
{
}
void Reset() OVERRIDE
{
_Reset();
}
void EnterCombat(Unit* /*who*/) OVERRIDE
{
}
void KilledUnit(Unit * /*victim*/) OVERRIDE
{
}
void JustDied(Unit * /*victim*/) OVERRIDE
{
}
void UpdateAI(uint32 diff) OVERRIDE
{
if (!UpdateVictim())
return;
events.Update(diff);
if (me->HasUnitState(UNIT_STATE_CASTING))
return;
while (uint32 eventId = events.ExecuteEvent())
{
switch (eventId)
{
default:
break;
}
}
DoMeleeAttackIfReady();
}
};
CreatureAI* GetAI(Creature* creature) const OVERRIDE
{
return new exampleAI(creature);
}
};
void AddSC_example()
{
new example();
}
Spells - Part 1
I will show you how to make the creature cast spells, but first you will need to define the spells in the “enum Spells” showed in the basic Boss Template.
Code:
enum Spells
{
};
Code:
enum Spells
{
SPELL_LIGHTNINGBOLT = 403,
SPELL_HEALINGWAVE = 331,
SPELL_FLAMESHOCK = 8050,
};
Now we need to define some events that we will use later in the script. In addition to “enum Spells” I have created one called “enum Events” which is shown in the Boss Template.
Code:
enum Events
{
};
Code:
enum Events
{
EVENT_LIGHTNINGBOLT = 1,
EVENT_HEALINGWAVE = 2,
EVENT_FLAMESHOCK = 3,
};
We can now move on with the script.
Now go to “void EnterCombat” in the Boss Template.
Code:
void EnterCombat(Unit* /*who*/) OVERRIDE
{
}
Code:
void EnterCombat(Unit* /*who*/) OVERRIDE
{
events.ScheduleEvent(EVENT_LIGHTNINGBOLT, 8000);
events.ScheduleEvent(EVENT_HEALINGWAVE, 12000);
events.ScheduleEvent(EVENT_FLAMESHOCK , 10000);
}
We will now go down to our switch shown in the Boss Template.
Code:
while (uint32 eventId = events.ExecuteEvent())
{
switch (eventId)
{
default:
break;
}
}
Code:
while (uint32 eventId = events.ExecuteEvent())
{
switch (eventId)
{
case EVENT_LIGHTNINGBOLT:
break;
case EVENT_HEALINGWAVE:
break;
case EVENT_FLAMESHOCK:
break;
default:
break;
}
}
Code:
while (uint32 eventId = events.ExecuteEvent())
{
switch (eventId)
{
case EVENT_LIGHTNINGBOLT:
DoCastVictim(SPELL_LIGHTNINGBOLT);
events.ScheduleEvent(EVENT_LIGHTNINGBOLT, 8000);
break;
case EVENT_HEALINGWAVE:
DoCast(me, SPELL_HEALINGWAVE);
events.ScheduleEvent(EVENT_HEALINGWAVE, 12000);
break;
case EVENT_FLAMESHOCK:
if (Unit *target = SelectTarget(SELECT_TARGET_RANDOM, 0))
DoCast(target, SPELL_FLAMESHOCK);
events.ScheduleEvent(EVENT_FLAMESHOCK, 10000);
break;
default:
break;
}
}
In the EVENT_LIGHTNINGBOLT
Code:
DoCastVictim(SPELL_LIGHTNINGBOLT); //Will cast the spell on the victim (main tank.)
events.ScheduleEvent(EVENT_LIGHTNINGBOLT, 8000); //Will execute the event again after 8000 milliseconds (8 seconds.)
Code:
DoCast(me, SPELL_HEALINGWAVE); //Will cast the spell on itself.
events.ScheduleEvent(EVENT_HEALINGWAVE, 12000); //Will execute the event again after 12000 milliseconds (12 seconds.)
Code:
if (Unit *target = SelectTarget(SELECT_TARGET_RANDOM, [COLOR="#FF0000"]0[/COLOR]))
DoCast(target, SPELL_FLAMESHOCK);
events.ScheduleEvent(EVENT_FLAMESHOCK , 10000);
List of the different groups.
Code:
(SELECT_TARGET_RANDOM, 0) //Any random target.
(SELECT_TARGET_RANDOM, 1) //Random target in Short Range.
(SELECT_TARGET_RANDOM, 2) //Random target in Mid Range.
(SELECT_TARGET_RANDOM, 3) //Random target in Long Range.
(SELECT_TARGET_RANDOM, 4) //Random target with Mana.
(SELECT_TARGET_RANDOM, 5) //Random target with Rage.
(SELECT_TARGET_RANDOM, 6) //Random target with Energy.
The Complete Boss Script Part 1
Code:
#include "ScriptPCH.h"
enum Spells
{
SPELL_LIGHTNINGBOLT = 403,
SPELL_HEALINGWAVE = 331,
SPELL_FLAMESHOCK = 8050,
};
enum Events
{
EVENT_LIGHTNINGBOLT = 1,
EVENT_HEALINGWAVE = 2,
EVENT_FLAMESHOCK = 3,
};
class example : public CreatureScript
{
public:
example() : CreatureScript("example") { }
struct exampleAI : public BossAI
{
exampleAI(Creature* creature) : BossAI(creature, 0)
{
}
void Reset() OVERRIDE
{
_Reset();
}
void EnterCombat(Unit* /*who*/) OVERRIDE
{
events.ScheduleEvent(EVENT_LIGHTNINGBOLT, 8000);
events.ScheduleEvent(EVENT_HEALINGWAVE, 12000);
events.ScheduleEvent(EVENT_FLAMESHOCK , 10000);
}
void KilledUnit(Unit * /*victim*/) OVERRIDE
{
}
void JustDied(Unit * /*victim*/) OVERRIDE
{
}
void UpdateAI(uint32 diff) OVERRIDE
{
if (!UpdateVictim())
return;
events.Update(diff);
if (me->HasUnitState(UNIT_STATE_CASTING))
return;
while (uint32 eventId = events.ExecuteEvent())
{
switch (eventId)
{
case EVENT_LIGHTNINGBOLT:
DoCastVictim(SPELL_LIGHTNINGBOLT);
events.ScheduleEvent(EVENT_LIGHTNINGBOLT , 8000);
break;
case EVENT_HEALINGWAVE:
DoCast(me, SPELL_HEALINGWAVE);
events.ScheduleEvent(EVENT_HEALINGWAVE , 12000);
break;
case EVENT_FLAMESHOCK:
if (Unit *target = SelectTarget(SELECT_TARGET_RANDOM, 0))
DoCast(target, SPELL_FLAMESHOCK);
events.ScheduleEvent(EVENT_FLAMESHOCK , 10000);
break;
default:
break;
}
}
DoMeleeAttackIfReady();
}
};
CreatureAI* GetAI(Creature* creature) const OVERRIDE
{
return new exampleAI(creature);
}
};
void AddSC_example()
{
new example();
}