Tutorial - How to add a C++ script into your core

ExO

Admin
5,084
2014
1,442
This is a share from Jameyboor, I have asked him if I was allowed to share it and got his permissions to release it on here:

this is a tutorial on how to add a custom C++ script to your Trinity core.

I know there are more of these only some are not very clear.

lets start:


How to add a C++ script to your server?:


1. You NEED a self-compiled server, so NOT a repack.

2. Open up your Trinitycore solution in Microsoft Visual Studio , hit Ctrl+N then a screen will pop-up, click on Visual C++ and click on C++ file.cpp

3. paste the whole code in the new text box and save it as your desired name.cpp and place it in your C:/Trinity/src/server/scripts/Custom folder.

4. open up C:/Trinity/src/server/scripts/Custom/Cmakelists.txt

5. you will see some copyright text, scroll down till you find this:
Code:

set(scripts_STAT_SRCS ${scripts_STAT_SRCS})
add a new line, that looks like this : Custom/yourscriptname.cpp
so example:
Code:

set(scripts_STAT_SRCS ${scripts_STAT_SRCS}Custom/mynewscript.cpp)
then save that

6. Go to your build folder Default C:/Build.

7. Open the TrinityCore.sln file with the type: Microsoft Visual Studio Solution

8. on the left of the screen you should have a solution explorer, if not then hit CTRL+ Alt + L

9. open up the project "game" in your solution explorer by clicking on the arrow left to the "game" project.

10. click on the arrow that says "Source files" and scroll down until you see Scriptloader.cpp

11. open the file Scriptloader.cpp, scroll all the way down until you see this:
Code:

#ifdef SCRIPTS/* This is where custom scripts' loading functions should be declared. */#endifvoid AddCustomScripts(){#ifdef SCRIPTS /* This is where custom scripts should be added. */#endif}
12. Find the code of your script and scroll all the way down until you see something like this:
Code:

void AddSC_Example(){ new Example;}
I used example but at your code there can be other text ofcourse.

13. Copy the void AddSC_Example() then go back to your Scriploader.cpp file and paste that, so that it will look like this :
Code:

#ifdef SCRIPTS/* This is where custom scripts' loading functions should be declared. */void AddSC_Example();#endifvoid AddCustomScripts(){#ifdef SCRIPTS /* This is where custom scripts should be added. */AddSC_Example();#endif}
Remember to add the ; at the end to both and remove the void at the second.

14. Go back to your Solution Explorer and search the project "scripts", then click on the arrow left from the project.

15. Right-click on the Source files folder and click on Add->Existing Item.

16. You will see a window popping up that will ask where your .cpp file is, we already saved it in a folder so lets go and open that folder.
Go to C:/Trinity/src/server/scripts/Custom and double-click on your .cpp file to add it.

17. Recompile and your done, Congratulations!


How to recompile?

A lot of people don't know what the word "recompiling" means in when starting, the meaning of this word is just the re-making (building) of your server, how to do this?
1. on the top of your screen you will see a green triangle and a dropdown- menu on the side of it.
2. Make sure that the dropdown-menu is set to Release and set to the right Bit version, according to your Computer (32/64 bit)
3. Click on the green triangle, a box will pop-up asking you to build some projects, click on "yes" and the recompiling will start, Congratulations!


This part is only for adding a script to an areatrigger/creature/gameobject/instance/item, if your script is not about any of these categories then you are done.

If you want to add a areatrigger/creature/gameobject/instance/item
then you have to do one more thing, I will show you in a few steps.


1. Open up your Database and open up the catergory table of what you want to add like : creature_template for creatures.

2. Make or edit an existing areatrigger/creature/gameobject/instance/item

3. Go to the column named "ScriptName".

4. Go to your script, and search something like this ( used Faded's teleporter (a creature)) :
Code:

class tc_teleporter : public CreatureScript{ public: tc_teleporter() : CreatureScript("tc_teleporter") {}

5. When you have that then you will need
Code:

: CreatureScript("tc_teleporter")

6. Go back to your Database and Write in ScriptName, the part i wrote in red:

Code:

: CreatureScript("tc_teleporter")

7. You are done now, you may need to restart your server or reload your areatrigger/creature/gameobject/instance/item.
 

jregan

Verified Member
6
2014
0
thank you been searching for how to start working on trying to program on the server.
 
Top