mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-14 09:39:11 +00:00
feat(Core/CommandScript): New GM command "player learn" (#2487)
This commit is contained in:
93
src/server/scripts/Commands/cs_player.cpp
Normal file
93
src/server/scripts/Commands/cs_player.cpp
Normal file
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU AGPL v3 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-AGPL3
|
||||
*/
|
||||
|
||||
#include "Chat.h"
|
||||
#include "ScriptMgr.h"
|
||||
#include "Language.h"
|
||||
#include "Player.h"
|
||||
#include "PlayerCommand.h"
|
||||
|
||||
class player_commandscript : public CommandScript, public PlayerCommand
|
||||
{
|
||||
public:
|
||||
player_commandscript() : CommandScript("player_commandscript") { }
|
||||
|
||||
std::vector<ChatCommand> GetCommands() const override
|
||||
{
|
||||
static std::vector<ChatCommand> playerCommandTable =
|
||||
{
|
||||
{ "learn", SEC_GAMEMASTER, true, &HandlePlayerLearnCommand, "" },
|
||||
{ "unlearn", SEC_GAMEMASTER, true, &HandlePlayerUnLearnCommand, "" }
|
||||
};
|
||||
|
||||
static std::vector<ChatCommand> commandTable =
|
||||
{
|
||||
{ "player", SEC_GAMEMASTER, true, nullptr, "", playerCommandTable }
|
||||
};
|
||||
return commandTable;
|
||||
}
|
||||
|
||||
static bool HandlePlayerLearnCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
if (!*args)
|
||||
return false;
|
||||
|
||||
char* playerName = strtok((char*)args, " ");
|
||||
char* spellid = strtok(nullptr, " ");
|
||||
char const* all = strtok(nullptr, " ");
|
||||
Player* targetPlayer = FindPlayer(handler, playerName);
|
||||
if (!spellid || !targetPlayer)
|
||||
return false;
|
||||
|
||||
uint32 spell = handler->extractSpellIdFromLink(spellid);
|
||||
if (!spell)
|
||||
return false;
|
||||
|
||||
return Learn(handler, targetPlayer, spell, all);
|
||||
}
|
||||
|
||||
static bool HandlePlayerUnLearnCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
if (!*args)
|
||||
return false;
|
||||
|
||||
char* playerName = strtok((char*)args, " ");
|
||||
char* spellid = strtok(nullptr, " ");
|
||||
char const* all = strtok(nullptr, " ");
|
||||
Player* targetPlayer = FindPlayer(handler, playerName);
|
||||
if (!spellid || !targetPlayer)
|
||||
return false;
|
||||
|
||||
uint32 spell = handler->extractSpellIdFromLink(spellid);
|
||||
if (!spell)
|
||||
return false;
|
||||
|
||||
return UnLearn(handler, targetPlayer, spell, all);
|
||||
}
|
||||
|
||||
private:
|
||||
static Player* FindPlayer(ChatHandler* handler, char* playerName)
|
||||
{
|
||||
if (!playerName)
|
||||
return nullptr;
|
||||
|
||||
Player* targetPlayer;
|
||||
if (!handler->extractPlayerTarget(playerName, &targetPlayer))
|
||||
return nullptr;
|
||||
|
||||
if (!targetPlayer)
|
||||
{
|
||||
handler->SendSysMessage(LANG_PLAYER_NOT_FOUND);
|
||||
handler->SetSentErrorMessage(true);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return targetPlayer;
|
||||
}
|
||||
};
|
||||
|
||||
void AddSC_player_commandscript()
|
||||
{
|
||||
new player_commandscript();
|
||||
}
|
||||
Reference in New Issue
Block a user