Adding the script to the Solution Bearbeiten
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.
If you are converting an older script, be sure to replace #include "precompiled.h" with #include "ScriptedPch.h"
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 '//custom' at the top of the file and under '//custom' at the bottom of the file the lines:
void AddSC_my_script(); AddSC_my_script();
//custom void AddSC_my_script(); //examples void AddSC_example_creature(); void AddSC_example_escort(); void AddSC_example_gossip_codebox(); void AddSC_example_misc();
//custom AddSC_my_script(); //examples AddSC_example_creature(); AddSC_example_escort(); AddSC_example_gossip_codebox(); AddSC_example_misc();
Adding the script to the Scripts project Bearbeiten
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 Source 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.
Simply add the following line to /home/trinity/core_directory/src/scripts/CMakeLists.txt:
Adding the script to the Database Bearbeiten
You need to link the script to the appropriate areatrigger/creature/gameobject/instance/item the script is for.
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.