How can I add cooldown / cost to a custom command (c++ script)?

[FONT=‘comic sans ms’][SIZE=18px]Hey guys. First of all, sorry if that’s in the wrong section and if it should be moved please do that, wasn’t sure where to put it since it is a code (c++ code).[/FONT][/SIZE]

[FONT=‘comic sans ms’][SIZE=18px]So, my problem is that I have a script that I have been editing and I ran into this sort of problem. I do not know how can I add a cooldown or a cost to a custom command I made.[/FONT][/SIZE]

[FONT=‘comic sans ms’][SIZE=18px]So far I did not encounter any sort of problems, but if you got any advices in addition to the part I need help in that’ll be most welcome![/FONT][/SIZE]

[FONT=‘comic sans ms’][SIZE=18px]The code: (the last session)[/FONT][/SIZE]

THIS SCRIPT IS NOT MINE, I ONLY EDITED IT!

#include “ScriptPCH.h”

#include “Chat.h”

uint32 auras[] = { 15366, 16609, 48162, 48074, 48170, 43223, 36880, 467, 69994, 33081, 24705, 26035, 48469 };

class buff_commandscript : public CommandScript

{

public:

buff_commandscript() : CommandScript("buff_commandscript") { }

ChatCommand* GetCommands() const

{

    static ChatCommand IngameCommandTable[] =

    {

{ “buff”, SEC_PLAYER, false, &HandleBuffCommand, “”, NULL },

{ “mall”, SEC_PLAYER, false, &HandleMallCommand, “”, NULL },

{ “vip”, SEC_VIP, false, &HandleVipCommand, “”, NULL },

{ “heal”, SEC_MODERATOR, false, &HandleHealCommand, “”, NULL },

{ “cd”, SEC_MODERATOR, false, &HandleCooldownCommand, “”, NULL },

        { NULL,             0,                  false, NULL,                              "", NULL }

    };

return IngameCommandTable;

}

static bool HandleBuffCommand(ChatHandler * handler, const char * args)

{

    Player * me = handler->GetSession()->GetPlayer();

me->RemoveAurasByType(SPELL_AURA_MOUNTED);

for(int i = 0; i < 11; i++)

me->AddAura(auras[i], me);

handler->PSendSysMessage(“|cffff6060You’re buffed now! Use it well to kill others!”); // available for everyone!

return true;

}

static bool HandleMallCommand(ChatHandler * handler, const char * args)

{

    Player * me = handler->GetSession()->GetPlayer();

me-> TeleportTo(1, 7337.972168f, -1541.647705f, 161.172668f, 5.585654f); // available for everyone!

handler->PSendSysMessage(“|cff00E5EEYou have been teleported to the mall!”);

return true;

}

static bool HandleVipCommand(ChatHandler * handler, const char * args)

{

    Player * me = handler->GetSession()->GetPlayer();

me-> TeleportTo(0, -7370.899414f, 1062.117920f, 131.407379f, 4.726033f);

handler->PSendSysMessage(“|cff00ff00 have been teleported to the VIP mall!”); // available for VIPs and above! (r2+)

return true;

}

static bool HandleHealCommand(ChatHandler * handler, const char * args)
{
Player * me = handler->GetSession()->GetPlayer();

me-> SetHealth(me->GetMaxHealth());
handler->PSendSysMessage(“|cffffcc00You’ve been healed!!”); // available for GMs only!
return true;
}

static bool HandleCooldownCommand(ChatHandler * handler, const char * args)
{
Player * me = handler->GetSession()->GetPlayer();

me-> RemoveAllSpellCooldown();
handler->PSendSysMessage(“|cffFF4500Your cooldowns are now clear!”); // available for GMs only!
return true;
}

};

void AddSC_Ingame_commandscript()
{
new buff_commandscript();
}
[FONT=‘comic sans ms’][SIZE=18px]The code can be found HERE (via Pastebin).[/FONT][/SIZE]

[FONT=‘comic sans ms’][SIZE=18px]OFFTOPIC:
If you guys can help me with how to install Manuel’s Passive Anticheat, that’ll be just great! I have no idea how can I do that, sadly.[/FONT][/SIZE]

[FONT=‘comic sans ms’][SIZE=18px]Thank you very much for reading it![/FONT][/SIZE]

— Canned message start —

This thread is not related to the official Trinity codebase and was moved to the Custom Code section.

Please read the stickies next time.

— Canned message end —

[FONT=‘comic sans ms’][SIZE=18px]Alright, thanks, but… can I get some help?[/FONT][/SIZE]

[FONT=‘comic sans ms’][SIZE=18px]Nevermind, I’ve found a better way to handle this. I’ve added a token required to make it work. I will share my script here.[/FONT][/SIZE]

