[Plus EMU] Adding Commands

deathly

shit happens
May 3, 2015
36
6
Hello,
I'm attempting to add custom commands such as :hug to my localhost hotel (and later develop/add more). I'm looking for information on debugging/getting them to god dang work. Currently I have command_hug added to permission_commands. I have Hug.cs located in HabboHotel>Rooms>Chat>Commands>Users>Fun (Following code).
Code:
using System;
using Plus.HabboHotel.Rooms;
using Plus.HabboHotel.GameClients;
using Plus.Communication.Packets.Outgoing.Rooms.Chat;

namespace Plus.HabboHotel.Rooms.Chat.Commands.User.Fun
{
    class Hug : 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 (Params.Length == 1)
            {
                Session.SendWhisper("You must enter a username!");
                return;
            }

            GameClient TargetClient = PlusEnvironment.GetGame().GetClientManager().GetClientByUsername(Params[1]);
            if (TargetClient == null)
            {
                Session.SendWhisper("That user cannot be found, maybe they're offline or not in the room.");
                return;
            }

            RoomUser User = Room.GetRoomUserManager().GetRoomUserByHabbo(TargetClient.GetHabbo().Id);
            if (User == null)
            {
                Session.SendWhisper("The user cannot be found, maybe they're offline or not in the room.");
                return;
            }
            RoomUser ThisUser = Room.GetRoomUserManager().GetRoomUserByHabbo(Session.GetHabbo().Id);
            if (ThisUser == null)
                return;

            if (!((Math.Abs(User.X - ThisUser.X) >= 2 && (Math.Abs(User.Y - ThisUser.Y) >= 2))))
            {

                Room.SendMessage(new ChatComposer(ThisUser.VirtualId, "*Hugs " + TargetClient.GetHabbo().Username + "*", 0, User.LastBubble));
                User.ApplyEffect(9);
            }
            else
            {
                Session.SendWhisper("That user is too far away, try getting closer.");
                return;
            }
        }
    }
}

Now its not even registering the command, no error via whisper stating "this user is offline". I'm using Microsoft Visual Studios of course, this is my CommandHandler.cs
Code:
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;

using Plus.Utilities;
using Plus.HabboHotel.Rooms;
using Plus.HabboHotel.GameClients;

using Plus.HabboHotel.Rooms.Chat.Commands.User;
using Plus.HabboHotel.Rooms.Chat.Commands.User.Fun;
using Plus.HabboHotel.Rooms.Chat.Commands.Moderator;
using Plus.HabboHotel.Rooms.Chat.Commands.Moderator.Fun;
using Plus.HabboHotel.Rooms.Chat.Commands.Administrator;

using Plus.Communication.Packets.Outgoing.Rooms.Chat;
using Plus.Communication.Packets.Outgoing.Notifications;
using Plus.Database.Interfaces;
using Plus.HabboHotel.Rooms.Chat.Commands.Events;
using Plus.HabboHotel.Items.Wired;


namespace Plus.HabboHotel.Rooms.Chat.Commands
{
    public class CommandManager
    {
        /// <summary>
        /// Command Prefix only applies to custom commands.
        /// </summary>
        private string _prefix = ":";

        /// <summary>
        /// Commands registered for use.
        /// </summary>
        private readonly Dictionary<string, IChatCommand> _commands;

        /// <summary>
        /// The default initializer for the CommandManager
        /// </summary>
        public CommandManager(string Prefix)
        {
            this._prefix = Prefix;
            this._commands = new Dictionary<string, IChatCommand>();

            this.RegisterVIP();
            this.RegisterUser();
            this.RegisterEvents();
            this.RegisterModerator();
            this.RegisterAdministrator();
        }

