PlusEmulator Command Cooldowns

JynX

Posting Freak
Feb 6, 2016
710
438
Hello Devbest,
Recently I've added commands to PlusEMU some of my own origin and some of which have been released here and on the rival forum, but throughout the fast few days I've realized most of them are "spammable" and after a while get annoying, and I would like to add a cool down to it to where a user can only do that command every 'x' amount of seconds to prevent this. How would I go about doing this?

Following People are tagged because I thought they'd know
@Sledmore
@kingsh4wn
@JayCustom

Thanks in advance!
 

JayC

Always Learning
Aug 8, 2013
5,493
1,398
IN HABBO CLASS:
Code:
private nextCommand = 0;

public long NextCommand
{
            get { return this.nextCommand; }
            set { this.nextCommand = value; }
}

Then in the command class:
Code:
if (Session.GetHabbo().NextCommand != 0)
{
          if (Session.GetHabbo().NextCommand > PlusEnvironment.Now())
       {
         Session.SendWhisper("Command Flood Protection [2 Second Cooldown]", 3);
         return;
      }
}
Session.GetHabbo().NextCommand = PlusEnvironment.Now() + 2000;

2000 = milliseconds, 1000 = 1 second.
 

Velaski

winner
Aug 4, 2015
562
165
I remember a good friend Jordan posting this somewhere. Havent got visual studio rn, but I'll have a crack.

In RoomUser.cs, add:
Code:
public static DateTime CommandExecuted;

In you're commands:

Code:
TimeSpan Cooldown = DateTime.Now - RoomUser.CommandExecuted;
                if (Cooldown.Seconds >= 5)
                {
                   //PUT EVERYTHING UNDER public void(Execute idk) Here
                  RoomUser.CommandExecuted = DateTime.Now;
                }

                else
                {
                    int num = checked(5 - Cooldown.Seconds);
                    Session.SendWhisper("Cooldown! You must wait 5 seconds until you can do that!");
           
                }
            }

Where it says "//PUT EVERYTHING UNDER public void(Execute idk) Here" You'll see under your public void Execute in your command.
This :
Code:
public void Execute(GameClients.GameClient Session, Rooms.Room Room, string[] Params)
        {
Put it here.
}


If you still don't understand, heres an example of a simple rko command
Code:
class RKOCommand : IChatCommand
    {
        public string PermissionRequired
        {
            get { return "command_rko"; }
        }

        public string Parameters
        {
            get { return "%target%"; }
        }

        public string Description
        {
            get { return "RKO a user."; }
        }

        public void Execute(GameClients.GameClient Session, Rooms.Room Room, string[] Params)
        {


TimeSpan Cooldown = DateTime.Now - RoomUser.CommandExecuted;
                if (Cooldown.Seconds >= 5)
                {


            if (Params.Length == 1)
            {
                Session.SendWhisper("Please enter a username");
                return;
            }
            GameClient TargetClient = PlusEnvironment.GetGame().GetClientManager().GetClientByUsername(Params[1]);

            RoomUser User = Room.GetRoomUserManager().GetRoomUserByHabbo(TargetClient.GetHabbo().Id);

            RoomUser ThisUser = Room.GetRoomUserManager().GetRoomUserByHabbo(Session.GetHabbo().Id);
            if (User == null)
{
Session.SendWhisper("Error in command execution");
                return;
}
            if (TargetClient == null)
             
{
Session.SendWhisper("Target not found");
                return;
}
            if (TargetClient.GetHabbo().CurrentRoomId == Session.GetHabbo().CurrentRoomId && (Math.Abs(ThisUser.X - User.X) < 3 && Math.Abs(ThisUser.Y - User.Y) < 3))
            {
                Room.SendMessage(new ChatComposer(ThisUser.VirtualId, "*RKO OUTTA NOWHERE ON " + TargetClient.GetHabbo().Username + "*", 0, User.LastBubble));
                Room.SendMessage(new ChatComposer(User.VirtualId, "*feels the viper effect well*", 0, User.LastBubble));
            }

            if (!User.Statusses.ContainsKey("sit"))
            {
                if ((User.RotBody % 2) == 0)
                {
                    if (User == null)
                        return;

                    try
                    {
                        User.Statusses.Add("sit", "1.0");
                        User.Z -= 0.35;
                        User.isSitting = true;
                        User.UpdateNeeded = true;
                    }
                    catch { }
                }
                else
                {
                    User.RotBody--;
                    User.Statusses.Add("sit", "1.0");
                    User.Z -= 0.35;
                    User.isSitting = true;
                    User.UpdateNeeded = true;
                }
            }

 RoomUser.CommandExecuted = DateTime.Now;
                }

                else
                {
                    int num = checked(5 - Cooldown.Seconds);
                    Session.SendWhisper("Cooldown! You must wait 5 seconds until you can do that!");
             
                }
            }

        }
        }
}

@Altercationz thanks for this.
 

JayC

Always Learning
Aug 8, 2013
5,493
1,398
I remember a good friend Jordan posting this somewhere. Havent got visual studio rn, but I'll have a crack.

In RoomUser.cs, add:
Code:
public static DateTime CommandExecuted;

In you're commands:

