• 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 Creating a custom configuration setting

Tommy

Founder
Hello guys! Today I'm going to show you how to make your own configuration setting in the worldserver.conf file. It is pretty simple.

First, let's go off of what you need:
TrinityCore Source
Microsoft Visual Studio 2010, 2012 or greater
Knowledge on how to edit existing code


The files we will be editing is:
World.cpp
World.h
worldserver.conf


What we need to do is think of what we want. I guess I'll go with a basic value that can be changed to give an item to a player.

Go to your worldserver.conf file and we'll edit that first.


At the very bottom of my worldserver.conf file, I added:

Code:
#  Player item on login or when needed
#      Item.
#        Description: This is an itemId that will be given to a player when needed
#

Item.RandomItemId = 90000


Pretty basic! Alright, now we need to get this sucker loading when the server goes up. Open your World.h file.

Search for WorldIntConfigs enumerator. Once found, above
"INT_CONFIG_VALUE_COUNT" at the very bottom of the enumerator add:

Code:
CONFIG_RANDOM_ITEM_ID,

Great! Now go to your World.cpp file and search for:

Code:
/// Initialize config values
void World::LoadConfigSettings(bool reload)

Once found, we need to add our custom setting in there. This is what we need to use for 'WorldIntConfigs' enumerator:

Code:
m_int_configs[CONFIG]

Very simple. Alright, at the very bottom above:

Code:
    // call ScriptMgr if we're reloading the configuration
    if (reload)
        sScriptMgr->OnConfigLoad(reload);

Add:

Code:
m_int_configs[CONFIG_RANDOM_ITEM_ID] = sConfigMgr->GetIntDefault("Item.RandomItemId", 90000);

Really self explanatory. The "Item.RandomItemId" is our setting name and the "90000" is our default value if a value isn't given in the configuration file.


Great! It is pretty much finished! Let's run a test script, shall we?

Change the item Id in the config to 0 and see if it still sets itself to the default value.

Code:
Item.RandomItemId = 0


And it works:

tnFKWjV.png


One more test! Set the itemId to a randomId. Testing code:

Code:
    TC_LOG_ERROR(LOG_FILTER_SERVER_LOADING, "ItemId is %u!", sWorld->getIntConfig(CONFIG_RANDOM_ITEM_ID));

Setting:

Code:
Item.RandomItemId = 89


Output:

ScjaWWo.png


I hope you enjoyed this tutorial! :D
 

Neth

BETA Tester
note :
Code:
sLog->outError(LOG_FILTER_SERVER_LOADING, "ItemId is %u!", sWorld->getIntConfig(CONFIG_RANDOM_ITEM_ID));
has been changed to
Code:
TC_LOG_ERROR(LOG_FILTER_SERVER_LOADING, "ItemId is %u!", sWorld->getIntConfig(CONFIG_RANDOM_ITEM_ID));
 

Tommy

Founder
Really, why do they keep changing everything? It is getting really pointless.

Updated, thanks Neth.

----
Okay, after going through this, they are only using #define definitions for easy access.
 

Kaev

Super Moderator
Outdated.
Instead of
Code:
m_int_configs[CONFIG_RANDOM_ITEM_ID] = ConfigMgr::GetIntDefault("Item.RandomItemId", 90000);

It should be:
Code:
m_int_configs[CONFIG_RANDOM_ITEM_ID] = sConfigMgr->GetIntDefault("Item.RandomItemId", 90000);
 
Top