Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Server Development
Habbo Retros
Habbo Releases
Server Releases
Sellroom / Buyroom.
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Altercationz" data-source="post: 402019" data-attributes="member: 59038"><p>Hello,</p><p>There was a sellroom command recently released in an emulator, the code was written very poorly and had a few exploits.</p><p>I've touched it up, removed a bunch of unnecessary code and cleaned it up.</p><p>It requires a lot of steps, but it's worth it.</p><p>Add</p><p>[CODE]</p><p>public int ForSaleAmount;</p><p>public bool RoomForSale;</p><p>[/CODE] to room.cs as well as the following method:</p><p>[CODE]</p><p>public void AssignNewOwner(Room ForSale, RoomUser Buyer, RoomUser Seller)</p><p> {</p><p> using (IQueryAdapter Adapter = PlusEnvironment.GetDatabaseManager().GetQueryReactor())</p><p> {</p><p> Adapter.SetQuery("UPDATE rooms SET owner = @new WHERE id = @id");</p><p> Adapter.AddParameter("new", Buyer.HabboId);</p><p> Adapter.AddParameter("id", ForSale.RoomData.Id);</p><p> Adapter.RunQuery();</p><p></p><p> Adapter.SetQuery("UPDATE items SET user_id = @new WHERE id = @id");</p><p> Adapter.AddParameter("new", Buyer.HabboId);</p><p> Adapter.AddParameter("id", ForSale.RoomData.Id);</p><p> Adapter.RunQuery();</p><p></p><p> Adapter.SetQuery("DELETE FROM room_rights WHERE room_id = @id");</p><p> Adapter.AddParameter("id", ForSale.RoomData.Id);</p><p></p><p> if (ForSale.Group != null)</p><p> {</p><p> Adapter.SetQuery("SELECT id FROM groups WHERE room_id = @id");</p><p> Adapter.AddParameter("id", ForSale.RoomData.Id);</p><p> int GroupID = Adapter.getInteger();</p><p> if (GroupID > 0)</p><p> {</p><p> ForSale.Group.ClearRequests();</p><p> foreach (int UserID in ForSale.Group.GetAllMembers)</p><p> {</p><p> ForSale.Group.DeleteMember(UserID);</p><p> GameClient UserClient = PlusEnvironment.GetGame().GetClientManager().GetClientByUserID(UserID);</p><p> if (UserClient == null)</p><p> continue;</p><p></p><p> if (UserClient.GetHabbo().GetStats().FavouriteGroupId == GroupID)</p><p> {</p><p> UserClient.GetHabbo().GetStats().FavouriteGroupId = 0;</p><p> }</p><p> }</p><p> Adapter.RunQuery("DELETE FROM `groups` WHERE `id` = @id = '" + ForSale.Group.Id + "'");</p><p> Adapter.RunQuery("DELETE FROM `group_memberships` WHERE group_id = '" + ForSale.Group.Id + "'");</p><p> Adapter.RunQuery("DELETE FROM `group_requests` WHERE group_id = '" + ForSale.Group.Id + "'");</p><p> Adapter.RunQuery("UPDATE `rooms` SET `group_id` = '0' WHERE `group_id` = '" + ForSale.Group.Id + "'");</p><p> Adapter.RunQuery("UPDATE `user_stats` SET `group_id` = '0' WHERE group_id = '" + ForSale.Group.Id + "'");</p><p> Adapter.RunQuery("DELETE FROM `items_groups` WHERE `group_id` = '" + ForSale.Group.Id + "'");</p><p> }</p><p> PlusEnvironment.GetGame().GetGroupManager().DeleteGroup(ForSale.Group.Id);</p><p> ForSale.RoomData.Group = null;</p><p> ForSale.Group = null;</p><p> }</p><p> }</p><p> ForSale.RoomData.OwnerId = Buyer.HabboId;</p><p> ForSale.RoomData.OwnerName = Buyer.GetClient().GetHabbo().Username;</p><p></p><p> foreach (Item Item in ForSale.GetRoomItemHandler().GetWallAndFloor)</p><p> {</p><p> Item.UserID = Buyer.HabboId;</p><p> Item.Username = Buyer.GetClient().GetHabbo().Username;</p><p> }</p><p> Buyer.GetClient().GetHabbo().Credits -= ForSale.ForSaleAmount;</p><p> Buyer.GetClient().SendMessage(new CreditBalanceComposer(Buyer.GetClient().GetHabbo().Credits));</p><p> Seller.GetClient().GetHabbo().Credits += ForSale.ForSaleAmount;</p><p> Seller.GetClient().SendMessage(new CreditBalanceComposer(Seller.GetClient().GetHabbo().Credits));</p><p></p><p> ForSale.RoomForSale = false;</p><p> ForSale.ForSaleAmount = 0;</p><p></p><p> Buyer.GetClient().GetHabbo().UsersRooms.Add(ForSale);</p><p> Buyer.GetClient().GetHabbo().UsersRooms.Remove(ForSale);</p><p></p><p> Room Room = null;</p><p> List<RoomUser> UsersReturn = ForSale.GetRoomUserManager().GetRoomUsers().ToList();</p><p> PlusEnvironment.GetGame().GetNavigator().Init();</p><p> PlusEnvironment.GetGame().GetRoomManager().UnloadRoom(Room, true);</p><p> foreach (RoomUser User in UsersReturn)</p><p> {</p><p> if (User == null || User.GetClient() == null)</p><p> continue;</p><p> User.GetClient().SendMessage(new RoomForwardComposer(ForSale.RoomId));</p><p> User.GetClient().SendNotification("This room has just been purchased by " + Buyer.GetClient().GetHabbo().Username + " for " + ForSale.ForSaleAmount + "!");</p><p> }</p><p> }</p><p>[/CODE]</p><p>now for the commands,</p><p>SellRoomCommand</p><p>[CODE]</p><p>using System;</p><p>using System.Collections.Generic;</p><p>using System.Linq;</p><p>using System.Text;</p><p>using System.Threading.Tasks;</p><p>using Plus.Database.Interfaces;</p><p></p><p>namespace Plus.HabboHotel.Rooms.Chat.Commands.User.Fun</p><p>{</p><p> class SellRoom : IChatCommand</p><p> {</p><p> public string PermissionRequired</p><p> {</p><p> get { return "command_sellroom"; }</p><p> }</p><p> public string Parameters</p><p> {</p><p> get { return "%price%"; }</p><p> }</p><p> public string Description</p><p> {</p><p> get { return "Sell your room"; }</p><p> }</p><p> public void Execute(GameClients.GameClient Session, Rooms.Room Room, string[] Params)</p><p> {</p><p> RoomUser User = Room.GetRoomUserManager().GetRoomUserByHabbo(Session.GetHabbo().Id);</p><p></p><p> if (Params.Length == 1)</p><p> {</p><p> Session.SendWhisper("Please enter a price for your room!");</p><p> return;</p><p> }</p><p></p><p> string roomCost = Params[1];</p><p> int Cost;</p><p> Cost = int.Parse(roomCost.Substring(0, roomCost.Length - 1));</p><p></p><p> if (Cost == 0)</p><p> {</p><p> Room.RoomForSale = false;</p><p> Room.ForSaleAmount = 0;</p><p> return;</p><p> }</p><p></p><p> if (Room.RoomData.OwnerId != User.HabboId)</p><p> {</p><p> Session.SendWhisper("You can not sell this room because you are not the owner.");</p><p> return;</p><p> }</p><p></p><p> if (Cost < 1 || Cost > 100000)</p><p> {</p><p> Session.SendWhisper("Invalid cost. (1-100000)");</p><p> return;</p><p> }</p><p> else</p><p> {</p><p> Room.RoomForSale = true;</p><p> Room.ForSaleAmount = Cost;</p><p> Session.SendWhisper("This room has now been put for up for sale, the room has been notified.");</p><p></p><p> foreach (RoomUser user in Room.GetRoomUserManager().GetRoomUsers())</p><p> {</p><p> if (user == null || user.GetClient() == null)</p><p> continue;</p><p></p><p> user.GetClient().SendNotification("This room is now for sale for " + Cost + " credits! type :buyroom to purchase it.");</p><p> }</p><p> }</p><p> }</p><p> }</p><p>}</p><p>[/CODE]</p><p>BuyRoomCommand</p><p>[CODE]</p><p>using System;</p><p>using System.Collections.Generic;</p><p>using System.Linq;</p><p>using System.Text;</p><p>using System.Threading.Tasks;</p><p></p><p>namespace Plus.HabboHotel.Rooms.Chat.Commands.User.Fun</p><p>{</p><p> class BuyRoomCommand</p><p> {</p><p> public string PermissionRequired</p><p> {</p><p> get { return "command_buyroom"; }</p><p> }</p><p> public string Parameters</p><p> {</p><p> get { return ""; }</p><p> }</p><p> public string Description</p><p> {</p><p> get { return "Purchase a room that is for sale."; }</p><p> }</p><p> public void Execute(GameClients.GameClient Session, Rooms.Room Room, string[] Params)</p><p> {</p><p> RoomUser User = Room.GetRoomUserManager().GetRoomUserByHabbo(Session.GetHabbo().Id);</p><p> RoomUser Owner = Room.GetRoomUserManager().GetRoomUserByHabbo(Room.RoomData.OwnerId);</p><p></p><p> if (User == null)</p><p> return;</p><p></p><p> if (!Room.RoomForSale)</p><p> {</p><p> Session.SendWhisper("This room is not for sale!");</p><p> return;</p><p> }</p><p></p><p> if (Room.OwnerId == User.HabboId)</p><p> {</p><p> Session.SendWhisper("You can not purchase your own room.");</p><p> return;</p><p> }</p><p></p><p> if (User.GetClient().GetHabbo().Credits >= Room.ForSaleAmount)</p><p> {</p><p> Room.AssignNewOwner(Room, User, Owner);</p><p> }</p><p> else</p><p> {</p><p> User.GetClient().SendWhisper("You do not have enough credits!");</p><p> return;</p><p> }</p><p> }</p><p> }</p><p>}</p><p>[/CODE]</p><p>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.</p><p>This has not been tested, if you come across any issues i'd be more than happy to help.</p></blockquote><p></p>
[QUOTE="Altercationz, post: 402019, member: 59038"] 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 [CODE] public int ForSaleAmount; public bool RoomForSale; [/CODE] to room.cs as well as the following method: [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 + "!"); } } [/CODE] now for the commands, 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] BuyRoomCommand [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; } } } } [/CODE] 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. [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Server Development
Habbo Retros
Habbo Releases
Server Releases
Sellroom / Buyroom.
Top