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

Written Adding a C++ script to your core

Jameyboor

Retired Staff

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

2. Open up your 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 to you find this:
Code:
set(scripts_STAT_SRCS
  ${scripts_STAT_SRCS}
)

do like this Custom/yourscriptname.cpp
so example:
Code:
set(scripts_STAT_SRCS
  ${scripts_STAT_SRCS}
Custom/example.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. */
#endif

void 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();
#endif

void 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 the beginning, 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("[COLOR=Red]tc_teleporter[/COLOR]")

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

Note: I took Faded's teleporter script so that why its : tc_teleporter, ofcourse there can be something else in your script.

Remember that you can always ask me questions if you need help with this, just leave a post :)
 
Last edited:

ravez

Respected Member
Weird. All of a sudden after adding some scripts successfully my "source files" under scripts is gone, any ideas? ;P


http://i.imgur.com/pBgn9O4.png
 

Attachments

  • pBgn9O4.jpg
    pBgn9O4.jpg
    7.2 KB · Views: 57

ravez

Respected Member
Yeah opening with that one. Now when clicking on 'scripts' all the cpp files which usually show when clicking on source file, is showing directly in Scripts. So it's like the files in 'source file' folder is now directly in scripts?

If you understand what I mean, gosh I suck at explaining lol.

Can I restore it back to how it was before? ;D
 

Tommy

Founder
Yeah opening with that one. Now when clicking on 'scripts' all the cpp files which usually show when clicking on source file, is showing directly in Scripts. So it's like the files in 'source file' folder is now directly in scripts?

If you understand what I mean, gosh I suck at explaining lol.

Can I restore it back to how it was before? ;D

It doesn't have to be in the Source Files / Header Files filters in your solutions, but if you want it back the same just rerun a configure / generate in CMake and I'm sure it will go back the same.
 

vxea

Respected Member
That's not my video... so you know and no im not afraid to talk to a microphone

I though I didn't have to credit it since I shared the video and can be acces to youtube :/
 

Tommy

Founder
That's not my video... so you know and no im not afraid to talk to a microphone

I though I didn't have to credit it since I shared the video and can be acces to youtube :/

That's fine. Videos like that shouldn't be created anyway. Considering nobody is talking and giving directions on what you're suppose to do. Nonetheless, thanks for sharing.
 
Top