Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[BC Storm/Swift Emu] Sellroom and buyroom command

Status
Not open for further replies.
Experienced Elementalist
Joined
Aug 26, 2012
Messages
248
Reaction score
49
Hello Ragezone, This is my first Release.

All Works (but you need to reload emu for room owner to change anyone can fix that would help alot)

This code is Messy i know but no hate please. Also Sorry about my English my spelling and Grammar are Crap.

1.

Find (CTRL F) "internal void AppendPetsUpdateString(IQueryAdapter dbClient)" in RoomUserManger And Add Above it.
PHP:
#region Check Sell
            int Sale;
            int price;
              using (IQueryAdapter adapter = ButterflyEnvironment.GetDatabaseManager().getQueryreactor())
                
            {
                adapter.setQuery("SELECT room_sell FROM rooms WHERE id =" + this.room.RoomId);
               
                Sale = adapter.getInteger();

            }

            using (IQueryAdapter adapter = ButterflyEnvironment.GetDatabaseManager().getQueryreactor())
            {
                adapter.setQuery("SELECT room_price FROM rooms WHERE id = "+ this.room.RoomId);
               
                price = adapter.getInteger();
            }
            if (Sale == 1)
            {
                Session.SendNotifWithScroll("This Room is For sale at " + price + "  Type :buyroom");
            }
            
        }
            #endregion
What this does is When you enter the room it will alert you if the room is for sale and how much

