Custom Scripts

I’m trying to add a custom script to custom_script_loader.cpp.

The file I’m trying to add is DoubleXP.h

My function call is as follows:

void AddSC_XpWeekend()
{
new XpWeekend();
}

My source is scripts/Custom/DoubleXP.h

However when I compile I get that AddSC_XpWeekend() is an uncalled function. Is there anything that needs to be modified within the cmakelists? The last time I did anything with custom scripting was when the custom folder had it’s own cmakelist, now when I check the scripts.dir inside the build it does not have any of the custom content.

https://github.com/TrinityCore/TrinityCore/pull/17782

Thanks Aokromes. Never thought that would be brought into the core. While that is helpful in the case of giving the XP do you know what’s going on with the fact that my custom scripts aren’t added? When I read the new docs I thought they would be auto included with the cmake files. My thoughts now are that it’s because it’s a .h file and not a .cpp and it’s skipped over during cmake processing.

look the code there, compare with your.

What I use is slightly different then the core. I wrote it years ago and just now getting back into toying with emulation. My script I could easily convert it for every day of the week if wanted:

#include “ScriptMgr.h”
#include “Player.h”
#include “Chat.h”
#include “World.h”
#include “/usr/include/boost/date_time.hpp”

class XpWeekend : public PlayerScript
{
public:
XpWeekend() : PlayerScript(“XpWeekend”) { }
void OnGiveXP(Player* player, uint32& amount, Unit* victim)override
{
boost::gregorian::date date(boost::gregorian::day_clock::local_day());
auto day = date.day_of_week();
if (day == boost::date_time::Friday ||
day == boost::date_time::Saturday ||
day == boost::date_time::Sunday) {

    amount = amount*2; }

}
void OnLogin(Player* player, bool firstLogin)
{
boost::gregorian::date date(boost::gregorian::day_clock::local_day());
auto day = date.day_of_week();
if (day == boost::date_time::Friday ||
day == boost::date_time::Saturday ||
day == boost::date_time::Sunday) {

  ChatHandler(player->GetSession()).PSendSysMessage("Double XP is going on now!");
  }
  else {
    //Make informational Script?

}

}

};

void AddSC_XpWeekend()
{
new XpWeekend();
}

And then for loading in in custom_script_loader.cpp I have 

void AddSC_XpWeekend();

// The name of this function should match:
// void Add${NameOfDirectory}Scripts()

void AddCustomScripts()
{
AddSC_XpWeekend();
}

The way I would add this used to be with cmake files

set(scripts_STAT_SRCS
${scripts_STAT_SRCS}

Custom/DoubleXP.h

That would have been in the Custom/CmakeLists.txt, but it looks like that method may be long ago deprecated. Just trying to grasp the new methods as the wiki didn’t provide the information as to how to actually have the custom script included in the cmake generation.