• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

Working with TrinityCore's new "OVERRIDE" and "FINAL" define directive

Tommy

Founder
Hello everyone! I'm here to keep everyone up to date with the latest of TrinityCore. It comes to my attention they have added 'OVERRIDE' and 'FINAL' define directives to their source. OVERRIDE is used in just about every Scripting class. For example: CommandScript, ItemScript, CreatureScript, ScriptedAI, BossAI, etc.

If you don't know much about the override keyword, here is more about: http://msdn.microsoft.com/en-us/library/vstudio/41w3sh1c.aspx
If you don't know much about the final keyword, here is a link about it: http://en.cppreference.com/w/cpp/language/final
If you don't know much about virtual functions, here is another link: VIRTUAL FUNCTIONS

As far as I can tell, 'FINAL' is only used on 'IsDatabaseBound' function.

Okay! Now, what you can do is look at the other sources to see what they look like or you can follow me.. either way, I'm trying to make this as quick as possible.

Every function in all the classes I mentioned above are virtual functions, meaning an OVERRIDE should be used beside of them when called. For example:

ScriptedAI / CreatureScript:
Code:
class npc_tutorial : public CreatureScript
{
public:
    npc_tutorial() : CreatureScript("tutorial") { }

    struct npc_tutorialAI : public ScriptedAI
    {
        npc_tutorialAI(Creature* creature) : ScriptedAI(creature) { }

        void Reset() OVERRIDE
        {
        }

        void UpdateAI(uint32 diff) OVERRIDE
        {
        }

        void EnterCombat(Unit* /* target */) OVERRIDE
        {
        }

        void JustDied(Unit* /* killer */) OVERRIDE
        {
        }
    };

    CreatureAI* GetAI(Creature* creature) const OVERRIDE
    {
        return new npc_tutorialAI(creature);
    }
};

void AddSC_tutorial_npc()
{
    new npc_tutorial;
}

Creature Gossip:

Code:
class npc_tutorial : public CreatureScript
{
public:
    npc_tutorial() : CreatureScript("tutorial") { }

    bool OnGossipHello(Player* player, Creature* creature) OVERRIDE
    {
        return true;
    }

    bool OnGossipSelect(Player* player, Creature* creature, uint32 /* sender */, uint32 /* actions */) OVERRIDE
    {
        return true;
    }

    bool OnGossipSelectCode(Player* player, Creature* creature, uint32 /* sender */, uint32 /* actions */, const char* code) OVERRIDE
    {
        return true;
    }
};

void AddSC_npc_gossip()
{
    new npc_tutorial;
}

Please note CreatureScript was used as an example. "OVERRIDE" goes for almost all script classes like I mentioned above!

I'm just giving you a heads up about all of this, as it is new and you need to stay updated! If you aren't sure about something, look at TrinityCore's example scripts: https://github.com/TrinityCore/TrinityCore/tree/master/src/server/scripts/Examples

You can also go to my scripting templates thread as well: http://emudevs.com/showthread.php/58-Basic-Intermediate-Scripting-Templates?p=184#post184

Enjoy!
 
Last edited:

Tommy

Founder
tbh it's not even needed

I know, but I'd rather keep everyone updated. Besides, it should be needed because there are virtual functions in most of the scripting classes, I just never bothered with it until they did. :/
 
Top