2. In ChatCommandHandleing (where all the other commands are)
add
PHP:
#region Buyroom
        internal void buyroom()
        {
            int Price;
            uint user;
            string owner;
            int sale;
            int Credits;
            int OwnerCredits;
            string caption;
            string model;
            user = this.Session.GetHabbo().Id;
            string user1 = this.Session.GetHabbo().Username;
            uint currentRoom1 = this.Session.GetHabbo().CurrentRoomId;
            Room currentRoom = this.Session.GetHabbo().CurrentRoom;
            Room ownercurrentRoom = this.Session.GetHabbo().CurrentRoom;
            currentRoom = ButterflyEnvironment.GetGame().GetRoomManager().GetRoom(this.Session.GetHabbo().CurrentRoomId);
            
            GameClient roomowner = null;

            // querys to get data
            using (IQueryAdapter adapter = ButterflyEnvironment.GetDatabaseManager().getQueryreactor())
            {
                {
                    adapter.setQuery("SELECT owner FROM rooms WHERE id ="+currentRoom1);
                    
                    owner = adapter.getString();
                }
                
            }

            
             using (IQueryAdapter adapter = ButterflyEnvironment.GetDatabaseManager().getQueryreactor())
             {
            roomowner = ButterflyEnvironment.GetGame().GetClientManager().GetClientByUsername(owner);
                uint owner2 = roomowner.GetHabbo().Id;
                {
                    adapter.setQuery("SELECT credits FROM users WHERE id ="+user);
                   
                    Credits = adapter.getInteger();
                }
                {
                    adapter.setQuery("SELECT credits FROM users WHERE id ="+owner2);
                    
                    OwnerCredits = adapter.getInteger();
                }
                {
                    adapter.setQuery("SELECT room_price FROM rooms WHERE id =" +currentRoom1);
                    
                    Price = adapter.getInteger();
                }
                {
                    adapter.setQuery("SELECT room_sell FROM rooms WHERE id ="+currentRoom1);
                  
                    sale = adapter.getInteger();
                }
                  {
                    adapter.setQuery("SELECT caption FROM rooms WHERE id ="+currentRoom1);
                  
                    caption = adapter.getString();
                }
                    {
                    adapter.setQuery("SELECT model_name FROM rooms WHERE id ="+currentRoom1);
                  
                    model = adapter.getString();
                }
            }
        
            roomowner = ButterflyEnvironment.GetGame().GetClientManager().GetClientByUsername(owner);
            ownercurrentRoom = ButterflyEnvironment.GetGame().GetRoomManager().GetRoom(roomowner.GetHabbo().CurrentRoomId);
            if (sale == 0) // check to see if room for sale.
            {
               this.Session.SendNotifWithScroll("Not For Sale Sorry.");
            }
                //check to see if owners in room.
            else if (currentRoom != ownercurrentRoom)
                
            {
                this.Session.SendNotifWithScroll("Sorry the room owner isnt in the room.");
                using (IQueryAdapter adapter = ButterflyEnvironment.GetDatabaseManager().getQueryreactor())
                {

                    adapter.runFastQuery("UPDATE rooms SET room_sell = '0' WHERE id = " + currentRoom);


                }
            }
            else
            {

                if (user == roomowner.GetHabbo().Id) // Cancells Sell
                {
                    using (IQueryAdapter adapter = ButterflyEnvironment.GetDatabaseManager().getQueryreactor())
                    {

                        adapter.runFastQuery("UPDATE rooms SET room_sell = '0' WHERE id = " + currentRoom1);


                    }
                    //
                    // alerts room 
                    this.Session.SendNotifWithScroll("You Have Cancelled The Room Being Sold");
                    string s = "The Owner Has Cancelled The Room being sold";
                    ServerMessage message = new ServerMessage();
                    message.Init(Outgoing.SendNotif);
                    message.AppendString(s);
                    message.AppendString("");
                    currentRoom.QueueRoomMessage(message);
                }
                else
                {
                    if (Credits >= Price) // check credits
                    {

                        // Updates Room Owner And Updates The Room Sell
                        using (IQueryAdapter adapter = ButterflyEnvironment.GetDatabaseManager().getQueryreactor())
                        {
                            adapter.runFastQuery(string.Concat(new object[] {"UPDATE rooms SET room_sell = '0' WHERE id = " + currentRoom1}));
                            adapter.runFastQuery("UPDATE rooms SET owner = '" +this.Session.GetHabbo().Username+ "'  WHERE id = " + currentRoom1);


                        }
                        //


                        // update prices 
                        Session.GetHabbo().Credits -= Price;
                        Session.GetHabbo().UpdateCreditsBalance();
                        roomowner.GetHabbo().Credits += Price;
                        roomowner.GetHabbo().UpdateCreditsBalance();
                        //
                        

                        // Alerts Room
                        string s = "This Room Has Been Bought by:" + user1;
                        Thread.Sleep(1000);
                        ServerMessage message = new ServerMessage(2);
                        message.Init(Outgoing.SendNotif);
                        message.AppendString(s);
                        message.AppendString("");
                        currentRoom.QueueRoomMessage(message);
                        //


                        
                        // adds new room to users room And removes it from old users room
                        RoomData item = ButterflyEnvironment.GetGame().GetRoomManager().GenerateRoomData(currentRoom1);
                        Session.GetHabbo().UsersRooms.Add(item);
                        roomowner.GetHabbo().UsersRooms.Remove(item);
                       //

           
                        // unloads the room
                       ButterflyEnvironment.GetGame().GetRoomManager().UnloadRoom(currentRoom);
                        //
       
                      
                    }
                    else
                    {
                      this.Session.SendNotifWithScroll("Sorry you dont have enough for the rooms D:");
                    }
                    
                }
            }
        }
#endregion
        #region Sellroom

        internal void sellroom()
        {


            int num = 1;
            string user;
            string owner;
            int Price;
            user = this.Session.GetHabbo().Username;
            uint currentRoom = this.Session.GetHabbo().CurrentRoomId;
            Room currentRoom2 = ButterflyEnvironment.GetGame().GetRoomManager().GetRoom(Session.GetHabbo().CurrentRoomId);
            using (IQueryAdapter adapter = ButterflyEnvironment.GetDatabaseManager().getQueryreactor())
            {
                adapter.setQuery("SELECT owner FROM rooms WHERE id =" + currentRoom);
                
                owner = adapter.getString();
            }
            if (int.TryParse(this.Params[1], out Price))
            {
                if (owner != user)
                {
                    Session.SendNotifWithScroll("Sorry You Do Not Own This Room");
                }
                else
                {
                    using (IQueryAdapter adapter = ButterflyEnvironment.GetDatabaseManager().getQueryreactor())
                    {
                        adapter.runFastQuery(string.Concat(new object[] {"UPDATE rooms SET room_sell = ",num ," WHERE id = ", currentRoom}));
                        adapter.runFastQuery(string.Concat(new object[] {"UPDATE rooms SET room_price = ", Price , " WHERE id = ", currentRoom}));

                    }
                    this.Session.SendNotifWithScroll("You have put your room for sale");
                    string s = "this Room Is For Sale /n Amount:" + Price + " Credits.";
                    ServerMessage message = new ServerMessage(2);
                    message.Init(Outgoing.SendNotif);
                    message.AppendString(s);
                    message.AppendString("");
                    currentRoom2.QueueRoomMessage(message);
                }
            }
            else
            {
                this.Session.SendNotifWithScroll(" Sorry There Was a Error ");
            }
        }
        #endregion

