SetState command

Status
Not open for further replies.

Brad

Well-Known Member
Jun 5, 2012
2,320
993
SetStateCommand.cs
PHP:
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;

using Plus.HabboHotel.Rooms;
using Plus.HabboHotel.Rooms.Games;
using Plus.HabboHotel.Rooms.Games.TEAMs;
using Plus.HabboHotel.Rooms.Notifications;

namespace Plus.HabboHotel.Rooms.Chat.Commands.User.Fun
{
    class SetStateCommand : IChatCommand
    {
        public string PermissionRequired
        {
            get { return "command_setst"; }
        }

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

        public string Description
        {
            get { return "Gives you the ability to set a default item state!"; }
        }

        public void Execute(GameClients.GameClient Session, Rooms.Room Room, string[] Params)
        {
            RoomUser user = Room.GetRoomUserManager().GetRoomUserByHabbo(Session.GetHabbo().Id);
            if (user == null)
            {
                NotificationManager.SimpleNotification(Session, "User not found.");
                return;
            }

            if (Params.Length == 1 && user.ItemState > 0 )
            {
                user.ItemState = 0;
                NotificationManager.Whisper(Session, "Your default item state has been reset.");
                return;
            }

            if (Params.Length == 1)
            {               
                NotificationManager.Whisper(Session, "You must include a number after :setst.");
                return;
            }

            if (!int.TryParse(Params[1], out int StateId))
            {
                NotificationManager.Whisper(Session, "Invalid input, please enter a number only.");
                return;
            }

            if (StateId < 1 || StateId > 8)
            {
                NotificationManager.Whisper(Session, "Please enter a state between 1-8.");
                return;
            }

          
            NotificationManager.Whisper(Session, "Your default item state has been set to " + Convert.ToString(StateId));
            user.ItemState = StateId;
        }
    }
}
Obviously replace NotifManager with how you handle notifs.

Then in RoomItemHandling.cs
add these inside SetFloorItem

Code:
 bool state = false;
 int istate = 0;

 if (user != null)
     state = user.ItemState > 0;
  if (state)
      istate = user.ItemState;
      
      
      replace
      
       if (newItem)
            {
                if (_floorItems.ContainsKey(Item.Id))
                {
                    if (Session != null)
                        Session.SendNotification(HabboEnvironment.GetLanguageManager().TryGetValue("room.item.already_placed"));

                    _room.GetGameMap().RemoveFromMap(Item);
                    return true;
                }
                if (state)
                    Item.ExtraData = Convert.ToString(istate);

                if (Item.IsFloorItem && !_floorItems.ContainsKey(Item.Id))
                    _floorItems.TryAdd(Item.Id, Item);
                else if (Item.IsWallItem && !_wallItems.ContainsKey(Item.Id))
                    _wallItems.TryAdd(Item.Id, Item);

                if (sendMessage)
                    _room.SendMessage(new ObjectAddComposer(Item, _room));
            }
 

Bran

habcrush.pw
Mar 13, 2017
1,789
1,608
SetStateCommand.cs
PHP:
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;

using Plus.HabboHotel.Rooms;
using Plus.HabboHotel.Rooms.Games;
using Plus.HabboHotel.Rooms.Games.TEAMs;
using Plus.HabboHotel.Rooms.Notifications;

namespace Plus.HabboHotel.Rooms.Chat.Commands.User.Fun
{
    class SetStateCommand : IChatCommand
    {
        public string PermissionRequired
        {
            get { return "command_setst"; }
        }

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

        public string Description
        {
            get { return "Gives you the ability to set a default item state!"; }
        }

        public void Execute(GameClients.GameClient Session, Rooms.Room Room, string[] Params)
        {
            RoomUser user = Room.GetRoomUserManager().GetRoomUserByHabbo(Session.GetHabbo().Id);
            if (user == null)
            {
                NotificationManager.SimpleNotification(Session, "User not found.");
                return;
            }

            if (Params.Length == 1 && user.ItemState > 0 )
            {
                user.ItemState = 0;
                NotificationManager.Whisper(Session, "Your default item state has been reset.");
                return;
            }

            if (Params.Length == 1)
            {              
                NotificationManager.Whisper(Session, "You must include a number after :setst.");
                return;
            }

            if (!int.TryParse(Params[1], out int StateId))
            {
                NotificationManager.Whisper(Session, "Invalid input, please enter a number only.");
                return;
            }

            if (StateId < 1 || StateId > 8)
            {
                NotificationManager.Whisper(Session, "Please enter a state between 1-8.");
                return;
            }

         
            NotificationManager.Whisper(Session, "Your default item state has been set to " + Convert.ToString(StateId));
            user.ItemState = StateId;
        }
    }
}
Obviously replace NotifManager with how you handle notifs.

Then in RoomItemHandling.cs
add these inside SetFloorItem

Code:
 bool state = false;
int istate = 0;

if (user != null)
     state = user.ItemState > 0;
  if (state)
      istate = user.ItemState;
     
     
      replace
     
       if (newItem)
            {
                if (_floorItems.ContainsKey(Item.Id))
                {
                    if (Session != null)
                        Session.SendNotification(HabboEnvironment.GetLanguageManager().TryGetValue("room.item.already_placed"));

                    _room.GetGameMap().RemoveFromMap(Item);
                    return true;
                }
                if (state)
                    Item.ExtraData = Convert.ToString(istate);

                if (Item.IsFloorItem && !_floorItems.ContainsKey(Item.Id))
                    _floorItems.TryAdd(Item.Id, Item);
                else if (Item.IsWallItem && !_wallItems.ContainsKey(Item.Id))
                    _wallItems.TryAdd(Item.Id, Item);

                if (sendMessage)
                    _room.SendMessage(new ObjectAddComposer(Item, _room));
            }
sent it to him already
 
Status
Not open for further replies.

Users who are viewing this thread

Top