Code:
TimeSpan Cooldown = DateTime.Now - RoomUser.CommandExecuted;
                if (Cooldown.Seconds >= 5)
                {
                   //PUT EVERYTHING UNDER public void(Execute idk) Here
                  RoomUser.CommandExecuted = DateTime.Now;
                }

                else
                {
                    int num = checked(5 - Cooldown.Seconds);
                    Session.SendWhisper("Cooldown! You must wait 5 seconds until you can do that!");
          
                }
            }

Where it says "//PUT EVERYTHING UNDER public void(Execute idk) Here" You'll see under your public void Execute in your command.
This :
Code:
public void Execute(GameClients.GameClient Session, Rooms.Room Room, string[] Params)
        {
Put it here.
}


If you still don't understand, heres an example of a simple rko command
Code:
class RKOCommand : IChatCommand
    {
        public string PermissionRequired
        {
            get { return "command_rko"; }
        }

        public string Parameters
        {
            get { return "%target%"; }
        }

        public string Description
        {
            get { return "RKO a user."; }
        }

        public void Execute(GameClients.GameClient Session, Rooms.Room Room, string[] Params)
        {


TimeSpan Cooldown = DateTime.Now - RoomUser.CommandExecuted;
                if (Cooldown.Seconds >= 5)
                {


            if (Params.Length == 1)
            {
                Session.SendWhisper("Please enter a username");
                return;
            }
            GameClient TargetClient = PlusEnvironment.GetGame().GetClientManager().GetClientByUsername(Params[1]);

            RoomUser User = Room.GetRoomUserManager().GetRoomUserByHabbo(TargetClient.GetHabbo().Id);

            RoomUser ThisUser = Room.GetRoomUserManager().GetRoomUserByHabbo(Session.GetHabbo().Id);
            if (User == null)
{
Session.SendWhisper("Error in command execution");
                return;
}
            if (TargetClient == null)
            
{
Session.SendWhisper("Target not found");
                return;
}
            if (TargetClient.GetHabbo().CurrentRoomId == Session.GetHabbo().CurrentRoomId && (Math.Abs(ThisUser.X - User.X) < 3 && Math.Abs(ThisUser.Y - User.Y) < 3))
            {
                Room.SendMessage(new ChatComposer(ThisUser.VirtualId, "*RKO OUTTA NOWHERE ON " + TargetClient.GetHabbo().Username + "*", 0, User.LastBubble));
                Room.SendMessage(new ChatComposer(User.VirtualId, "*feels the viper effect well*", 0, User.LastBubble));
            }

            if (!User.Statusses.ContainsKey("sit"))
            {
                if ((User.RotBody % 2) == 0)
                {
                    if (User == null)
                        return;

                    try
                    {
                        User.Statusses.Add("sit", "1.0");
                        User.Z -= 0.35;
                        User.isSitting = true;
                        User.UpdateNeeded = true;
                    }
                    catch { }
                }
                else
                {
                    User.RotBody--;
                    User.Statusses.Add("sit", "1.0");
                    User.Z -= 0.35;
                    User.isSitting = true;
                    User.UpdateNeeded = true;
                }
            }

 RoomUser.CommandExecuted = DateTime.Now;
                }

                else
                {
                    int num = checked(5 - Cooldown.Seconds);
                    Session.SendWhisper("Cooldown! You must wait 5 seconds until you can do that!");
            
                }
            }

        }
        }
}

@Altercationz thanks for this.
Code:
int num = checked(5 - Cooldown.Seconds);
This number does absolutely nothing. You're declaring an int everytime this command is executed then doing nothing with it.
Code:
Session.SendWhisper("Cooldown! You must wait 5 seconds until you can do that!");
You could show them the timer since you have Cooldown.Seconds (I believe this is what NUM was supposed to be used for...)
Code:
Session.SendWhisper("Cooldown! You must wait " + num + " seconds until you can do that!");
 
May 1, 2015
467
152
Code:
int num = checked(5 - Cooldown.Seconds);
This number does absolutely nothing. You're declaring an int everytime this command is executed then doing nothing with it.
Code:
Session.SendWhisper("Cooldown! You must wait 5 seconds until you can do that!");
You could show them the timer since you have Cooldown.Seconds (I believe this is what NUM was supposed to be used for...)
Code:
Session.SendWhisper("Cooldown! You must wait " + num + " seconds until you can do that!");
That is what i used "num" for when making the cooldown, guess he just forgot to put it.
 

Seriosk

Programmer;
Oct 29, 2016
256
105
I know other people have already answered this but I guess I'll post an answer too incase anyone else wants to know another way of doing this... haven't got VS right now so I'll just have to write it here.

In Habbo.cs:
Code:
public DateTime CommandExecutedLast
{
    get; private set;
}
At the start of the command:
Code:
TimeSpan lastExecuted = Session.GetHabbo().CommandExecutedLast - DateTime.Now;
if (lastExecuted.Seconds < 5)
{
    Session.SendWhispher("You're cooling down, please wait! [" + lastExecuted.Seconds + "/5]");
    return;
}

In your command file (at the very end)
Code:
Session.GetHabbo().CommandExecutedLast = DateTime.Now;
 

Users who are viewing this thread

Top