Convert Diamonds

Joe

Well-Known Member
Jun 10, 2012
4,172
1,955
Hey,

I'm looking for a convert diamonds command, it's probably very straight forward but I don't really have any experience with C#.

Here's the ConvertCreditsCommand
Code:
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;
using System.Data;

using Plus.HabboHotel.Items;
using Plus.Communication.Packets.Outgoing.Inventory.Purse;
using Plus.Database.Interfaces;

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

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

        public string Description
        {
            get { return "Convert your exchangeable furniture into actual credits."; }
        }

        public void Execute(GameClients.GameClient Session, Rooms.Room Room, string[] Params)
        {
            int TotalValue = 0;

            try
            {
                DataTable Table = null;           
                using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
                {
                    dbClient.SetQuery("SELECT `id` FROM `items` WHERE `user_id` = '" + Session.GetHabbo().Id + "' AND (`room_id`=  '0' OR `room_id` = '')");
                    Table = dbClient.getTable();
                }

                if (Table == null)
                {
                    Session.SendWhisper("You currently have no items in your inventory!");
                    return;
                }

                foreach (DataRow Row in Table.Rows)
                {
                    Item Item = Session.GetHabbo().GetInventoryComponent().GetItem(Convert.ToInt32(Row[0]));
                    if (Item == null)
                        continue;

                    if (!Item.GetBaseItem().ItemName.StartsWith("CF_") && !Item.GetBaseItem().ItemName.StartsWith("CFC_"))
                        continue;

                    if (Item.RoomId > 0)
                        continue;

                    string[] Split = Item.GetBaseItem().ItemName.Split('_');
                    int Value = int.Parse(Split[1]);
                    
                    using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
                    {
                        dbClient.RunQuery("DELETE FROM `items` WHERE `id` = '" + Item.Id + "' LIMIT 1");
                    }

                    Session.GetHabbo().GetInventoryComponent().RemoveItem(Item.Id);

                    TotalValue += Value;

                    if (Value > 0)
                    {
                        Session.GetHabbo().Credits += Value;
                        Session.SendMessage(new CreditBalanceComposer(Session.GetHabbo().Credits));
                    }
                }

                if (TotalValue > 0)
                    Session.SendNotification("All credits have successfully been converted!\r\r(Total value: " + TotalValue + " credits!");
                else
                    Session.SendNotification("It appears you don't have any exchangeable items!");
            }
            catch
            {
                Session.SendNotification("Oops, an error occoured whilst converting your credits!");
            }
        }
    }
}
 

Kodys

lmao
Oct 24, 2016
36
17
I didn't look I just posted mine before you get laired. atleast i'm attempting to help you spacko
 
@JMG pm me your skype i'll help further more on there.
Your post was the most pointless and retarded shit you've posted, yet.. you copied and pasted what he wrote and posted it back and claimed you was helping.. k

@JMG I've not tested this although I'm sure this should work, it also needs a new permission command_convert_diamonds but if you want use command_convert_credits tbh.
Code:
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;
using System.Data;

using Plus.HabboHotel.Items;
using Plus.Communication.Packets.Outgoing.Inventory.Purse;
using Plus.Database.Interfaces;

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

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

        public string Description
        {
            get { return "Convert your exchangeable furniture into actual diamonds."; }
        }

        public void Execute(GameClients.GameClient Session, Rooms.Room Room, string[] Params)
        {
            int TotalValue = 0;

            try
            {
                DataTable Table = null;
                using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
                {
                    dbClient.SetQuery("SELECT `id` FROM `items` WHERE `user_id` = '" + Session.GetHabbo().Id + "' AND (`room_id`=  '0' OR `room_id` = '')");
                    Table = dbClient.getTable();
                }

                if (Table == null)
                {
                    Session.SendWhisper("You currently have no items in your inventory!");
                    return;
                }

                foreach (DataRow Row in Table.Rows)
                {
                    Item Item = Session.GetHabbo().GetInventoryComponent().GetItem(Convert.ToInt32(Row[0]));
                    if (Item == null)
                        continue;

                    if (!Item.GetBaseItem().ItemName.StartsWith("what the diamond furniture starts with") && !Item.GetBaseItem().ItemName.StartsWith("is there any other diamond furniture maybe"))
                        continue;

                    if (Item.RoomId > 0)
                        continue;

                    string[] Split = Item.GetBaseItem().ItemName.Split('_');
                    int Value = int.Parse(Split[1]);

                    using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
                    {
                        dbClient.RunQuery("DELETE FROM `items` WHERE `id` = '" + Item.Id + "' LIMIT 1");
                    }

                    Session.GetHabbo().GetInventoryComponent().RemoveItem(Item.Id);

                    TotalValue += Value;

                    if (Value > 0)
                    {
                        Session.GetHabbo().Diamonds += Value;
                        Session.SendMessage(new HabboActivityPointNotificationComposer(Session.GetHabbo().Diamonds, Value, 5));
                    }
                }

                if (TotalValue > 0)
                    Session.SendNotification("All diamonds have successfully been converted!\r\r(Total value: " + TotalValue + " diamonds!");
                else
                    Session.SendNotification("It appears you don't have any exchangeable items!");
            }
            catch
            {
                Session.SendNotification("Oops, an error occoured whilst converting your diamonds!");
            }
        }
    }
}
There are some strings that you'll need to change - I'd advice you to name all your diamond furniture something along the lines D_%VALUE%.
For example if you wanted to create a furni that's worth 250 diamonds and is a suitcase you'd run a query along the lines of... (I'm not good with furniture so I apologise if the query I supplied doesn't work)
Code:
INSERT INTO `furniture` (`item_name`, `public_name`, `sprite_id`) VALUES ('D_250_suitcase', 'D_250_suitcase', '5461')
As you can see it's named D_250_suitcase, the D_ is what the command would search for (if you've set it to that) in the furniture so it knows it's an exchangeable diamond furni, the _ are used to split up the name 250 being the price which is converted to an int and the _suitcase is there in case you'd like to have other diamond exchangeable furni that exchanges into 250 diamonds, you'd name those things such as D_250_throne, D_250_duck.
Btw be sure to change the strings in if (!Item.GetBaseItem().ItemName.StartsWith("what the diamond furniture starts with") && !Item.GetBaseItem().ItemName.StartsWith("is there any other diamond furniture maybe")) to something like "D_" if you're using my query shit.

TLDR: Command checks for furni including whatever you want at the start, uses _ to split the string, grabs number after first _ in the furni name and puts that into the users purse. Name the furni something to easily identify it's exchangeable diamond furni using _ to split it up.
Tbh just PM me if that was too confusing - confusing myself a bit.
 
Last edited:

Users who are viewing this thread

Top