Advanced Mob
Inspiration
Do you ever sit there, making mobs and you want the same mob to have different spells than the other one, and you hate that you have to make a whole new Npc for it. Well, i felt that same way when writing an instance one time and i wrote this script
How to Use
This script is entirely basic, anything you need to know has a comment to the right of it, so its no challenge, this Npc is a mage, but in the future i may decide to make a melee fighter as well. I hope you enjoy this release, maybe learn from it and save yourself the wasted effort of 2 npcs' and 2 scripts. Enjoy
Code:/******************************************** **********Created By Mager******************* ********Advanced Mob Script****************** ********Created for MMowned****************** ********************************************/ #define CN_ADVANCEDMOB 100015 #define FIRECAST 38692///Choose a normal firespell #define FIREAOE 27086///Choose a AoE Firespell #define FROSTCAST 38697//Choose a normal frostspell #define FROSTAOE 27384//Choose a AoE frostspell #define SHADOWCAST 27209//Choose a normal Shadow Spell #define SHADOWAOE 30414// Choose a shadow AoE spell #define FIRESHIELD 30663//Choose a firebased mage-shield ex."Molten Armor" #define FROSTSHIELD 27124//Choose a frostbased mage-shield ex. "Ice Armor" #define SHADOWSHIELD 27260//Choose a shadowbased mage-shield ex. "Demon Skin" p.s. yes i know its warlock but you get the point #define FIRESUMMON 40133//Choose a fire pet to summon (shammy spells have fire elements) #define FROSTSUMMON 45067//Choose a frost pet to summon, "Summon Water Elemental" is good #define SHADOWSUMMON 34237//Choose a shadow pet to summon, usually a warlocks demon //Start talking to people about how awesome mager is and how much you know it XD class AdvancedMobAI : CreatureAIScript { public: ADD_CREATURE_FACTORY_FUNCTION(MafiaSpellWeaverAI); MafiaSpellWeaverAI(Creature* pCreature) : CreatureAIScript(pCreature) { m_fire = m_frost = m_shadow = false; m_cast = m_aoe = m_shield = m_summon = true; ChooseSpec(); } void ChooseSpec() { int RandType; RandType=rand()%3; switch (RandType) { case 0: m_fire = true; infocast = dbcSpell.LookupEntry(FIRECAST); infoaoe = dbcSpell.LookupEntry(FIREAOE); infoshield = dbcSpell.LookupEntry(FIRESHIELD); infosummon = dbcSpell.LookupEntry(FIRESUMMON); break; case 1: m_frost = true; infocast = dbcSpell.LookupEntry(FROSTCAST); infoaoe = dbcSpell.LookupEntry(FROSTAOE); infoshield = dbcSpell.LookupEntry(FROSTSHIELD); infosummon = dbcSpell.LookupEntry(FROSTSUMMON); break; case 2: m_shadow = true; infocast = dbcSpell.LookupEntry(SHADOWCAST); infoaoe = dbcSpell.LookupEntry(SHADOWAOE); infoshield = dbcSpell.LookupEntry(SHADOWSHIELD); infosummon = dbcSpell.LookupEntry(SHADOWSUMMON); break; } } void OnCombatStart(Unit* mTarget) { RegisterAIUpdateEvent(_unit->GetUInt32Value(UNIT_FIELD_BASEATTACKTIME)); _unit->CastSpell(_unit, infoshield, false); m_shield = false; int RandType; RandType=rand()%3; switch (RandType) { case 0: _unit->SendChatMessage(CHAT_MSG_MONSTER_YELL, LANG_UNIVERSAL, "Stop them they threaten our plans!!"); break; } } void OnCombatStop(Unit *mTarget) { _unit->GetAIInterface()->setCurrentAgent(AGENT_NULL); _unit->GetAIInterface()->SetAIState(STATE_IDLE); RemoveAIUpdateEvent(); } void OnDied(Unit * mKiller) { RemoveAIUpdateEvent(); } void AIUpdate() { uint32 val = RandomUInt(1000); SpellCast(val); } void SpellCast(uint32 val) { if(_unit->GetCurrentSpell() == NULL && _unit->GetAIInterface()->GetNextTarget())//_unit->getAttackTarget()) { if(m_cast) { _unit->CastSpell(_unit->GetAIInterface()->GetNextTarget(), infocast, false); m_cast = false; return; } if(m_aoe) { _unit->CastSpell(_unit->GetAIInterface()->GetNextTarget(), infoaoe, false); m_aoe = false; return; } if(m_summon) { _unit->CastSpell(_unit->GetAIInterface()->GetNextTarget(), infosummon, false); m_summon = false; return; } if(val >= 1 && val <= 499) { _unit->setAttackTimer(2000, false); m_cast = true; } if(val >= 500 && val <= 700) { _unit->setAttackTimer(3000, false); m_summon = true; } if(val >= 701 && val <= 1000) { _unit->setAttackTimer(4000, false); m_aoe = true; } } } protected: bool m_cast; bool m_aoe; bool m_fire; bool m_frost; bool m_shadow; bool m_summon; bool m_shield; SpellEntry *infocast, *infoaoe, *infoshield, *infosummon; }; void SetupAdvancedMobScriptMgr * mgr) { mgr->register_creature_script(CN_ADVANCEDMOB, &AdvancedMobAI::Create); }