PlusEmu RCON commands

MayoMayn

BestDev
Oct 18, 2016
1,423
683
Basically I want a command that gives an user an item of x amount.
Currently I can only insert it through the cms and reload all inventories through rcon, which isn't what I want.

As I haven't gotten into the source code of Plus Emulator or the weird structure it would take too long to for me figure out.
This is as far as I've gotten:

@Sledmore wrote something about using ItemFactory instead of
Code:
 client.GetHabbo().GetInventoryComponent().AddNewItem(0, itemId)

Here's the code snippet for now:
PHP:
using System;
using Plus.HabboHotel.GameClients;
using Plus.Database.Interfaces;
//using Plus.HabboHotel.Users.Inventory

namespace Plus.Communication.RCON.Commands.User
{
    class GiveUserItemCommand : IRCONCommand
    {

        public string Description
        {
            get { return "This command is used to give a user a specific item."; }
        }

        public string Parameters
        {
            get { return "%userId% %itemId% %amount%"; }
        }

        public bool TryExecute(string[] parameters)
        {
            int userId = 0;
            if (!int.TryParse(parameters[0].ToString(), out userId))
                return false;

            GameClient client = PlusEnvironment.GetGame().GetClientManager().GetClientByUserID(userId);
            if (client == null || client.GetHabbo() == null)
                return false;

            int itemId = 0;
            if (!int.TryParse(parameters[1].ToString(), out itemId))
                return false;

            int amount = 0;
            if (!int.TryParse(parameters[2].ToString(), out amount))
                amount = 1;

            while (amount > 0) {
                client.GetHabbo().GetInventoryComponent().AddNewItem(0, itemId)

                amount--;
            }

            return true;
        }

    }

}
 
Last edited:

Sledmore

Chaturbate Livestreamer
Staff member
FindRetros Moderator
Jul 24, 2010
5,194
3,901
This should do it:

PHP:
using System.Collections.Generic;

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

namespace Plus.Communication.RCON.Commands.User
{
    class GiveUserItemCommand : IRCONCommand
    {
        public string Description
        {
            get { return "This command is used to give a user a specific item."; }
        }

        public string Parameters
        {
            get { return "%userId% %itemId% %amount%"; }
        }

        public bool TryExecute(string[] parameters)
        {
            int userId = 0;
            if (!int.TryParse(parameters[0].ToString(), out userId))
                return false;

            GameClient client = PlusEnvironment.GetGame().GetClientManager().GetClientByUserID(userId);
            if (client == null || client.GetHabbo() == null)
                return false;

            int itemId = 0;
            if (!int.TryParse(parameters[1].ToString(), out itemId))
                return false;

            int amount = 0;
            if (!int.TryParse(parameters[2].ToString(), out amount))
                amount = 1;

            ItemData item = null;
            if (!PlusEnvironment.GetGame().GetItemManager().GetItem(itemId, out item))
                return false;

            List<Item> items = ItemFactory.CreateMultipleItems(item, client.GetHabbo(), "", amount);

            if (items != null)
            {
                foreach (Item i in items)
                {
                    if (client.GetHabbo().GetInventoryComponent().TryAddItem(i))
                    {
                        client.SendPacket(new FurniListNotificationComposer(i.Id, 1));
                    }
                }
            }

            return true;
        }
    }
}
 

Users who are viewing this thread

Top