Versiones comparadas

Clave

  • Se ha añadido esta línea.
  • Se ha eliminado esta línea.
  • El formato se ha cambiado.
Comentarios: add missing headers, add override keyword, change tabs to spaces for consistency

...

Lets assume we you have created a script and saved it in a file called My_script.cpp in the source directory /src/server/scripts/Custom
For this guide lets use this script as an example of what My_script.cpp could look like:

Bloque de código
languagecpp
titleMy_script.cpp
linenumberstrue
#include "Define.h"
#include "ScriptMgr.h"
#include "SharedDefines.h"
#include "Unit.h"
// .. more includes

class my_script_class : CreatureScriptUnitScript
{
public:
    my_script_class() : CreatureScriptUnitScript("my_script") {}

    void OnHeal(Unit* healer, Unit* reciever, uint32& gain) override
    {
        // more code ..  this will make healer yell after healing spell is done
        healer->Yell("Healing done", LANG_UNIVERSAL);
    }
};
 
void AddSC_my_script()
{
    new my_script_class();
} 

The example script uses the function called AddSC_my_script to link it to the core code. You need to use an unique name for your function - otherwise the compiler will error as there are two identical functions.  


First you need to add the declaration of the function that is used to link your script and then you add the call to the function - soon we show where to place them.
For our example code the function was called AddSC_my_script. Here is an example of how the declaration and the call look like:

...

Bloque de código
languagecpp
// The name of this function should match:
// void Add${NameOfDirectory}Scripts()
void AddCustomScripts()
{
    AddSC_my_script();
}

...


Here is a final example of how the file could look after both edits:

Bloque de código
languagecpp
// This is where scripts' loading functions should be declared:
void AddSC_my_script();


// The name of this function should match:
// void Add${NameOfDirectory}Scripts()
void AddCustomScripts()
{
    AddSC_my_script();
}

...


Next you need to use cmake and compile.

...