Jump to content
  • 0

[ELUNA] Adding a Get_XP_Rate and Set_XP_Rate Funktion


cabfever

Question

Hey guys,

I was thinking that it would be a nice feature to have this included by default into lua (at least because I am unable to extend it to support it myself on my server :D)

Could be useful for more people maybe.

Talking about something like this:

// GetXpRate()
static int GetXpRate(lua_State* L, Unit* unit)
{
	TO_PLAYER();

	sEluna->PushInteger(L, player->GetCustomXpRate());
	return 1;
}

// SetXpRate(number)
static int SetXpRate(lua_State* L, Unit* unit)
{
	TO_PLAYER();

	float xprate = luaL_checknumber(L, 1);

	player->SetCustomXpRate(xprate);
	return 0;
}

Found here: [Trinity] Individual player XP and loot rates for latest TrinityCore 3.3.5a

Link to comment
Share on other sites

10 answers to this question

Recommended Posts

Its not that simple.

The core in itself doesnt support custom XP rates. Adding that would mean implementing support everywhere.

Unlikely a custom and not necessarily useful functionality is added.

This can already be done in a way in Eluna.

Assuming the XP hook works as intended, you can use it:

PLAYER_EVENT_ON_GIVE_XP = 12, // (event, player, amount, victim) - Can return new XP amount

and just make it return a bigger XP amount than what "amount" variable is.

You can make it player specific rate relatively easily and could store the rates to DB as well.

Quick draft:

local function OnGiveXp(event, player, amount, victim)
   return amount * 1.2
end

RegisterPlayerEvent(12, OnGiveXp)

Link to comment
Share on other sites

And if I wanted to allow the player to change that ingame with a .xprate (from 1 to 14) for example.

Then I would replace the OnLogin function with this?

PLAYER_EVENT_ON_COMMAND = 42, // (event, player, command) - player is nil if command used from console. Can return false

Need to find out then how I could use this.

Link to comment
Share on other sites

And if I wanted to allow the player to change that ingame with a .xprate (from 1 to 14) for example.

Then I would replace the OnLogin function with this?

PLAYER_EVENT_ON_COMMAND = 42, // (event, player, command) - player is nil if command used from console. Can return false

Need to find out then how I could use this.

No. I coded a ready function in the script for player so you can just make a command and there use

player:SetXPRate(2.3) for example. 2.3 would come from the command ofc.

Okay, tested the script so far. If I type in a value into the DB for my character manually, it get's deleted when I use .save or logout.

Plus the gained XP is not increased when I set the rate to 14 for example.

Were you logged in when you changed the value in DB?

You should never mess with the database when the server runs or you are logged in with the character you modify.

Also if you are logged in and or the server is running, I made a function that you can use. Read the bottom of the script and above what I wrote about the SetXPRate

Link to comment
Share on other sites

Okay, worked when I wasn't logged in. But now I have absolutely no clue how to make a command out of this.

Watched at this https://github.com/CoronaCore/LuaScripts/blob/master/lua_scripts/custom/gm_announce.lua. Also watched into this [Lua] local lootCmd = "char loot"; -- Maximum loot shown on use of the loot command - Pastebin.com to make a .xp rate command outta it.

I feel lost in unknowledge, god damnit :D

Tried to add it this way:

local XPCMD14 = "#set xprate 14"

function ChatSystem(event, player, msg, _, lang)
   if (msg:sub(1, XPCMD14:len()) == XPCMD14) then
       player:SetXPRate(14)
   end
end

RegisterPlayerEvent(18, ChatSystem) 

Tried to add this to your script - but this did not work. I'm doing something completely wrong + I would love to use a . command instead of the #

Also I think my method is pretty dirty since I would add an if loop for every single xp rate... like set xprate 1, set xprate 2 up to 14 :D

Link to comment
Share on other sites

Oh fuck, it worked somehow. I guess it's writing the 1.4 into the rate column on every automatic server sided character saving.

But how could I change the # command to a . command? And would there be a possibilty to write it instantly into the DB instead after a char save, logout or disconnect?

Link to comment
Share on other sites

Okay, worked when I wasn't logged in. But now I have absolutely no clue how to make a command out of this.

Watched at this https://github.com/CoronaCore/LuaScripts/blob/master/lua_scripts/custom/gm_announce.lua. Also watched into this [Lua] local lootCmd = "char loot"; -- Maximum loot shown on use of the loot command - Pastebin.com to make a .xp rate command outta it.

I feel lost in unknowledge, god damnit :D

Tried to add it this way:

local XPCMD14 = "#set xprate 14"

function ChatSystem(event, player, msg, _, lang)
   if (msg:sub(1, XPCMD14:len()) == XPCMD14) then
       player:SetXPRate(14)
   end
end

RegisterPlayerEvent(18, ChatSystem) 

Tried to add this to your script - but this did not work. I'm doing something completely wrong + I would love to use a . command instead of the #

Also I think my method is pretty dirty since I would add an if loop for every single xp rate... like set xprate 1, set xprate 2 up to 14 :D

Looks alright .. hmm.

Oh fuck, it worked somehow. I guess it's writing the 1.4 into the rate column on every automatic server sided character saving.

But how could I change the # command to a . command? And would there be a possibilty to write it instantly into the DB instead after a char save, logout or disconnect?

Yes. The save happens on steady intervals. And like I said earlier, you should use rather new Rel20. The OnSave hook was using old TC code that was faulty.

The old save code only ran on the steady intervals and no on logout etc.

I would recommend only saving on the save hook to reduce server stress.

Also incase of a rollback everything is rolled back and not everything else except the rate change.

If you really want to directly save on change, just call OnSave in the SetXPRate command.

To change # to a . you can use the hook you already mentioned earlier and like everything .. its obviously 42.

To make the command .. better ..

you can use patterns. Check this out: Pattern matching - WoWWiki - Your guide to the World of Warcraft

simple command:

local function OnCommand(event, player, cmd)
   -- Use regex to check that cmd is the right command and also extract the value the player wants to use
   -- make the command lowercase before matching to allow using .SeT xPrAtE 1
   local rate = cmd:lower():match("set xprate ([^%s]+)")

   -- check that rate is not nil (cmd matched and rate is a number)
   if (rate) then
       -- convert the string extracted to a number or nil
       rate = tonumber(rate)

       -- check that rate is number and is within wanted range
       if (not rate or rate < 1 or rate > 1.4) then
           player:SendBroadcastMessage("Invalid value, must be between 1 and 1.4") -- error
       else
           player:SetXPRate(rate) -- change rate
       end

       -- prevent Incorrect Syntax from appearing in chat
       return false
   end
end

RegisterPlayerEvent(42, OnCommand)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use