3.
then go to ChatCommandRegister.cs
and add

PHP:
                case 169:
                    commandHandler.sellroom();
                    break;
                case 170:
                    commandHandler.buyroom();
                    break;
4. Then Add it to your Commands and command Register In the emu bin file.

5. go to database and run this 2

ALTER TABLE `rooms` ADD `room_sell` INT(9)
ALTER TABLE `rooms` ADD `room_price` INT(9)



If You can help with updating Owner with out reloading Emu i Would Be Very Thankfull!!
 
Zephyr Studios
Loyal Member
Joined
Feb 18, 2012
Messages
1,877
Reaction score
724
Nice idea, It's a really nice idea!
I apreciate your work man, thank you :love:
 
Experienced Elementalist
Joined
Aug 26, 2012
Messages
248
Reaction score
49
This can be done very well without querying the database, so you do not get many ...
If i Can Fix The Room Owner Updating Then i will fix up and make the code alot neater and faster.
Nice idea, It's a really nice idea!
I apreciate your work man, thank you :love:

Thanks Dude.
 
Junior Spellweaver
Joined
May 24, 2013
Messages
123
Reaction score
22
I would use a query for the update room owner, I don't know if it fix your problem there. Well anyways good release ;) I'm a fan of command releases :)
 
Experienced Elementalist
Joined
Aug 26, 2012
Messages
248
Reaction score
49
I would use a query for the update room owner, I don't know if it fix your problem there. Well anyways good release ;) I'm a fan of command releases :)
It updates the room owner on database fine, just not on client till the emu reload which means i have to find away off completely reloading the room with all info (cant find away off doing it)
 
Experienced Elementalist
Joined
Sep 19, 2011
Messages
240
Reaction score
35
try :unload to unload the room and see. If that works just call the command after each :buy
 
Experienced Elementalist
Joined
Aug 26, 2012
Messages
248
Reaction score
49
try :unload to unload the room and see. If that works just call the command after each :buy

I have Already Tried That "
// unloads the room
ButterflyEnvironment.GetGame().GetRoomManager().UnloadRoom(currentRoom);
// "
it make no diffrence.
 
Newbie Spellweaver
Joined
May 20, 2013
Messages
33
Reaction score
26
@Ben - Use
Room Room = ButterflyEnvironment.GetGame().GetRoomManager().GetRoom(Session.GetHabbo().CurrentRoom.RoomId);
Room.OwnerId = Session.GetHabbo().Id;
 
Banned
Banned
Joined
Aug 4, 2011
Messages
852
Reaction score
331
Do this for live updating the room owner:
Code:
Room.ownerId = Session.GetHabbo().Id;
 
Experienced Elementalist
Joined
Aug 26, 2012
Messages
248
Reaction score
49
Do this for live updating the room owner:
Code:
Room.ownerId = Session.GetHabbo().Id;

Thank you also had to do
Room.owner = Session.GetHabbo().username;

and did a little bit more editing to get the bugs out.

ill Release the fixed code when i recode the items so you can keep all items inside
 
Experienced Elementalist
Joined
Aug 26, 2012
Messages
248
Reaction score
49
I think its a great idea to. Like the release btw. Maybe im going to add it to test it, i think i'll do that :)

If you wait a Couple of hours ill Update this Thread With Fully fixed, Neater code + It updates furni to your name.
 
Newbie Spellweaver
Joined
Nov 22, 2012
Messages
26
Reaction score
21
Have you an idea on how we could ever duplicate a room? It seems quite hard but it would be really interesting for selling purposes (hard because we also need to duplicate the items inside, from different tables)
 
Status
Not open for further replies.
Back
Top