        /// <summary>
        /// Request the text to parse and check for commands that need to be executed.
        /// </summary>
        /// <param name="Session">Session calling this method.</param>
        /// <param name="Message">The message to parse.</param>
        /// <returns>True if parsed or false if not.</returns>
        public bool Parse(GameClient Session, string Message)
        {
            if (Session == null || Session.GetHabbo() == null || Session.GetHabbo().CurrentRoom == null)
                return false;

            if (!Message.StartsWith(_prefix))
                return false;

            if (Message == _prefix + "commands")
            {
                StringBuilder List = new StringBuilder();
                List.Append("This is the list of commands you have available:\n");
                foreach (var CmdList in _commands.ToList())
                {
                    if (!string.IsNullOrEmpty(CmdList.Value.PermissionRequired))
                    {
                        if (!Session.GetHabbo().GetPermissions().HasCommand(CmdList.Value.PermissionRequired))
                            continue;
                    }

                    List.Append(":" + CmdList.Key + " " + CmdList.Value.Parameters + " - " + CmdList.Value.Description + "\n");
                }
                Session.SendMessage(new MOTDNotificationComposer(List.ToString()));
                return true;
            }

            Message = Message.Substring(1);
            string[] Split = Message.Split(' ');

            if (Split.Length == 0)
                return false;

            IChatCommand Cmd = null;
            if (_commands.TryGetValue(Split[0].ToLower(), out Cmd))
            {
                if (Session.GetHabbo().GetPermissions().HasRight("mod_tool"))
                    this.LogCommand(Session.GetHabbo().Id, Message, Session.GetHabbo().MachineId);

                if (!string.IsNullOrEmpty(Cmd.PermissionRequired))
                {
                    if (!Session.GetHabbo().GetPermissions().HasCommand(Cmd.PermissionRequired))
                        return false;
                }


                Session.GetHabbo().IChatCommand = Cmd;
                Session.GetHabbo().CurrentRoom.GetWired().TriggerEvent(WiredBoxType.TriggerUserSaysCommand, Session.GetHabbo(), this);

                Cmd.Execute(Session, Session.GetHabbo().CurrentRoom, Split);
                return true;
            }
            return false;
        }

        /// <summary>
        /// Registers the VIP set of commands.
        /// </summary>
        private void RegisterVIP()
        {
            this.Register("spull", new SuperPullCommand());
        }

        /// <summary>
        /// Registers the Events set of commands.
        /// </summary>
        private void RegisterEvents()
        {
            this.Register("eha", new EventAlertCommand());
            this.Register("eventalert", new EventAlertCommand());
        }

        /// <summary>
        /// Registers the default set of commands.
        /// </summary>
        private void RegisterUser()
        {
            this.Register("about", new InfoCommand());
            this.Register("pickall", new PickAllCommand());
            this.Register("ejectall", new EjectAllCommand());
            this.Register("lay", new LayCommand());
            this.Register("sit", new SitCommand());
            this.Register("hug", new Hug());
            this.Register("stand", new StandCommand());
            this.Register("mutepets", new MutePetsCommand());
            this.Register("mutebots", new MuteBotsCommand());

            this.Register("mimic", new MimicCommand());
            this.Register("dance", new DanceCommand());
            this.Register("push", new PushCommand());
            this.Register("pull", new PullCommand());
            this.Register("enable", new EnableCommand());
            this.Register("follow", new FollowCommand());
            this.Register("faceless", new FacelessCommand());
            this.Register("moonwalk", new MoonwalkCommand());

            this.Register("unload", new UnloadCommand());
            this.Register("regenmaps", new RegenMaps());
            this.Register("emptyitems", new EmptyItems());
            this.Register("setmax", new SetMaxCommand());
            this.Register("setspeed", new SetSpeedCommand());
            this.Register("disablediagonal", new DisableDiagonalCommand());
            this.Register("flagme", new FlagMeCommand());

            this.Register("stats", new StatsCommand());
            this.Register("kickpets", new KickPetsCommand());
            this.Register("kickbots", new KickBotsCommand());

            this.Register("room", new RoomCommand());
            this.Register("dnd", new DNDCommand());
            this.Register("disablegifts", new DisableGiftsCommand());
            this.Register("convertcredits", new ConvertCreditsCommand());
            this.Register("disablewhispers", new DisableWhispersCommand());
            this.Register("disablemimic", new DisableMimicCommand()); ;

            this.Register("pet", new PetCommand());
            this.Register("spush", new SuperPushCommand());
            this.Register("superpush", new SuperPushCommand());

        }

