[PlusEMU] Viewinventory Command Not Working Properly

Status
Not open for further replies.

treebeard

Member
Jan 16, 2018
317
173
Hello everyone,

For some reason when using the viewinventory command the first time the command is used it doesn't actually show the other users inventory. It requires the user to use the command a second time to be able to actually see the other persons inventory.

Here is my ViewInventoryCommand.cs

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

using Plus.HabboHotel.GameClients;
using Plus.Communication.Packets.Outgoing.Inventory.Furni;

namespace Plus.HabboHotel.Rooms.Chat.Commands.Administrator
{
    class ViewInventoryCommand : IChatCommand
    {
        public string PermissionRequired
        {
            get { return "command_viewinv"; }
        }

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

        public string Description
        {
            get { return ""; }
        }

        public void Execute(GameClient Session, Room Room, string[] Params)
        {
            if (Session.GetHabbo().ViewInventory)
            {
                Session.SendPacket(new FurniListComposer(Session.GetHabbo().GetInventoryComponent().GetFloorItems().ToList(), Session.GetHabbo().GetInventoryComponent().GetWallItems()));
                Session.GetHabbo().ViewInventory = false;
                Session.SendWhisper("Inventory reverted back to your own.");
                return;
            }

            if (Params.Length == 1)
            {
                Session.SendWhisper("Please enter the username of the user you'd like to check inventory.");
                return;
            }

            GameClient TargetClient = PlusEnvironment.GetGame().GetClientManager().GetClientByUsername(Params[1]);
            if (TargetClient == null)
            {
                Session.SendWhisper("An error occoured whilst finding that user, maybe they're not online.");
                return;
            }

            if (TargetClient.GetHabbo() == null)
            {
                Session.SendWhisper("An error occoured whilst finding that user, maybe they're not online.");
                return;
            }

            Session.SendPacket(new FurniListComposer(TargetClient.GetHabbo().GetInventoryComponent().GetFloorItems().ToList(), TargetClient.GetHabbo().GetInventoryComponent().GetWallItems(), true));
            Session.GetHabbo().ViewInventory = true;

            Session.SendWhisper("Next time you open your inventory you'll see " + TargetClient.GetHabbo().Username + "'s inventory.");
        }
    }
}

I appreciate your time, energy, and feedback!
 

treebeard

Member
Jan 16, 2018
317
173
FurniListComposerEvent.cs
Code:
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;

using Plus.HabboHotel.Items;
using Plus.HabboHotel.Groups;
using Plus.HabboHotel.Users;
using Plus.HabboHotel.Catalog.Utilities;

namespace Plus.Communication.Packets.Outgoing.Inventory.Furni
{
    class FurniListComposer : ServerPacket
    {
        public FurniListComposer(ICollection<Item> Items, int pages, int page)
            : base(ServerPacketHeader.FurniListMessageComposer)
        {
            base.WriteInteger(pages);//Pages
            base.WriteInteger(page);//Page?

            base.WriteInteger(Items.Count);
            foreach (Item Item in Items)
            {
                WriteItem(Item);
            }
        }

        public FurniListComposer(List<Item> Items, ICollection<Item> Walls, bool StaffCheck = false)
            : base(ServerPacketHeader.FurniListMessageComposer)
        {
            base.WriteInteger(1);
            base.WriteInteger(1);

            base.WriteInteger(Items.Count + Walls.Count);
            foreach (Item Item in Items.ToList())
                WriteItem(Item, StaffCheck);

            foreach (Item Item in Walls.ToList())
                WriteItem(Item, StaffCheck);
        }

        private void WriteItem(Item Item, bool StaffCheck)
        {
            base.WriteInteger(Item.Id);
            base.WriteString(Item.GetBaseItem().Type.ToString().ToUpper());
            base.WriteInteger(Item.Id);
            base.WriteInteger(Item.GetBaseItem().SpriteId);
            ItemBehaviourUtility.GenerateExtradata(Item, this);
            base.WriteBoolean(StaffCheck ? false : Item.GetBaseItem().AllowEcotronRecycle);
            base.WriteBoolean(StaffCheck ? false : Item.GetBaseItem().AllowTrade);
            base.WriteBoolean(Item.LimitedNo == 0 ? Item.GetBaseItem().AllowInventoryStack : false);
            base.WriteBoolean(StaffCheck ? false : ItemUtility.IsRare(Item));
            base.WriteInteger(-1);//Seconds to expiration.
            base.WriteBoolean(true);
            base.WriteInteger(-1);//Item RoomId

            if (!Item.IsWallItem)
            {
                base.WriteString(string.Empty);
                base.WriteInteger(0);
            }
        }
        private void WriteItem(Item Item)
        {
            base.WriteInteger(Item.Id);
            base.WriteString(Item.GetBaseItem().Type.ToString().ToUpper());
            base.WriteInteger(Item.Id);
            base.WriteInteger(Item.GetBaseItem().SpriteId);

            if (Item.LimitedNo > 0)
            {
                base.WriteInteger(1);
                base.WriteInteger(256);
                base.WriteString(Item.ExtraData);
                base.WriteInteger(Item.LimitedNo);
                base.WriteInteger(Item.LimitedTot);
            }
            else
                ItemBehaviourUtility.GenerateExtradata(Item, this);

            base.WriteBoolean(Item.GetBaseItem().AllowEcotronRecycle);
            base.WriteBoolean(Item.GetBaseItem().AllowTrade);
            base.WriteBoolean(Item.LimitedNo == 0 ? Item.GetBaseItem().AllowInventoryStack : false);
            base.WriteBoolean(ItemUtility.IsRare(Item));
            base.WriteInteger(-1);//Seconds to expiration.
            base.WriteBoolean(true);
            base.WriteInteger(-1);//Item RoomId

            if (!Item.IsWallItem)
            {
                base.WriteString(string.Empty);
                base.WriteInteger(0);
            }
        }
    }
}

Added to Habbo.cs
Code:
At Top
private bool _ViewInventory;

Habbo Method
this._ViewInventory = false;


public bool ViewInventory
        {
            get { return this._ViewInventory; }
            set { this._ViewInventory = value; }
        }

Added to PlaceObjectEvent.cs
Code:
if (Session.GetHabbo().ViewInventory)
            {
                Session.SendMessage(new RoomNotificationComposer("furni_placement_error", "message", "This item doesn't belong to you. Are you currently viewing someone elses inventory?"));
                return;
            }

Yeah I tried opening and closing. The first time I use the command it gives the message that it is successful but upon opening it is still my inventory. On the second time it works with no issues what-so-ever.
 

JayC

Always Learning
Aug 8, 2013
5,493
1,398
Code:
Session.SendPacket(new FurniListComposer(TargetClient.GetHabbo().GetInventoryComponent().GetFloorItems().ToList(), TargetClient.GetHabbo().GetInventoryComponent().GetWallItems(), true));
            Session.GetHabbo().ViewInventory = true;
Flip those 2 around.

Set ViewInventory to true BEFORE you call to update their inventory
 

treebeard

Member
Jan 16, 2018
317
173
Code:
Session.SendPacket(new FurniListComposer(TargetClient.GetHabbo().GetInventoryComponent().GetFloorItems().ToList(), TargetClient.GetHabbo().GetInventoryComponent().GetWallItems(), true));
            Session.GetHabbo().ViewInventory = true;
Flip those 2 around.

Set ViewInventory to true BEFORE you call to update their inventory
Damn.. Fairly obvious after you point it out. Thanks a ton!
 
Status
Not open for further replies.

Users who are viewing this thread

Top