Emulator Command Delay Issue

Supermario

Member
Jan 5, 2016
99
0
Hi,

I saw Sage tutorial about emulator command delays ( ) but I have some issues. The delay works, but it breaks my cool down code, and I have no idea why. Here is my HugCommand.cs code.

Code:
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;

using Plus.HabboHotel.Rooms;
using Plus.HabboHotel.GameClients;
using Plus.Communication.Packets.Outgoing.Rooms.Chat;
using System.Threading.Tasks;

namespace Plus.HabboHotel.Rooms.Chat.Commands.User.Fun
{
    class HugCommand : IChatCommand
    {
        public string PermissionRequired
        {
            get { return "command_hug"; }
        }
        public string Parameters
        {
            get { return "%username%"; }
        }
        public string Description
        {
            get { return "Hug another user."; }
        }
        public void Execute(GameClients.GameClient Session, Rooms.Room Room, string[] Params)
        {
            if (!Room.rpEnabled)
            {
                Session.SendWhisper("Oops, it appears that the room owner has disabled the ability to use rp commands in this room.");
                return;
            }
            if (Params.Length == 1)
            {
                Session.SendWhisper("Please enter the username of the person you want to Hug.");
                return;
            }
            GameClient TargetClient = PlusEnvironment.GetGame().GetClientManager().GetClientByUsername(Params[1]);
            if (TargetClient == null)
            {
                Session.SendWhisper("The user was not found in the room, maybe they're offline.");
                return;
            }
            RoomUser TargetUser = Room.GetRoomUserManager().GetRoomUserByHabbo(TargetClient.GetHabbo().Id);
            if (TargetUser == null)
            {
                Session.SendWhisper("An error occured while finding that user, maybe they're offline or not in this room.");
            }
            if (TargetClient.GetHabbo().Username == Session.GetHabbo().Username)
            {
                Session.SendWhisper("You cannot Hug yourself!");
                return;
            }

            RoomUser ThisUser = Room.GetRoomUserManager().GetRoomUserByHabbo(Session.GetHabbo().Id);
            if (ThisUser == null)
                return;

            if (!((Math.Abs(TargetUser.X - ThisUser.X) >= 2) || (Math.Abs(TargetUser.Y - ThisUser.Y) >= 2)))
            {
                TimeSpan Cooldown = DateTime.Now - Session.GetHabbo().HugCoolDown;
                if (Cooldown.TotalSeconds >= 30)
                {
                    Task.Run(async delegate
                    {
                        Room.SendMessage(new ShoutComposer(ThisUser.VirtualId, "| *Hugs " + Params[1] + "* |", 0, ThisUser.LastBubble = 16));
                        await Task.Delay(1000);
                        Room.SendMessage(new ShoutComposer(TargetUser.VirtualId, "| *Is hugged and feeling loved* |", 0, ThisUser.LastBubble = 16));
                        await Task.Delay(1000);
                        TargetUser.ApplyEffect(168);
                        await Task.Delay(4000);
                        ThisUser.ApplyEffect(0);
                        ThisUser.UpdateNeeded = true;
                        TargetUser.ApplyEffect(0);
                        TargetUser.UpdateNeeded = true;
                        Session.GetHabbo().HugCoolDown = DateTime.Now;
                    });
                }
                else
                {
                    int num = (int)(30 - Cooldown.TotalSeconds);
                    Session.SendWhisper("Cooldown Mode: " + num + " seconds left until you can do that!", 0);
                    return;
                }
            }
            else
            {
                Session.SendWhisper("You're too far away! please try getting closer.");
                return;
            }
        }
    }
}
 
bump
 

Users who are viewing this thread

Top