        /// <summary>
        /// Registers the moderator set of commands.
        /// </summary>
        private void RegisterModerator()
        {
            this.Register("ban", new BanCommand());
            this.Register("mip", new MIPCommand());
            this.Register("ipban", new IPBanCommand());

            this.Register("ui", new UserInfoCommand());
            this.Register("userinfo", new UserInfoCommand());
            this.Register("sa", new StaffAlertCommand());
            this.Register("roomunmute", new RoomUnmuteCommand());
            this.Register("roommute", new RoomMuteCommand());
            this.Register("roombadge", new RoomBadgeCommand());
            this.Register("roomalert", new RoomAlertCommand());
            this.Register("roomkick", new RoomKickCommand());
            this.Register("mute", new MuteCommand());
            this.Register("smute", new MuteCommand());
            this.Register("unmute", new UnmuteCommand());
            this.Register("massbadge", new MassBadgeCommand());
            this.Register("kick", new KickCommand());
            this.Register("skick", new KickCommand());
            this.Register("ha", new HotelAlertCommand());
            this.Register("hotelalert", new HotelAlertCommand());
            this.Register("hal", new HALCommand());
            this.Register("give", new GiveCommand());
            this.Register("givebadge", new GiveBadgeCommand());
            this.Register("dc", new DisconnectCommand());
            this.Register("kill", new DisconnectCommand());
            this.Register("disconnect", new DisconnectCommand());
            this.Register("alert", new AlertCommand());
            this.Register("tradeban", new TradeBanCommand());

            this.Register("teleport", new TeleportCommand());
            this.Register("summon", new SummonCommand());
            this.Register("override", new OverrideCommand());
            this.Register("massenable", new MassEnableCommand());
            this.Register("massdance", new MassDanceCommand());
            this.Register("freeze", new FreezeCommand());
            this.Register("unfreeze", new UnFreezeCommand());
            this.Register("fastwalk", new FastwalkCommand());
            this.Register("superfastwalk", new SuperFastwalkCommand());
            this.Register("coords", new CoordsCommand());
            this.Register("alleyesonme", new AllEyesOnMeCommand());
            this.Register("allaroundme", new AllAroundMeCommand());
            this.Register("forcesit", new ForceSitCommand());

            this.Register("ignorewhispers", new IgnoreWhispersCommand());
            this.Register("forced_effects", new DisableForcedFXCommand());

            this.Register("makesay", new MakeSayCommand());
            this.Register("flaguser", new FlagUserCommand());
        }

        /// <summary>
        /// Registers the administrator set of commands.
        /// </summary>
        private void RegisterAdministrator()
        {
            this.Register("bubble", new BubbleCommand());
            this.Register("update", new UpdateCommand());
            this.Register("deletegroup", new DeleteGroupCommand());
            this.Register("carry", new CarryCommand());
            this.Register("goto", new GOTOCommand());
        }

        /// <summary>
        /// Registers a Chat Command.
        /// </summary>
        /// <param name="CommandText">Text to type for this command.</param>
        /// <param name="Command">The command to execute.</param>
        public void Register(string CommandText, IChatCommand Command)
        {
            this._commands.Add(CommandText, Command);
        }

        public static string MergeParams(string[] Params, int Start)
        {
            var Merged = new StringBuilder();
            for (int i = Start; i < Params.Length; i++)
            {
                if (i > Start)
                    Merged.Append(" ");
                Merged.Append(Params[i]);
            }

            return Merged.ToString();
        }

        public void LogCommand(int UserId, string Data, string MachineId)
        {
            using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                dbClient.SetQuery("INSERT INTO `logs_client_staff` (`user_id`,`data_string`,`machine_id`, `timestamp`) VALUES (@UserId,@Data,@MachineId,@Timestamp)");
                dbClient.AddParameter("UserId", UserId);
                dbClient.AddParameter("Data", Data);
                dbClient.AddParameter("MachineId", MachineId);
                dbClient.AddParameter("Timestamp", PlusEnvironment.GetUnixTimestamp());
                dbClient.RunQuery();
            }
        }

        public bool TryGetCommand(string Command, out IChatCommand IChatCommand)
        {
            return this._commands.TryGetValue(Command, out IChatCommand);
        }
    }
}

I click save, reload cache, even reload EMU. Updated Permissions. Nothing is working. I'm not looking for someone to come and fix it for me, rather looking to learn and be able to go forth myself. Hopefully I can get help.
 

Joshhh

