You are on page 1of 2

CustomScript

Adding the script to the Solution


Assuming you created a script called My_script.cpp in C:\Trinity\src\server\scripts\Custom directory, if you are reading this guide it means you
can't figure out how to put it in your solution and compile it with the rest of the source.

Open the file: C:\Trinity\src\server\game\Scripting\ScriptLoader.cpp

We will assume that your linked your script using 'AddSC_my_script', if you don't know what that means, check other scripts to see how they are
linked. You first need to add under ' /* This is where custom scripts' loading functions should be declared. / ' and under '/ This is where custom
scripts should be added. */' at the bottom of the file the lines:

void AddSC_my_script();
AddSC_my_script();

Example

#ifdef SCRIPTS
/* This is where custom scripts' loading functions should be declared. */
void AddSC_my_script();
#endif

and

void AddCustomScripts(){
#ifdef SCRIPTS
/* This is where custom scripts should be added. */
AddSC_my_script();
#endif
}

Adding the script to the Scripts project


Windows
This information is deprecated, all scripts should be added to the proper cmakelists file as shown in the Linux instructions below.

Open the TrinityCore solution file (~build-directory/TrinityCore.sln using the designated compiler that you selected during the CMake process).

Under the scripts project (left hand side of the screen), press the arrow on the left to open the project dependencies. Then right click on the Sour
ce Files folder, and select 'Add' -> 'Existing Item'. Navigate to the location of your custom script (should be something like
C:/Trinity/src/server/scripts/custom), select your script and press 'Add' or 'OK'.

You are done! Now you can build the solution.

Linux
Start by placing scripts in source directory:

~/TrinityCore/src/server/scripts/Custom
Next link each script into the build:

sudo vi ~/TrinityCore/src/server/scripts/Custom/CMakeLists.txt

add each script with a line break before the Parenthesis and after the Curly Brace with <font color="darkblue">Custom/</font> in front of each
script.

Example:

set(scripts_STAT_SRCS
${scripts_STAT_SRCS}
Custom/CS3.cpp
Custom/CS2.cpp
Custom/CS1.cpp
)

message(" -> Prepared: Custom")

Last but not least compile

Adding the script to the Database


You need to link the script to the appropriate areatrigger/creature/gameobject/instance/item the script is for.

Note: Some script types (such as CommandScripts) do not need to be linked to anything in the DB

Example

UPDATE `areatrigger_scripts` SET ScriptName='my_script' WHERE `entry`=XXXX;


UPDATE `creature_template` SET ScriptName='my_script' WHERE `entry`=XXXXX;
UPDATE `gameobject_template` SET ScriptName='my_script' WHERE `entry`=XXXXXX;
UPDATE `instance_template` SET ScriptName='my_script' WHERE `map`=XXX;
UPDATE `item_template` SET ScriptName='my_script' WHERE `entry`=XXXXX;

Note: You might need to edit the creature/gameobject/etc to make sure the script has effect. For example, if you have created a gossip script for
a creature, you will need to set creature_template.npcflag=1 to enable gossip flag on the creature or the script will not work.

You might also like