mirror of
https://github.com/araxiaonline/wow.ets.modules.git
synced 2026-06-13 02:32:21 -04:00
Added XP Rate command
This commit is contained in:
15
modules/commands/set-xp-rate.readme.md
Normal file
15
modules/commands/set-xp-rate.readme.md
Normal file
@@ -0,0 +1,15 @@
|
||||
## Set XP Rate Command
|
||||
|
||||
This will allow players to use their chat window to set a custom xp rate with a limit. This allows individual players to either choose to enjoy the store or get to the end game content.
|
||||
|
||||
Configuration:
|
||||
|
||||
**MAX_XP_RATE**: number - defaults to 5
|
||||
|
||||
Chat commands
|
||||
|
||||
```
|
||||
#xprate show - displays players current xp rate
|
||||
#xprate set [number] - sets the players xp growth rate
|
||||
|
||||
```
|
||||
116
modules/commands/set-xp-rate.ts
Normal file
116
modules/commands/set-xp-rate.ts
Normal file
@@ -0,0 +1,116 @@
|
||||
/**
|
||||
* @file set-xp-rate.ts
|
||||
* @date 2023-11-15
|
||||
* @author ben-of-codecraft
|
||||
*
|
||||
* Type: Command
|
||||
* Adds a command that allows players to set their own XP rate for their character up to 5x normal xp rate.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Configuration options
|
||||
*/
|
||||
const MAX_XP_RATE = 5;
|
||||
|
||||
// Command to show the current xp rate
|
||||
const xpCmd = "#xprate";
|
||||
const showXPcmd = "#xprate show";
|
||||
const setXPcmd = "#xprate set";
|
||||
|
||||
const XP_RATE_SETTING = "xp_rate";
|
||||
|
||||
import { PlayerStats } from "../classes/stats";
|
||||
|
||||
let xpRateCache = new Map<number, number>();
|
||||
|
||||
const XPRateHandler: player_event_on_chat = (event: number, player: Player, message: string) => {
|
||||
|
||||
if(message.includes(xpCmd)) {
|
||||
|
||||
const args = message.split(" ");
|
||||
const cmd = args[1];
|
||||
|
||||
|
||||
const playerCustom = new PlayerStats(player);
|
||||
playerCustom.load();
|
||||
|
||||
if(cmd == "show") {
|
||||
const xpRate = xpRateCache.get(player.GetGUIDLow());
|
||||
if(xpRate != undefined) {
|
||||
player.SendBroadcastMessage(`Your current XP rate is ${xpRate}x`);
|
||||
} else {
|
||||
player.SendBroadcastMessage(`Your current XP rate is 1x`);
|
||||
}
|
||||
|
||||
} else if(cmd == "set") {
|
||||
const rate = args[2];
|
||||
const rateNum = parseInt(rate);
|
||||
|
||||
if(rateNum > MAX_XP_RATE) {
|
||||
player.SendNotification(`You cannot set your XP rate higher then ${MAX_XP_RATE}x`);
|
||||
return false;
|
||||
}
|
||||
|
||||
playerCustom.setStat(XP_RATE_SETTING, rateNum);
|
||||
playerCustom.save();
|
||||
xpRateCache.set(player.GetGUIDLow(), rateNum);
|
||||
|
||||
player.SendBroadcastMessage(`Your XP rate has been set to ${rateNum}x`);
|
||||
}
|
||||
else {
|
||||
player.SendBroadcastMessage(`Usage: ${xpCmd} [show|set] [rate]`);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* Gives players extra XP based on their rate
|
||||
* @param event \
|
||||
* @param player
|
||||
* @param amount
|
||||
* @param victim
|
||||
*/
|
||||
const XPBonus: player_event_on_give_xp = (event: number, player: Player, amount: number, victim: Unit) => {
|
||||
|
||||
const xpRate = xpRateCache.get(player.GetGUIDLow());
|
||||
if(xpRate && xpRate > 1) {
|
||||
player.GiveXP(amount * xpRate);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const XPRateLoader: player_event_on_login = (event: number, player: Player) => {
|
||||
|
||||
|
||||
const playerCustom = new PlayerStats(player);
|
||||
playerCustom.load();
|
||||
|
||||
const xpRate = playerCustom.getStat(XP_RATE_SETTING);
|
||||
if(xpRate) {
|
||||
xpRateCache.set(player.GetGUIDLow(), xpRate.value);
|
||||
} else {
|
||||
xpRateCache.set(player.GetGUIDLow(), 1);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// Grants players extra XP Based on their rate
|
||||
RegisterPlayerEvent(PlayerEvents.PLAYER_EVENT_ON_GIVE_XP, (...args) => XPBonus(...args));
|
||||
|
||||
// Register the command
|
||||
RegisterPlayerEvent(PlayerEvents.PLAYER_EVENT_ON_CHAT,
|
||||
(...args) => XPRateHandler(...args)
|
||||
);
|
||||
|
||||
// Loads the cache of seetings on login
|
||||
RegisterPlayerEvent(PlayerEvents.PLAYER_EVENT_ON_LOGIN, (...args) => XPRateLoader(...args));
|
||||
|
||||
// reloads the cache of settings when the lua state is opened
|
||||
RegisterServerEvent(ServerEvents.ELUNA_EVENT_ON_LUA_STATE_OPEN, (...args) => {
|
||||
xpRateCache = PlayerStats.GetStatsByType('player', XP_RATE_SETTING);
|
||||
});
|
||||
Reference in New Issue
Block a user