Member
Apr 13, 2016
323
172
Where it says: 'Class Hug : IChatCommand'
Code:
using System;
using Plus.HabboHotel.Rooms;
using Plus.HabboHotel.GameClients;
using Plus.Communication.Packets.Outgoing.Rooms.Chat;

namespace Plus.HabboHotel.Rooms.Chat.Commands.User.Fun
{
    class Hug : IChatCommand
    {
Change that to HugCommand.
Where it says "hug"
Code:
 this.Register("hug", new Hug());
Change that to HugCommand());

Make sure in the permissions table in the db, and add "command_hug".
 
Where it says: 'Class Hug : IChatCommand'
Code:
using System;
using Plus.HabboHotel.Rooms;
using Plus.HabboHotel.GameClients;
using Plus.Communication.Packets.Outgoing.Rooms.Chat;

namespace Plus.HabboHotel.Rooms.Chat.Commands.User.Fun
{
    class Hug : IChatCommand
    {
Change that to HugCommand.
Where it says "hug"
Code:
 this.Register("hug", new Hug());
Change that to HugCommand());

Make sure in the permissions table in the db, and add "command_hug".

Maybe Look at the .cs file, and try renaming that to "HugCommand.cs".
 

deathly

shit happens
May 3, 2015
36
6
Where it says: 'Class Hug : IChatCommand'
Code:
using System;
using Plus.HabboHotel.Rooms;
using Plus.HabboHotel.GameClients;
using Plus.Communication.Packets.Outgoing.Rooms.Chat;

namespace Plus.HabboHotel.Rooms.Chat.Commands.User.Fun
{
    class Hug : IChatCommand
    {
Change that to HugCommand.
Where it says "hug"
Code:
 this.Register("hug", new Hug());
Change that to HugCommand());

Make sure in the permissions table in the db, and add "command_hug".
 


Maybe Look at the .cs file, and try renaming that to "HugCommand.cs".
Will try this.
 

deathly

shit happens
May 3, 2015
36
6
Just rebuild or press f5 , if pressing f5 fails press fn+f5
Off topic: Sorry, I was away for a few days last minute.
On topic: I have tried both those things but neither seem to work.
Just rebuild the solution hats what i do. Build -> Rebuild solution
 
And add the command_hug into permissions_commands in the database
Have done this. As stated in the original post.
 

JayC

Always Learning
Aug 8, 2013
5,493
1,398
Code:
this.Register("hug", new hugCommand());
Code:
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;
using Plus.HabboHotel.GameClients;
using Plus.HabboHotel.Rooms;
using Plus.Communication.Packets.Outgoing.Rooms.Chat;
namespace Plus.HabboHotel.Rooms.Chat.Commands.User
{
    class hugCommand : IChatCommand
    {
        public string PermissionRequired
        {
            get { return "command_rp_hug"; }
        }

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

        public string Description
        {
            get { return "Give a virtual hug, to a friend!"; }
        }

        public void Execute(GameClients.GameClient Session, Rooms.Room Room, string[] Params)
        {
            if (Params.Length == 1)
            {
                Session.SendWhisper("Please enter a username.");
                return;
            }

            GameClient TargetClient = PlusEnvironment.GetGame().GetClientManager().GetClientByUsername(Params[1]);
            RoomUser TargetUser = Room.GetRoomUserManager().GetRoomUserByHabbo(TargetClient.GetHabbo().Id);
            RoomUser CurrentUser = Room.GetRoomUserManager().GetRoomUserByHabbo(Session.GetHabbo().Id);
            if (TargetUser == null)
                return;

            if (((Math.Abs(TargetUser.X - CurrentUser.X) >= 2) || (Math.Abs(TargetUser.Y - CurrentUser.Y) >= 2)))
            {
                Session.SendWhisper("Try to get closer to the user");
                return;
            }

            TargetClient.GetHabbo().Effects().ApplyEffect(9);
            Session.GetHabbo().Effects().ApplyEffect(9);

            Room.SendMessage(new ChatComposer(CurrentUser.VirtualId, "*Hugs " + TargetUser.GetUsername() + "*", 0, CurrentUser.LastBubble));
            Room.SendMessage(new ChatComposer(TargetUser.VirtualId, "*Hugs " + CurrentUser.GetUsername() + "*", 0, TargetUser.LastBubble));

        }
    }
}

Just coded this on my localhost for my hotel, It works.
 

deathly

shit happens
May 3, 2015
36
6
Code:
this.Register("hug", new hugCommand());
Code:
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;
using Plus.HabboHotel.GameClients;
using Plus.HabboHotel.Rooms;
using Plus.Communication.Packets.Outgoing.Rooms.Chat;
namespace Plus.HabboHotel.Rooms.Chat.Commands.User
{
    class hugCommand : IChatCommand
    {
        public string PermissionRequired
        {
            get { return "command_rp_hug"; }
        }

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

