Hi
Is it possible to set up a limit on commands, so a player can only execute a command say 2 times per 10 seconds?
The reason I want this is because I use the world chat script from here.
Here’s the code for convenience:
#include “ScriptPCH.h”
#include “Chat.h”
std::string GetNameLink(Player* player)
{
std::string name = player->GetName();
std::string color;
switch(player->getClass())
{
case CLASS_DEATH_KNIGHT:
color = “|cffC41F3B”;
break;
case CLASS_DRUID:
color = “|cffFF7D0A”;
break;
case CLASS_HUNTER:
color = “|cffABD473”;
break;
case CLASS_MAGE:
color = “|cff69CCF0”;
break;
case CLASS_PALADIN:
color = “|cffF58CBA”;
break;
case CLASS_PRIEST:
color = “|cffFFFFFF”;
break;
case CLASS_ROGUE:
color = “|cffFFF569”;
break;
case CLASS_SHAMAN:
color = “|cff0070DE”;
break;
case CLASS_WARLOCK:
color = “|cff9482C9”;
break;
case CLASS_WARRIOR:
color = “|cffC79C6E”;
break;
}
return “|Hplayer:”+name+“|h|cffFFFFFF[”+color+name+“|cffFFFFFF]:|h|r”;
}
class cs_world_chat : public CommandScript
{
public:
cs_world_chat() : CommandScript(“cs_world_chat”){}
ChatCommand * GetCommands() const
{
static ChatCommand WorldChatCommandTable[] =
{
{"global", SEC_PLAYER, true, &HandleWorldChatCommand, "", NULL},
{"world", SEC_PLAYER, true, &HandleWorldChatCommand, "", NULL},
{"g", SEC_PLAYER, true, &HandleWorldChatCommand, "", NULL},
{"w", SEC_PLAYER, true, &HandleWorldChatCommand, "", NULL},
{NULL, 0, false, NULL, "", NULL}
};
return WorldChatCommandTable;
}
static bool HandleWorldChatCommand(ChatHandler * handler, const char * args)
{
if (!handler->GetSession()->GetPlayer()->CanSpeak())
return false;
std::string temp = args;
if (!args || temp.find_first_not_of(' ') == std::string::npos)
return false;
std::string msg = "";
Player * player = handler->GetSession()->GetPlayer();
switch(player->GetSession()->GetSecurity())
{
// Player
case SEC_PLAYER:
if (player->GetTeam() == ALLIANCE)
{
msg += "|cff0000ff[A] ";
msg += GetNameLink(player);
msg += " |cffFFFFFF";
}
else
{
msg += "|cffff0000[H] ";
msg += GetNameLink(player);
msg += " |cffFFFFFF";
}
break;
// Moderator/trial
case SEC_MODERATOR:
msg += "|cffff8a00[Mod] ";
msg += GetNameLink(player);
msg += " |cffFFFFFF";
break;
// GM
case SEC_GAMEMASTER:
msg += "|cff00ffff[GM] ";
msg += GetNameLink(player);
msg += " |cffFFFFFF";
break;
// Admin
case SEC_ADMINISTRATOR:
msg += "|cfffa9900[Admin] ";
msg += GetNameLink(player);
msg += " |cffFFFFFF";
break;
// Console
case SEC_CONSOLE:
msg += "|cfffa9900[Console] ";
msg += GetNameLink(player);
msg += " |cffFFFFFF";
break;
}
msg += args;
sWorld->SendServerMessage(SERVER_MSG_STRING, msg.c_str(), 0);
return true;
}
};
void AddSC_cs_world_chat()
{
new cs_world_chat();
}
Thanks in advance.
- qie314