[FONT=‘comic sans ms’][SIZE=18px]Note: THIS SCRIPT IS NOT MINE, I’VE ONLY EDITED IT!!![/FONT][/SIZE]

[CODE]
#include “ScriptPCH.h”
#include “Chat.h”

uint32 auras[] = { 15366, 16609, 48162, 48074, 48170, 43223, 36880, 467, 69994, 33081, 24705, 26035, 48469 };

class buff_commandscript : public CommandScript
{
public:
buff_commandscript() : CommandScript(“buff_commandscript”) { }

ChatCommand* GetCommands() const
{
static ChatCommand IngameCommandTable[] =
{
{ “buff”, SEC_PLAYER, false, &HandleBuffCommand, “”, NULL },
{ “mall”, SEC_PLAYER, false, &HandleMallCommand, “”, NULL },
{ “vip”, SEC_VIP, false, &HandleVipCommand, “”, NULL },
{ “heal”, SEC_PLAYER, false, &HandleHealCommand, “”, NULL },
{ “cd”, SEC_PLAYER, false, &HandleCooldownCommand, “”, NULL },
{ “lvl”, SEC_PLAYER, false, &HandleLevelCommand, “”, NULL },
{ NULL, 0, false, NULL, “”, NULL }
};
return IngameCommandTable;
}

static bool HandleBuffCommand(ChatHandler * handler, const char * args)
{
Player * me = handler->GetSession()->GetPlayer();

me->RemoveAurasByType(SPELL_AURA_MOUNTED);
for(int i = 0; i < 11; i++)
me->AddAura(auras[i], me);
handler->PSendSysMessage(“|cffff6060You’re buffed now! Use it well to kill others!”); // available for everyone!
return true;
}

static bool HandleMallCommand(ChatHandler * handler, const char * args) //MALL COMMAND
{
Player * me = handler->GetSession()->GetPlayer();

if(me->IsInCombat())
handler->PSendSysMessage(“|cff00ff00You’re in combat. When it’s gone you can use this command.”);
else
me-> TeleportTo(1, 7337.972168f, -1541.647705f, 161.172668f, 5.585654f), //if not in combat - teleport
me->SetHealth(18000), //set health when reaching the location
handler->PSendSysMessage(“|cff00E5EEYou have been teleported to the mall and your health has been set to 18000!!”); //send message

return true;
}

static bool HandleVipCommand(ChatHandler * handler, const char * args) //VIP COMMAND
{
Player * me = handler->GetSession()->GetPlayer();

if(me->IsInCombat())
handler->PSendSysMessage(“|cff00ff00You’re in combat. When it’s gone you can use this command.”);
else
me-> TeleportTo(0, -7370.899414f, 1062.117920f, 131.407379f, 4.726033f), //teleport
me->SetHealth(18000), //set hp to 18k
handler->PSendSysMessage(“|cff00ff00You have been teleported to the VIP mall!”);

return true;
}

static bool HandleHealCommand(ChatHandler * handler, const char * args) //HEAL COMMAND
{
Player * me = handler->GetSession()->GetPlayer();

if(me->HasItemCount(159787,1,true)) //require the Healing Coin
me->DestroyItemCount(159787,1,true,false), //Deleting the Healing Coin
me-> SetHealth(me->GetMaxHealth()), handler->PSendSysMessage(“|cffffcc00You’ve been healed!!”);
else
handler->PSendSysMessage(“|cffffcc00You need the Healing Coin first!”); //missing coin - fail
return true;
}

static bool HandleCooldownCommand(ChatHandler * handler, const char * args) //CD COMMAND
{
Player * me = handler->GetSession()->GetPlayer();

if(me->HasItemCount(159788,1,true)) //check if the player has the item
me->DestroyItemCount(159788,1,true,false), //delete the item
me-> RemoveAllSpellCooldown(), //remove CDs
handler->PSendSysMessage(“|cffFF4500Your cooldowns are now clear!!”); //remove item Cooldown Coin - for all
else
handler->PSendSysMessage(“|cffFF4500You need the Cooldown Coin first!”); //if he doesn’t have the Cooldown Coin - fail
return true;
}

static bool HandleLevelCommand(ChatHandler * handler, const char * args) //LEVEL COMMAND
{
Player * me = handler->GetSession()->GetPlayer();

if(me->HasItemCount(159786,1,true)) //require the Leveling Coin
me->DestroyItemCount(159786,1,true,false), //deleting the Leveling Coin
me->SetLevel(80), handler->PSendSysMessage(“|cffffcc00You’ve been leveled!!!”); //level 80
else
handler->PSendSysMessage(“|cffffcc00You need the Leveling Coin first!”); //missing coin - fail
return true;
}

};

void AddSC_Ingame_commandscript()
{
new buff_commandscript();
}[/CODE]