        public string Description
        {
            get { return "Give a virtual hug, to a friend!"; }
        }

        public void Execute(GameClients.GameClient Session, Rooms.Room Room, string[] Params)
        {
            if (Params.Length == 1)
            {
                Session.SendWhisper("Please enter a username.");
                return;
            }

            GameClient TargetClient = PlusEnvironment.GetGame().GetClientManager().GetClientByUsername(Params[1]);
            RoomUser TargetUser = Room.GetRoomUserManager().GetRoomUserByHabbo(TargetClient.GetHabbo().Id);
            RoomUser CurrentUser = Room.GetRoomUserManager().GetRoomUserByHabbo(Session.GetHabbo().Id);
            if (TargetUser == null)
                return;

            if (((Math.Abs(TargetUser.X - CurrentUser.X) >= 2) || (Math.Abs(TargetUser.Y - CurrentUser.Y) >= 2)))
            {
                Session.SendWhisper("Try to get closer to the user");
                return;
            }

            TargetClient.GetHabbo().Effects().ApplyEffect(9);
            Session.GetHabbo().Effects().ApplyEffect(9);

            Room.SendMessage(new ChatComposer(CurrentUser.VirtualId, "*Hugs " + TargetUser.GetUsername() + "*", 0, CurrentUser.LastBubble));
            Room.SendMessage(new ChatComposer(TargetUser.VirtualId, "*Hugs " + CurrentUser.GetUsername() + "*", 0, TargetUser.LastBubble));

        }
    }
}

Just coded this on my localhost for my hotel, It works.
I have no doubt it works, I'll give it a go. But I'm told you need to debug some files, and that is whats not working? Or do I just add the code, save the files in VS and restart EMU?
 

JayC

Always Learning
Aug 8, 2013
5,493
1,398
I have no doubt it works, I'll give it a go. But I'm told you need to debug some files, and that is whats not working? Or do I just add the code, save the files in VS and restart EMU?
So what I do when I am adding commands is,

You should see a 'Start' button at the top. You edit the code and then when you're done making changes you press 'Start'. That will debug your code! If you see any errors -> Changes were not saved. Fix the errors, and then press 'Start' again!
 

deathly

shit happens
May 3, 2015
36
6
So what I do when I am adding commands is,

You should see a 'Start' button at the top. You edit the code and then when you're done making changes you press 'Start'. That will debug your code! If you see any errors -> Changes were not saved. Fix the errors, and then press 'Start' again!
Thats very helpful thank you! But my start button is disabled, it doesn't allow me to click it and debug, nor does f5 or fn+f5.
 

SOUL

┼ ┼ ┼
Nov 10, 2015
224
45
An update: I'm still having the issue with debugging, I thought this would be more suitable screenshot? .
I'd reccomend resetting your visual studios , to do this you need to

  1. On the Tools menu, click Import and Export Settings.

  2. On the Welcome to the Import and Export Settings Wizard page, click Reset all settings and then click Next.

  3. If you want to save your current settings combination, click Yes, save my current settings, specify a file name, and then click Next.

    —or—

    If you want to delete your current settings combination, choose No, just reset settings, overwriting my current settings, and then clickNext. This option does not delete default settings, which will still be available the next time you use the wizard.

  4. In Which collection of settings do you want to reset to, select a settings collection from the list.

  5. Click Finish.

    The Reset Complete page alerts you to any problems encountered during the reset.
Once you've reset your VS attempt to debug it if that fails rebuild it , if all fails you most likely have the wrong file open make sure it's the project.
If it retains the same then re-install VS
 

Users who are viewing this thread

Top