Code:
#include "StdAfx.h"
#include "Setup.h"
#include <string>
/*
###############################
#####Created by Mager1794######
######Donator Commands#########
###############################
Command List
#AddItem <ItemId>
#Announce <Message>
#Teleport <PlayerName>
#Port <mapid> <x> <y> <z>
*/
bool FindCommand(string Message, string Command)
{
int i = Message.find(Command);
if(i != string::npos)
{
return true;
}else{
return false;
}
}
bool IsDonator(Player * pPlayer)
{
QueryResult * qres = CharacterDatabase.Query("SELECT * FROM `accounts` WHERE `acct` = '%s' and `gm` = 'Donator';", pPlayer->GetSession()->GetAccountId());
if(!qres == NULL)
return true;
else
return false;
}
bool CommandCheck(const char * Message)
{
if(Message[0]=='#')
return true;
else
return false;
}
void DonorAnnounceCommand(const char* Message, Player * pPlayer)
{
string commandname = "#Announce";
string command = Message;
if(!FindCommand(command, commandname))
return;
string Variable = command.replace(command.find(command),commandname.size()+1,"");
const char * announce = (const char *)Variable.c_str();
if(announce == NULL)
return;
char * msg;
sprintf(msg, "[Donator]%s: %s", pPlayer->GetName(), announce);
sWorld.SendWorldText(msg);
}
void DonorPort(const char* Message, Player * pPlayer)
{
string commandname = "#Port";
string command = Message;
if(!FindCommand(command, commandname))
return;
string Variable = command.replace(command.find(command),commandname.size()+1,"");
const char * args = (const char *)Variable.c_str();
float x, y, z;
uint32 mapid;
if(sscanf(args, "%u %f %f %f", (unsigned int*)&mapid, &x, &y, &z) != 4)
return;
if(x >= _maxX || x <= _minX || y <= _minY || y >= _maxY)
return;
LocationVector vec(x, y, z);
pPlayer->SafeTeleport(mapid, 0, vec);
}
void TeleportToFriendCommand(const char* Message, Player * pPlayer)
{
string commandname = "#Teleport";
string command = Message;
if(!FindCommand(command, commandname))
return;
string Variable = command.replace(command.find(command),commandname.size()+1,"");
const char * charname = (const char *)Variable.c_str();
Player * Target = objmgr.GetPlayer(charname, false);
if(!Target)
{
pPlayer->BroadcastMessage("Player doesn't exist");
return;
}
if(pPlayer->GetTeam() != Target->GetTeam())
{
pPlayer->BroadcastMessage("That player is not the same faction as you");
return;
}
if(Target->GetSession()->HasGMPermissions())
{
pPlayer->BroadcastMessage("You cannot teleport to a GM");
return;
}
if(Target->GetName() == pPlayer->GetName())
{
pPlayer->BroadcastMessage("You cannot teleport to yourself");
return;
}
float nx = pPlayer->GetPositionX();
float ny = pPlayer->GetPositionY();
float nz = pPlayer->GetPositionZ();
Target->BroadcastMessage("%s is teleporting to you...", pPlayer->GetName());
pPlayer->EventTeleport(Target->GetMapId(), Target->GetPositionX(), Target->GetPositionY(), Target->GetPositionZ());
if(nx == pPlayer->GetPositionX()|| ny == pPlayer->GetPositionY()|| nz == pPlayer->GetPositionZ())
{
pPlayer->BroadcastMessage("Teleportation failed...");
}
}
void AddItemCommand(const char * Message, Player * pPlayer)
{
string commandname = "#AddItem";
string command = Message;
if(!FindCommand(command, commandname))
return;
string Variable = command.replace(command.find(command),commandname.size()+1,"");
const char * strid = (const char *)Variable.c_str();
uint32 id = strlen(strid);
pPlayer->GetItemInterface()->AddItemToFreeSlot(objmgr.CreateItem(id, pPlayer));
}
void DonatorCommands(Player * pPlayer, uint32 Type, uint32 Lang, const char * Message, const char * Misc)
{
if(CommandCheck(Message))
{
if(IsDonator(pPlayer) || pPlayer->GetSession()->HasGMPermissions())
{
if(Config.MainConfig.GetBoolDefault("DonatorCommands", "AddItem", true))
{
AddItemCommand(Message, pPlayer);
}
if(Config.MainConfig.GetBoolDefault("DonatorCommands", "Tele2Friend", true))
{
TeleportToFriendCommand(Message, pPlayer);
}
if(Config.MainConfig.GetBoolDefault("DonatorCommands", "Announce", true))
{
DonorAnnounceCommand(Message,pPlayer);
}
if(Config.MainConfig.GetBoolDefault("DonatorCommands", "Port", true))
{
DonorPort(Message,pPlayer);
}
}
else
{
pPlayer->BroadcastMessage("You must be a donator to use this command");
}
}
}
void SetupDonatorCommands(ScriptMgr * mgr)
{
mgr->register_hook(SERVER_HOOK_EVENT_ON_CHAT, &DonatorCommands);
}
Config File