Altercationz
:)
Hello,
There was a sellroom command recently released in an emulator, the code was written very poorly and had a few exploits.
I've touched it up, removed a bunch of unnecessary code and cleaned it up.
It requires a lot of steps, but it's worth it.
Add
to room.cs as well as the following method:
now for the commands,
SellRoomCommand
BuyRoomCommand
Now, this may not be the best way to do this but it properly transfers the items and swaps the owners so it gets the job done.
This has not been tested, if you come across any issues i'd be more than happy to help.
There was a sellroom command recently released in an emulator, the code was written very poorly and had a few exploits.
I've touched it up, removed a bunch of unnecessary code and cleaned it up.
It requires a lot of steps, but it's worth it.
Add
Code:
public int ForSaleAmount;
public bool RoomForSale;
Code:
public void AssignNewOwner(Room ForSale, RoomUser Buyer, RoomUser Seller)
{
using (IQueryAdapter Adapter = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
{
Adapter.SetQuery("UPDATE rooms SET owner = @new WHERE id = @id");
Adapter.AddParameter("new", Buyer.HabboId);
Adapter.AddParameter("id", ForSale.RoomData.Id);
Adapter.RunQuery();
Adapter.SetQuery("UPDATE items SET user_id = @new WHERE id = @id");
Adapter.AddParameter("new", Buyer.HabboId);
Adapter.AddParameter("id", ForSale.RoomData.Id);
Adapter.RunQuery();
Adapter.SetQuery("DELETE FROM room_rights WHERE room_id = @id");
Adapter.AddParameter("id", ForSale.RoomData.Id);
if (ForSale.Group != null)
{
Adapter.SetQuery("SELECT id FROM groups WHERE room_id = @id");
Adapter.AddParameter("id", ForSale.RoomData.Id);
int GroupID = Adapter.getInteger();
if (GroupID > 0)
{
ForSale.Group.ClearRequests();
foreach (int UserID in ForSale.Group.GetAllMembers)
{
ForSale.Group.DeleteMember(UserID);
GameClient UserClient = PlusEnvironment.GetGame().GetClientManager().GetClientByUserID(UserID);
if (UserClient == null)
continue;
if (UserClient.GetHabbo().GetStats().FavouriteGroupId == GroupID)
{
UserClient.GetHabbo().GetStats().FavouriteGroupId = 0;
}
}
Adapter.RunQuery("DELETE FROM `groups` WHERE `id` = @id = '" + ForSale.Group.Id + "'");
Adapter.RunQuery("DELETE FROM `group_memberships` WHERE group_id = '" + ForSale.Group.Id + "'");
Adapter.RunQuery("DELETE FROM `group_requests` WHERE group_id = '" + ForSale.Group.Id + "'");
Adapter.RunQuery("UPDATE `rooms` SET `group_id` = '0' WHERE `group_id` = '" + ForSale.Group.Id + "'");
Adapter.RunQuery("UPDATE `user_stats` SET `group_id` = '0' WHERE group_id = '" + ForSale.Group.Id + "'");
Adapter.RunQuery("DELETE FROM `items_groups` WHERE `group_id` = '" + ForSale.Group.Id + "'");
}
PlusEnvironment.GetGame().GetGroupManager().DeleteGroup(ForSale.Group.Id);
ForSale.RoomData.Group = null;
ForSale.Group = null;
}
}
ForSale.RoomData.OwnerId = Buyer.HabboId;
ForSale.RoomData.OwnerName = Buyer.GetClient().GetHabbo().Username;
foreach (Item Item in ForSale.GetRoomItemHandler().GetWallAndFloor)
{
Item.UserID = Buyer.HabboId;
Item.Username = Buyer.GetClient().GetHabbo().Username;
}
Buyer.GetClient().GetHabbo().Credits -= ForSale.ForSaleAmount;
Buyer.GetClient().SendMessage(new CreditBalanceComposer(Buyer.GetClient().GetHabbo().Credits));
Seller.GetClient().GetHabbo().Credits += ForSale.ForSaleAmount;
Seller.GetClient().SendMessage(new CreditBalanceComposer(Seller.GetClient().GetHabbo().Credits));
ForSale.RoomForSale = false;
ForSale.ForSaleAmount = 0;
Buyer.GetClient().GetHabbo().UsersRooms.Add(ForSale);
Buyer.GetClient().GetHabbo().UsersRooms.Remove(ForSale);
Room Room = null;
List<RoomUser> UsersReturn = ForSale.GetRoomUserManager().GetRoomUsers().ToList();
PlusEnvironment.GetGame().GetNavigator().Init();
PlusEnvironment.GetGame().GetRoomManager().UnloadRoom(Room, true);
foreach (RoomUser User in UsersReturn)
{
if (User == null || User.GetClient() == null)
continue;
User.GetClient().SendMessage(new RoomForwardComposer(ForSale.RoomId));
User.GetClient().SendNotification("This room has just been purchased by " + Buyer.GetClient().GetHabbo().Username + " for " + ForSale.ForSaleAmount + "!");
}
}
SellRoomCommand
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Plus.Database.Interfaces;
namespace Plus.HabboHotel.Rooms.Chat.Commands.User.Fun
{
class SellRoom : IChatCommand
{
public string PermissionRequired
{
get { return "command_sellroom"; }
}
public string Parameters
{
get { return "%price%"; }
}
public string Description
{
get { return "Sell your room"; }
}
public void Execute(GameClients.GameClient Session, Rooms.Room Room, string[] Params)
{
RoomUser User = Room.GetRoomUserManager().GetRoomUserByHabbo(Session.GetHabbo().Id);
if (Params.Length == 1)
{
Session.SendWhisper("Please enter a price for your room!");
return;
}
string roomCost = Params[1];
int Cost;
Cost = int.Parse(roomCost.Substring(0, roomCost.Length - 1));
if (Cost == 0)
{
Room.RoomForSale = false;
Room.ForSaleAmount = 0;
return;
}
if (Room.RoomData.OwnerId != User.HabboId)
{
Session.SendWhisper("You can not sell this room because you are not the owner.");
return;
}
if (Cost < 1 || Cost > 100000)
{
Session.SendWhisper("Invalid cost. (1-100000)");
return;
}
else
{
Room.RoomForSale = true;
Room.ForSaleAmount = Cost;
Session.SendWhisper("This room has now been put for up for sale, the room has been notified.");
foreach (RoomUser user in Room.GetRoomUserManager().GetRoomUsers())
{
if (user == null || user.GetClient() == null)
continue;
user.GetClient().SendNotification("This room is now for sale for " + Cost + " credits! type :buyroom to purchase it.");
}
}
}
}
}
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Plus.HabboHotel.Rooms.Chat.Commands.User.Fun
{
class BuyRoomCommand
{
public string PermissionRequired
{
get { return "command_buyroom"; }
}
public string Parameters
{
get { return ""; }
}
public string Description
{
get { return "Purchase a room that is for sale."; }
}
public void Execute(GameClients.GameClient Session, Rooms.Room Room, string[] Params)
{
RoomUser User = Room.GetRoomUserManager().GetRoomUserByHabbo(Session.GetHabbo().Id);
RoomUser Owner = Room.GetRoomUserManager().GetRoomUserByHabbo(Room.RoomData.OwnerId);
if (User == null)
return;
if (!Room.RoomForSale)
{
Session.SendWhisper("This room is not for sale!");
return;
}
if (Room.OwnerId == User.HabboId)
{
Session.SendWhisper("You can not purchase your own room.");
return;
}
if (User.GetClient().GetHabbo().Credits >= Room.ForSaleAmount)
{
Room.AssignNewOwner(Room, User, Owner);
}
else
{
User.GetClient().SendWhisper("You do not have enough credits!");
return;
}
}
}
}
This has not been tested, if you come across any issues i'd be more than happy to help.
Last edited: