Double Experience

I want to make a custom script to check the day of the week and increase experience if it matches Friday, Saturday or Sunday, but I don’t even know where to start is the problem.

Essentially when a player turns in a quest I want the server to say okay it’s Saturday, so we’re going to grant worldserver.conf xp times two. Is this something that can be done with a custom cpp or do I have to modify the entire framework of player.cpp?

Looks like the best way would be to look where sWorld->getRate(RATE_XP_QUEST) is used (there are multiple places) and add code for what you need there.

For the time stuff you can either do some math with time(nullptr) or you can try use boost if possible.
There are also some functions like localtime, but its not thread safe and boost should be.

[CODE]#include “boost\date_time.hpp”

boost::gregorian::date date(boost::gregorian::day_clock::local_day());
if (date.day_of_week() == boost::date_time::Friday ||
date.day_of_week() == boost::date_time::Saturday ||
date.day_of_week() == boost::date_time::Sunday)
{
// do stuff
}[/CODE]

So essentially I could utilize

#include “boost\date_time.hpp”

boost::gregorian::date date(boost::gregorian::day_clock::local_day());
if (date.day_of_week() == boost::date_time::Friday ||
date.day_of_week() == boost::date_time::Saturday ||
date.day_of_week() == boost::date_time::Sunday)
{
#define doublexp = true;
}
else {
#define doublexp = false;
}And then for something within world.cpp. Just wondering if this would work they have

rate_values[RATE_XP_KILL] = sConfigMgr->GetFloatDefault(“Rate.XP.Kill”, 1.0f);
rate_values[RATE_XP_QUEST] = sConfigMgr->GetFloatDefault(“Rate.XP.Quest”, 1.0f);
rate_values[RATE_XP_EXPLORE] = sConfigMgr->GetFloatDefault(“Rate.XP.Explore”, 1.0f);Should something along the lines of

if(doublexp = true) {
rate_values[RATE_XP_KILL] = sConfigMgr->GetFloatDefault(“Rate.XP.Kill”, 2.0f);
rate_values[RATE_XP_QUEST] = sConfigMgr->GetFloatDefault(“Rate.XP.Quest”, 2.0f);
rate_values[RATE_XP_EXPLORE] = sConfigMgr->GetFloatDefault(“Rate.XP.Explore”, 2.0f);
}
else {
rate_values[RATE_XP_KILL] = sConfigMgr->GetFloatDefault(“Rate.XP.Kill”, 1.0f);
rate_values[RATE_XP_QUEST] = sConfigMgr->GetFloatDefault(“Rate.XP.Quest”, 1.0f);
rate_values[RATE_XP_EXPLORE] = sConfigMgr->GetFloatDefault(“Rate.XP.Explore”, 1.0f);
}Sorry; new to custom scripting and trying to learn it without being too much of an aggravance lol

Originally thought you wanted it for quest only.

If you want all XP to be double its easy to make a playerscript for the XP and double the given XP there.

PlayerScript:

OnXP(player, givenxp, victim)
{
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)
givenxp = givenxp*2;
}Note that the XP in the XP hook is a reference, so you can modify the value and it will modify the actual given XP.
Might also want to think a little about how to handle possible overflows. Like lets say someone gets 2200000000 xp (if thats even possible) then it multiplied by 2 would go over the uint32 range and result in less XP than the original.

https://github.com/TrinityCore/TrinityCore/blob/3.3.5/src/server/game/Scripting/ScriptMgr.h#L712-L713

If you would do it like you posted, then you would need to restart the server or at least reload the config in order for the rates to change and then Im pretty sure it would be the same as just manually changing the rates in the config all the time when you want an increased rate or normal.

So I could actually set this as a custom XP for the weekend only as well. I see a lot of possibilities just have to learn it all first haha

So I made a WeekendXP.cpp and added it to the cmake files then added it to the scriptloader. I put in a notification that way I could tell if it was working.

Everything compiles, but I had to set some variables manually, so I don’t know if that’s a good thing. This is the script I have that compiles, but stops there. Doesn’t work in game.

[CODE]#include “ScriptMgr.h”
#include “Player.h”
#include “Chat.h”

class XpWeekend : public PlayerScript
{
public:
XpWeekend() : PlayerScript(“XpWeekend”) { }
void OnXP(Player* player, uint32 givenxp, uint32 victim)
{
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 Weekend is going on now!”);

    givenxp = givenxp*2;

}
};

void AddSC_XpWeekend()
{
new XpWeekend();
}[/CODE]

Noticed I wasn’t including libboost. Trying to include it right now, but there is no date_time.hpp, there is however a date.hpp

Was able to include libboost, tried including world.h as a trial to see if that’s why givenxp and victim weren’t declared to no avail.

Someone did this on the past, very likely needs to be updated:

http://pastebin.com/pxpgVbA8

OnXP isnt an actual hook. See the link I posted earlier for the real one: https://github.com/TrinityCore/TrinityCore/blob/3.3.5/src/server/game/Scripting/ScriptMgr.h#L712-L713

Use override keyword so you can spot this stuff immediately:

class XpWeekend : public PlayerScript
{
public:
XpWeekend() : PlayerScript(“XpWeekend”) { }
void OnXP(Player* player, uint32 givenxp, uint32 victim) override // Error
{
// code
}

Note that now the day restriction only applies to the print and not to the actual XP gained since you are not using {} around the code that should be in the IF block.