Likes: 0
Results 1 to 3 of 3
-
27-04-10, 01:13 AM #1
[ArcEmu][C++] Scripting a Creature
Register to remove this adHello everyone! Today I would like to teach you all how to script an NPC using C++ for the ArcEmu Emulator.
I don't see a super reasonable reason to add credits to the script unless its a fairly long script or you are releasing it. But for personal use, you can skip the credits. instead, we'll begin with the header files.
The header files contain the information you will be using. For example, the header file "base.h" includes a majority, if not all, of the methods you are soon to use.
Code:#include "StdAfx.h" #include "Setup.h" #include "../Common/Base.h"
Code:#include "StdAfx.h" #include "Setup.h" #include "../Common/Base.h" class FirstNPC : public MoonScriptBossAI { MOONSCRIPT_FACTORY_FUNCTION(FirstNPC, MoonScriptBossAI); FirstNPC(Creature* pCreature) : MoonScriptBossAI(pCreature) { } void AIUpdate() { ParentClass::AIUpdate(); } void Destroy() { delete this; } }; void SetupFirstNPC(ScriptMgr * mgr) { mgr->register_creature_script(npcid, FirstNPC::Create); }
The piece you see in the dark green is the method where it will register your script to the server.
The method in the Dark Orange will delete the variables and such, to avoid overflow.
The method name AIUpdate in Dark Red is what the AI will continually check to see if any changes to the AI need to be made.
Next Section!!!1!(Teehee)
Aight so, I'm guessing you want to make the boss/npc say something when a certain event happens.
So we're going to take this snippet...
Code:FirstNPC(Creature* pCreature) : MoonScriptBossAI(pCreature) { }
Code:MOONSCRIPT_FACTORY_FUNCTION(FirstNPC, MoonScriptBossAI); FirstNPC(Creature* pCreature) : MoonScriptBossAI(pCreature) { AddEmote(Event_OnCombatStart, "OMG SDYESS IS AMAZING AND IM IN COMBAT", Text_Yell); }
Next, in the Dark Orange we have what event is going to cause the emote to happen. You're probably wondering...what other events are there..well, here is a list!
Code:Event_OnCombatStart Event_OnTargetDied Event_OnDied Event_OnTaunt
Dark green is the text that the npc will say when the event occurs.
And lastly, the color...uhm turquoise? is whether the npc will say the text, yell the text, or emote(?).
Here's the list.
Code:Text_Say Text_Yell Text_Emote
Modify like below:
Code:AddEmote(Event_OnCombatStart, "OMG SDYESS IS AMAZING AND IM IN COMBAT", Text_Yell); CHANGE TO AddEmote(Event_OnCombatStart, "OMG SDYESS IS AMAZING AND IM IN COMBAT", Text_Yell, soundid);
Never gonna guess whats next are you...? Nah you probably did. Spells!
Well, lets take our method from before
Code:MOONSCRIPT_FACTORY_FUNCTION(FirstNPC, MoonScriptBossAI); FirstNPC(Creature* pCreature) : MoonScriptBossAI(pCreature) { AddEmote(Event_OnCombatStart, "OMG SDYESS IS AMAZING AND IM IN COMBAT"[/COLOR], Text_Yell); AddSpell(spellid, target, chance, casttime, cooldown); }
target, is who the spell will be cast on. Here is a llist of the target types.
Code:Target_Self Target_Current Target_SecondMostHated Target_Destination Target_Predefined Target_RandomPlayer Target_RandomPlayerNotCurrent Target_RandomPlayerDestination Target_RandomPlayerApplyAura Target_RandomUnit Target_RandomUnitNotCurrent Target_RandomDestination Target_RandomUnitApplyAura Target_RandomFriendly Target_WoundedPlayer Target_WoundedUnit Target_WoundedFriendly Target_ClosestPlayer Target_ClosestPlayerNotCurrent Target_ClosestUnit Target_ClosestUnitNotCurrent Target_ClosestFriendly Target_ClosestCorpse Target_RandomCorpse
casttime is how long it takes the creature to the cast the added spell
and the cooldown is the amount of time until it can be cast again.
so here's an example
Code:AddSpell(32659, Target_Current, 100, 0, 5);
Code:#define SPELL_LOLZ 32569 *SCROLL DOWN* AddSpell(SPELL_LOLZ, Target_current, 100, 0, 5);
So here is what you should have so far:
Code:#include "StdAfx.h" #include "Setup.h" #include "../Common/Base.h" class FirstNPC : public MoonScriptBossAI { MOONSCRIPT_FACTORY_FUNCTION(FirstNPC, MoonScriptBossAI); FirstNPC(Creature* pCreature) : MoonScriptBossAI(pCreature) { AddEmote(Event_OnCombatStart, "OMG SDYESS IS AMAZING AND IM IN COMBAT", Text_Yell); AddSpell(50000, Target_Current, 100, 0, 20); } void AIUpdate() { ParentClass::AIUpdate(); } void Destroy() { delete this; } }; void SetupFirstNPC(ScriptMgr * mgr) { mgr->register_creature_script(npcid, FirstNPC::Create); }
Alright, so now, we're going to go ahead and move onto AIUpdate and how it works.
Essentially, this is what allows the creature to change what it does. Its like when you register an event a Lua I guess.
Okay so lets start of with some health percent phases.
Code:void AIUpdate() { if(GetPhase() == 1) { if(_unit->GetHealthPct() <= 80 ) { Emote("Now feel my wrath!, Text_Yell); SetPhase(2); } } else if(GetPhase() == 2) { if(_unit->GetHealthPct() <= 45 ) { Emote("I require heals!, Text_Yell); SetPhase(3); } } else if(GetPhase() == 3) { if(_unit->GetHealthPct() <= 20 ) { Emote("OH NOES!", Text_Yell); } } ParentClass::AIUpdate(); }
So we're going to go back to on of the blocks from earlier.
Code:MOONSCRIPT_FACTORY_FUNCTION(FirstNPC, MoonScriptBossAI); FirstNPC(Creature* pCreature) : MoonScriptBossAI(pCreature) { AddEmote(Event_OnCombatStart, "OMG SDYESS IS AMAZING AND IM IN COMBAT", Text_Yell); AddSpell(50000, Target_Current, 100, 0, 20); AddPhaseSpell(2, AddSpell(5, Target_RandomPlayer, 100, 0, 30)); AddPhaseSpell(3, AddSpell(5, Target_Current, 100, 0, 28)); }
The number that is Dark orange is the phase that the spell is used in.
The part in Turquiose, is where the spell is added. Its like the AddSpell before, except added into this one
And here is your end result:
Code:#include "StdAfx.h" #include "Setup.h" #include "../Common/Base.h" class FirstNPC : public MoonScriptBossAI { MOONSCRIPT_FACTORY_FUNCTION(FirstNPC, MoonScriptBossAI); FirstNPC(Creature* pCreature) : MoonScriptBossAI(pCreature) { AddEmote(Event_OnCombatStart, "OMG SDYESS IS AMAZING AND IM IN COMBAT", Text_Yell); AddSpell(50000, Target_Current, 100, 0, 20); AddPhaseSpell(2, AddSpell(5, Target_RandomPlayer, 100, 0, 30)); AddPhaseSpell(3, AddSpell(5, Target_Current, 100, 0, 28)); } void AIUpdate() { if(GetPhase() == 1) { if(_unit->GetHealthPct() <= 80 ) { Emote("Now feel my wrath!, Text_Yell); SetPhase(2); } } else if(GetPhase() == 2) { if(_unit->GetHealthPct() <= 45 ) { Emote("I require heals!, Text_Yell); SetPhase(3); } } else if(GetPhase() == 3) { if(_unit->GetHealthPct() <= 20 ) { Emote("OH NOES!", Text_Yell); } } ParentClass::AIUpdate(); } void Destroy() { delete this; } }; void SetupFirstNPC(ScriptMgr * mgr) { mgr->register_creature_script(npcid, FirstNPC::Create); }
If theres something else you'd like to see added just reply
Posted in wrong section. Please move when you see it :P
› See More: [ArcEmu][C++] Scripting a CreatureLast edited by Sdyess94; 27-04-10 at 01:26 AM.
-
27-04-10, 11:44 AM #2
Thanks for this Sydess +Rep
No touching please.
-
02-05-10, 03:56 AM #3
Register to remove this adI'll read this when I'm sober.
But looks nice, remind me to rep you in a few days for this, need to spread it around :P
Related Threads - Scroll Down after related threads if you are only interested to view replies for above post/thread
Visitors found this page by searching for:
Nobody landed on this page from a search engine, yet!
SEO Blog