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
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!");
}
}
}
}