C++ Script tutorials?

Hey, is there any documents or resource that will teach C++ WoW programming? I have just learned most of C++ console application development, and I thought I would try something new. The only thing I know so far is how to assign spells to a NPC. I need more knowledge before I can devote my full time to here. Thank you. Here’s an example of what I know so far (please let me know if this is a C++ script) :

[CODE]#define CN_DustWraith 10081

class DustWraithAI : public MoonScriptCreatureAI

{

MOONSCRIPT_FACTORY_FUNCTION(DustWraithAI,MoonScriptCreatureAI);

DustWraithAI(Creature * pCreature) : MoonScriptCreatureAI(pCreature)

{

    // Ability : Sinister Strike

    AddSpell(15667,Target_Current,30,0,5);

}

};[/CODE]

hope you know that this is not the arcemu support forums…

MOONSCRIPT_FACTORY_FUNCTION

As I said before, I am a beginner. I have no clue about the syntax, functions, what header files to use, etc. Is there a reference or any documents that will teach me?

There are several ways to make creature cast spell:

  1. Modify SQL database via adding spell1, spell2, etc. to creature_template table. Creature will use spells randomly in fight, you will be unable to control it.

  2. Add EventAI script, via modifying SQL database.

  3. Use SmartAI script, via modifying SQL database.

  4. Modify core (C++). Refer to the following code:


class npc_servant_of_the_throne : public CreatureScript

{

    enum eEvents

    {

        EVENT_GLACIAL_BLAST = 1,

    };

    enum eSpells

    {

        SPELL_GLACIAL_BLAST  = 71029,

    };


public:

    npc_servant_of_the_throne() : CreatureScript("npc_servant_of_the_throne") { }


    CreatureAI* GetAI(Creature* pCreature) const

    {

        return new npc_servant_of_the_throneAI (pCreature);

    }


    struct npc_servant_of_the_throneAI : public ScriptedAI

    {

        npc_servant_of_the_throneAI(Creature *c) : ScriptedAI(c)

        {

            instance = me->GetInstanceScript();

        }


        void Reset()

        {

            events.Reset();

        }


        void EnterCombat(Unit* /*who*/)

        {

            events.Reset();

            events.ScheduleEvent(EVENT_GLACIAL_BLAST, 3000);

        }


        void UpdateAI(const uint32 diff)

        {

            if (!UpdateVictim())

                return;

            if (me->HasUnitState(UNIT_STAT_CASTING))

                return;

            events.Update(diff);

            while (uint32 eventId = events.ExecuteEvent())

            {

                switch (eventId)

                {

                    case EVENT_GLACIAL_BLAST:  

                    {

                        DoCast(me, SPELL_GLACIAL_BLAST);

                        events.ScheduleEvent(EVENT_GLACIAL_BLAST, 5000);

                        break;

                    }

                    default:

                        break;

                }

            }

            DoMeleeAttackIfReady();

        }

    private:

        InstanceScript *instance;

        EventMap events;

    };


}; 

P.S.: contact me in Skype “faradi.no-ip.org” for more information about scripting. I’ve just finished scripting ICC bosses in AspirineCore (TrinityCore fork), so I think I have some knowledge to share.

Take a look at the example_*.cpp files, pretty useful for the first steps.

And never use an script of an different Emulator, it just won’t work without heavy rewriting.

I’m fairly certain this “feature” was removed a long time ago. the spell fields are only used for totems, mind control and vehicles.

https://github.com/TrinityCore/TrinityCore/tree/master/src/server/scripts/Examples