View Full Version : [SOLVED] Gathering info about TC\'s API

04-07-2015, 08:13 AM
Hello, some time ago i started the Cpp learning journey and blah blah blah you know that (motivation speech i'll don't repeat it).
Anywayz to the topic, well i looked into few scripts for TC few up to date few outdated i got basic point now how stuff work here, but here is my question :)

Where i can get any basic and short info about headers which one is which one? Look all them by myself or there is any documentation? Or maybe if there no API documentation and you not busy person, can you make a simple one including the most used headers?

P.s if you have any suggestions for starter feel free to give em up !

04-07-2015, 10:48 AM
It isn't necessary to include headers unless compilation fails and a header is required. For example, calling pet methods requires "Pet.h" to be included in your file and CommandScript requires "Chat.h" to be included. However, headers such as "ScriptPCH.h" isn't necessary because CMake takes care of a lot of the required includes. TrinityCore team changed that awhile back but people are still including "ScriptPCH.h" when they don't have to. However, including headers you aren't going to use is just a waste. I see a lot of people releasing scripts and they overload their scripts with unless headers that they think they need but they aren't using them at all. It is best to include headers when they are required.

Here's an example of a script in Visual Studio that doesn't have "Pet.h" included and I'm trying to call its methods anyway:

Intellisense errors and says:


Pet class isn't defined so we need to include "Pet.h" to lift this error.

If I include "Pet.h", all is well:


As you see, I have no other includes except "Pet.h".

For references, I'd look at the existing scripts to see how they are setup and work with specific included headers. It helps to view other scripts to expand out and try to learn off of them. Regarding the API, I don't think there's anything that can help you in detail unless someone made something to do so.

04-07-2015, 12:43 PM
Well i got the point :)
And for example for get player max level in configs i include config.h and search there for MAX_PLAYER_LEVEL define or something like that , and just use it
like :

#include "Config.h"

class firstScript : public PlayerScript
firstScript() : PlayerScript("firstScript") {}

bool levelCheck(Player * Hero){
if (Hero->getLevel() == sWorld->getIntConfig(CONFIG_MAX_PLAYER_LEVEL))
return true;


void AddSC_firstScript()
new firstScript();

IT will look like that?
IN Visual studio i have no errors here.

04-07-2015, 02:42 PM
This is not always true, but mostly headers contain what the name says:
Player.h = Player class
Pet.h = Pet class
And should be used like tommy said, when necessary.

If you want to use the player class, but not the functions etc that it holds,
you can do that by declaring the class like this before using it:

class Player;
// now we can create a variable to Player without including the file :D
Player* player;

If you code and see something missing like Pet, its pretty easy to guess that its probably Pet.h or something similar by name.
VS is able to suggest you stuff when you write the start like : #include "Pe
Headers give you access to the declared and defined things in them and other headers the headers include in themselves.

In your example you may need to include:
World.h for sWorld since singletons are classes and you need their method declarations to use their methods
ScriptMgr.h for PlayerScript since PlayerScript is a class that is defined there.
Player.h for Player class and its method usage

A few useful files you could check out: Common.h has most of the map, set, vector and Defines.h has types like uint32 etc defined. However Common.h also includes Defines.h, so just add Common.h.

Sometimes you may only need Player.h for example, since it could include World.h and ScriptMgr.h.
You might want to play it safe sometimes incase for example the headers for Player.h change and your code will then be erroring due to missing includes.

Your build might be going fine since you are using the precompiled header.
Precompiled header is a header file that has a lot of header code in it, which is included everywhere.
Having it compiled will speed up the compiling process of files that use those included files.
As a side effect you may not need to include everything you actually use in your script.
If you check TC commits, you should see often commits that say something like "Fixed build without precompiled header".
Those commits include files that should be included, but are not, and they are not noticed missing unless you build for example without the precompiled header files.

It is probably a good idea to know a bit about what files you actually need if you make some internal files, however for scripts its mostly needed just to include the ScriptPCH.h, which contains most common script and other headers and as the name says, is a pch so the precompiled header is used if set so in Cmake.

Correct me if I am wrong. I have not studied or referenced a textbook myself.

04-07-2015, 05:38 PM
Really informative and "clean" i like the answers guys ! :)
Thank you so much !