Likes: 0
Results 1 to 4 of 4
Thread: [C++] Scripting an Npc/Boss.
-
11-03-10, 02:24 PM #1
[C++] Scripting an Npc/Boss.
Register to remove this adAs to start of, this is the first Tutorial released from AuxProductions, mind that I rather do not retain flaming.
This guide will contain how to script simple NPC's. (A SIMPLE guide so.)
Let's begin,
As some of you might already know,Code://
Code:/*
Code://AuxProductions first guide.
Code:/*Auxproductions first guide made by Auxilium.*/
Now, let's start the actual script.
We'll instantly use what I've just tought you guys, so.
Code:/* My first script. Credits to : Myself. */
Start Code.
Code:#include "StdAfx.h" #include "Setup.h" #include "Base.h"
Lines beginning with a hash sign (#) are directives for the preprocessor. They are not regular code lines with expressions but indications for the compiler's preprocessor.
The red hashes should always be included !
Defining spells & the Npc's id.
As the title says, now we'll be doing basicly the same as the Local = lua function. You'll be defining the spells that the NPC will be able to cast/wont be able to cast. Imo for the ID (Meaning that the NPC his ID will be defined here.)
It's fairly easy, just watch :
Defining the NPC id.
Code://My First Boss. #Define Auxilium 123
- The 'Auxilium' will have to be replaced by the name of your own boss.
- The 123 is the ID of the npc.
Defining the spells that the NPC will be using.
Code://Auxilium's Spells. #Define Spellname Spellid.
- The 'Spellname' stands for the actual spellname, for example Death Touch.
- The Spellid stands for the ID of the spell that the NPC will be casting. (Can be found on wowhead; thotbott, ..)
Your script should now look like this :
Code:/***************************************** *All Credits go to Auxlium * * * * * *Name Of Boss : X * ******************************************/ #include "StdAfx.h" #include "Setup.h" #include "Base.h" // X ID #define Auxilium ID // Auxilium Spells #define SPELL SPELLID
When you have defined your spells, you can insert :
Code:class AuxiliumAI : public ArcScriptBossAI { ARCSCRIPT_FACTORY_FUNCTION(AuxiliumAI, ArcScriptBossAI); AuxiliumAI(Creature* pCreature) : ArcScriptBossAI(pCreature) {
As you see, the 'Auxilium' = Name of the boss you recently defined, is inserted here in a AI form. You can just replace 'Auxilium' by the name of your boss.
As soon as you reached this point, you can start adding spells underneath the codeline you have just inserted, for example :
Adding spells.
Code:class ZZZZZAI : public ArcScriptBossAI { ARCSCRIPT_FACTORY_FUNCTION(ZZZZZZAI, ArcScriptBossAI); ZZZZZZAI(Creature* pCreature) : ArcScriptBossAI(pCreature) { AddSpell(Lolwoot, Target_Self, 35, 0, 10); } }
Your current script should look like this now :
Code:/***************************************** *All Credits go to Auxlium * * * * * *Name Of Boss : X * ******************************************/ #include "StdAfx.h" #include "Setup.h" #include "Base.h" // X ID #define Auxilium ID // Auxilium Spells #define SPELL SPELLID class ZZZZZAI : public ArcScriptBossAI { ARCSCRIPT_FACTORY_FUNCTION(ZZZZZZAI, ArcScriptBossAI); ZZZZZZAI(Creature* pCreature) : ArcScriptBossAI(pCreature) { AddSpell(Lolwoot, Target_Self, 35, 0, 15); AddSpell(Rofl, Target_RandomPlayer, 45, 2, 10);
The
35 & 45 define the amount of chance it has to hit/proc.
0 & 2 define the Casttime. In seconds.
10 & 15 will define the interval. Meaning that it'll cast spell X each 10 & 15 seconds.
Adding Emotes.
Same as when you're adding spells, you'll be using the Add.. function.
Example :
Code:AddEmote(Event_OnCombatStart, "Auxilium's guide.", Text_Yell, 0);
The orange part defines when he says it. (This can be variable from OnCombatStart / OnDied / OnTargetDied / OnLeaveCombat)
& The '0' at the end, is reffering to the SoundID that it'll play when your npc announced the emote.
Phases.
Code:void AIUpdate() { if(GetHealthPercent()<=90) //TestPhase { AddSpell(X) }
You can add phases on similar ways as with this one,
for example :
Code:void AIUpdate() { if(GetHealthPercent()<=90) //TestPhase { AddSpell(X) if(GetHealthPercent()<=80) //TestPhase2 { AddSpell(Y)
Code:ParentClass::AIUpdate(); ParentClass::AIUpdate(); } };
Example :
Code:void AIUpdate() { if(GetHealthPercent()<=90) //TestPhase { AddSpell(X) } ParentClass::AIUpdate(); ParentClass::AIUpdate(); } };
Code:void SetupAuxilium(ScriptMgr* pScriptMgr) { pScriptMgr->register_creature_script(Auxilium, &AuxiliumAI::Create); }
I hope that you enjoyed my guide, if you have any questions please post them here and I'll reply onto them as soon as possible.
› See More: [C++] Scripting an Npc/Boss.
-
12-03-10, 07:17 AM #2
Thanks for the guide, will be sure to test it shortly.
-
01-08-11, 02:20 AM #3
Nice guide and is really easy for begginers to become Devs
The problem is, I have a trinitycore server, fresh installed is not a repack, only question is where i will put my script to test it in game ?Last edited by moteofsun; 01-08-11 at 02:37 AM.
-
26-06-12, 06:10 PM #4
Register to remove this adthere no need to add double call methods, i mean for example
Code:ParentClass::AIUpdate(); ParentClass::AIUpdate();