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:
The files we will be editing is:
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:
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:
Great! Now go to your World.cpp file and search for:
Once found, we need to add our custom setting in there. This is what we need to use for 'WorldIntConfigs' enumerator:
Very simple. Alright, at the very bottom above:
Add:
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.
And it works:
One more test! Set the itemId to a randomId. Testing code:
Setting:
Output:
I hope you enjoyed this tutorial!
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
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
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:
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:
I hope you enjoyed this tutorial!