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,gives the start of a so called 'comment'. Imo withCode://
the only diffrence is the // only comments that line, whilst /* comments everything between the second /*. I'll show you.Code:/*
Code://AuxProductions first guide.
I've explained you the use of 'Comment Brackets' because it might come in handy when you're scripting an NPC or any other kind of boss.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.
Now, you've made the 'intro' and you've given yourself the credits which you want. Now we can start by scripting the actual boss.Code:/* My first script. Credits to : Myself. */
Start Code.
Should always be underneath your credits.Code:#include "StdAfx.h" #include "Setup.h" #include "Base.h"
^ Hope that explains what it the hashes do. This basicly includes the commands that you'll be using in the future to script the boss, which you're working on.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.
You can do this as many times as you want.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 :
The actual script.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 :
Underneath your spells / Npc id.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.
You can keep adding spell lines which you defined above like that as much as you want.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 :
Let me explain what the AddSpell function did.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 :
Again,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.
Is the way on how to define correct phases.Code:void AIUpdate() { if(GetHealthPercent()<=90) //TestPhase { AddSpell(X) }
You can add phases on similar ways as with this one,
for example :
When you're done with adding phases, you can just add aCode:void AIUpdate() { if(GetHealthPercent()<=90) //TestPhase { AddSpell(X) if(GetHealthPercent()<=80) //TestPhase2 { AddSpell(Y)
To the end of the phase part.Code:ParentClass::AIUpdate(); ParentClass::AIUpdate(); } };
Example :
Now, you've learned on how to add phases, emotes & spells. You're almost done with your script now, just end the script by using :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.
-
12-03-10, 07:17 AM #2
Thanks for the guide, will be sure to test it shortly.
-
01-08-11, 02:20 AM #3Beginner

- Join Date
- Jul 2011
- Posts
- 1
- Rep Power
- 15
- Reputation
- 1
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 #4Beginner

- Join Date
- Apr 2009
- Posts
- 1
- Rep Power
- 17
- Reputation
- 1
Register to remove this adthere no need to add double call methods, i mean for example
need to put only oneCode:ParentClass::AIUpdate(); ParentClass::AIUpdate();



Cocain



Reply With Quote







