Welcome Bot

May 1, 2015
470
154
Hi,
To celebrate my returning back to retros (not something i'm proud of, bored to death lately) but enough of me let's get to the release.
I was on a hotel recently where they had a welcome bot which appears in your first room and greets you.
I loved the idea and the bot can be set to do pretty much anything which is why it's quite unique.

This probably isn't how the developer of the hotel I found it on did it but it does the job that's for sure.
The bot ID is randomly generated everytime a new player creates a room and this is checked by determining the users room count having it be less than 0 will send them the bot to welcome them, the method creates a new thread which holds the timer and kicks the bot out after a minute which is enough time for him to welcome the new player, if you think otherwise it can easily be changed.

This can be placed anywhere, I just threw it in Habbo.cs
Code:
public void CheckFirstRoom(GameClient User)
        {
            if (User.GetHabbo().UsersRooms.Count > 0)
            {
                return; // Already has a room.
            }
            else
            {

                // Bot Timer.
                TimeSpan BotSent = DateTime.Now - BotDeployed;
                WelcomeBotDeployed = true;

                //Execute.
                Room NewRoom;
                Bot Noob = null;
                int X = 3 - 10;
                int Y = 3 - 10;

                // Bot Id Randomizer.
                Random Random = new Random();
                int BotId = Random.Next(1, 9999);

                List<RandomSpeech> Speech = new List<RandomSpeech>();

                NewRoom = User.GetHabbo().CurrentRoom;
                RoomUser Bot = NewRoom.GetRoomUserManager().DeployBot(new RoomBot(BotId, User.GetHabbo().CurrentRoomId, "bartender", "freeroam", "Disguised", "Welcome!", Noob.Figure, X, Y, 0, 4, 0, 0, 0, 0, ref Speech, "", 0, Noob.OwnerId, false, 0, false, 0), null);
                Bot.Chat("Welcome to the hotel!", false, 0);
                // Have the bot do whatever else you wish here.

                new Thread(() => Thread.Sleep(60000));
                if (WelcomeBotDeployed)
                    // Bot has greeted new player, time to greet some more lets get rid of him!
                    NewRoom.GetRoomUserManager().RemoveBot(Noob.Id, true);
                WelcomeBotDeployed = false;
            }
        }
Then the following code to be pasted in the create room method in the RoomManager.cs
Code:
Session.GetHabbo().CheckFirstRoom(Session); // Send bot to new room to greet the user.

It's as easy as that, enjoy.
"Giving credit where credit is due is a very rewarding habit to form. Its rewards are inestimable." - Loretta Young

The idea was taken from Hebbo Hotel.

The code above is not efficient enough so use the one below!
Code:
internal void WelcomeBot()
       {
           if (WelcomeTask != null)
           {
               WelcomeTask.Dispose();
           }

           if (WelcomeTimer != null)
           {
               WelcomeTimer.Dispose();
           }

           if (this.UsersRooms.Count < 0 && WelcomeBotDeployed)
           {
               return; // User has created a room already / or had the bot deployed.
           }
           else
           {
               WelcomeBotDeployed = true; // set in database forever. bool (0/1)

               // Execute.
               Room NewRoom = this.CurrentRoom;
               Bot Noob = null;
               int X = 3 - 10;
               int Y = 3 - 10;

               // Bot Id Randomizer.
               Random Random = new Random();
               int BotId = Random.Next(1, 9999);

               List<RandomSpeech> Speech = new List<RandomSpeech>();

               RoomUser Bot = NewRoom.GetRoomUserManager().DeployBot(new RoomBot(BotId, this.CurrentRoomId, "bartender", "freeroam", "Disguised", "Welcome!", Noob.Figure, X, Y, 0, 4, 0, 0, 0, 0, ref Speech, "", 0, Noob.OwnerId, false, 0, false, 0), null);
               Bot.Chat("Welcome to the hotel!", false, 0);
               // Have the bot do whatever else here.

               WelcomeTimer = new System.Timers.Timer();
               WelcomeTimer.AutoReset = false;
               WelcomeTimer.Elapsed += WelcomeBot_Elapsed;
               WelcomeTimer.Interval = 60000; // time until the bot is kicked.

               WelcomeTask = new System.Threading.Tasks.Task(WelcomeTimer.Start);
               WelcomeTask.Start();
           }
       }
Code:
private void WelcomeBot_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
       {
           if (GetClient() == null)
           {
               WelcomeTask.Dispose();
               WelcomeTimer.Dispose();
               return;
           }

           Room Room = this.CurrentRoom;
           foreach (RoomUser User in Room.GetRoomUserManager().GetUserList().ToList())
           {
               if (User == null || !User.IsBot) // make sure you're removing the bot.
                   continue;

               RoomUser Bot = null;
               if (!Room.GetRoomUserManager().TryGetBot(User.BotData.Id, out Bot))
                   return;

               Room.GetRoomUserManager().RemoveBot(Bot.VirtualId, true);
               // end the timer and task.
               WelcomeTask.Dispose();
               WelcomeTimer.Dispose();
           }
       }
In the EnterRoom Method, "CheckFirstRoom" can be replaced with
Code:
WelcomeBot();
and you must put
Code:
public Timer WelcomeTimer;
public Task WelcomeTask;
in Habbo.cs
 
Last edited:

JMS

Posting Freak
Aug 25, 2014
562
270
This is a useful release, of course this bot could be used for a variety of things - just think outside the box ;)
 

Zodiak

recovering crack addict
Nov 18, 2011
453
417
Not messed w/ habbo shit in a while but if I remember correctly, isnt using "GameClient User" useless because it's in the Habbo.cs, so the session is accessible anyway
 

CosmoPeak

PeakRP.com
May 15, 2016
271
268
Not messed w/ habbo shit in a while but if I remember correctly, isnt using "GameClient User" useless because it's in the Habbo.cs, so the session is accessible anyway
Not just that, but the only method used from the `User` paramter is `GetHabbo()`, even though it's already inside the Habbo class...

Secondly, from the code posted, it looks like the bot is going to be removed straight away...

Creating a thread that sleeps for 60,000 doesn't block the methods after it from running, as the sleep is done in the separate thread. If you want the stuff after it delayed, you need to put it after the sleep inside the thread body as well. However, I don't know how thread-safe that would be.
 

Mythic

Member
Jan 27, 2018
33
15
Uhm. As far as I get it, the bot will be placed once the user has 0 rooms. Means, that I can create a room, but then delete it, and the bot would then join again, even when I am not freshly registered. Please have in mind, this can be an issue if the bot is going to give credits or diamonds to the user.
 
May 1, 2015
470
154
Alright,
Clearly I should of thought this out before releasing it.
I have now placed this on a timer which will elapse and remove the bot from the room once it's finished it's task.
I changed the way it checks if the user has already made a room, it'll still check if the user has 0 rooms but it will also check if the user has had the "Welcome bot deployed" which will be set as a bool 0/1 in the database indicating if the bot has been sent and greeted and rewarded the specific user.
I won't be using this myself which means I didn't cache "WelcomeBotDeployed" I just made it as a public bool not caching anything for demonstration purposes, If you're going to use this code I assume you know how to do that yourself (If not i added some step by step comments in the code itself, I will not be providing any further help with this as I've done most of the work for you since original release)

Below is the new codes, the timer itself and what happens when it has elapsed.
Code:
internal void WelcomeBot()
        {
            if (WelcomeTask != null)
            {
                WelcomeTask.Dispose();
            }

            if (WelcomeTimer != null)
            {
                WelcomeTimer.Dispose();
            }

            if (this.UsersRooms.Count < 0 && WelcomeBotDeployed)
            {
                return; // User has created a room already / or had the bot deployed.
            }
            else
            {
                WelcomeBotDeployed = true; // set in database forever. bool (0/1)

                // Execute.
                Room NewRoom = this.CurrentRoom;
                Bot Noob = null;
                int X = 3 - 10;
                int Y = 3 - 10;

                // Bot Id Randomizer.
                Random Random = new Random();
                int BotId = Random.Next(1, 9999);

                List<RandomSpeech> Speech = new List<RandomSpeech>();

                RoomUser Bot = NewRoom.GetRoomUserManager().DeployBot(new RoomBot(BotId, this.CurrentRoomId, "bartender", "freeroam", "Disguised", "Welcome!", Noob.Figure, X, Y, 0, 4, 0, 0, 0, 0, ref Speech, "", 0, Noob.OwnerId, false, 0, false, 0), null);
                Bot.Chat("Welcome to the hotel!", false, 0);
                // Have the bot do whatever else here.

                WelcomeTimer = new System.Timers.Timer();
                WelcomeTimer.AutoReset = false;
                WelcomeTimer.Elapsed += WelcomeBot_Elapsed;
                WelcomeTimer.Interval = 60000; // time until the bot is kicked.

                WelcomeTask = new System.Threading.Tasks.Task(WelcomeTimer.Start);
                WelcomeTask.Start();
            }
        }

Code:
private void WelcomeBot_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            if (GetClient() == null)
            {
                WelcomeTask.Dispose();
                WelcomeTimer.Dispose();
                return;
            }

            Room Room = this.CurrentRoom;
            foreach (RoomUser User in Room.GetRoomUserManager().GetUserList().ToList())
            {
                if (User == null || !User.IsBot) // make sure you're removing the bot.
                    continue;

                RoomUser Bot = null;
                if (!Room.GetRoomUserManager().TryGetBot(User.BotData.Id, out Bot))
                    return;

                Room.GetRoomUserManager().RemoveBot(Bot.VirtualId, true);
                // end the timer and task.
                WelcomeTask.Dispose();
                WelcomeTimer.Dispose();
            }
        }

In the EnterRoom Method, "CheckFirstRoom" can be replaced with
Code:
WelcomeBot();
and you must put
Code:
public Timer WelcomeTimer;
public Task WelcomeTask;
in Habbo.cs
and it's simple as that.

Enjoy.
 

Joe

Well-Known Member
Jun 10, 2012
4,172
1,955
Alright,
Clearly I should of thought this out before releasing it.
I have now placed this on a timer which will elapse and remove the bot from the room once it's finished it's task.
I changed the way it checks if the user has already made a room, it'll still check if the user has 0 rooms but it will also check if the user has had the "Welcome bot deployed" which will be set as a bool 0/1 in the database indicating if the bot has been sent and greeted and rewarded the specific user.
I won't be using this myself which means I didn't cache "WelcomeBotDeployed" I just made it as a public bool not caching anything for demonstration purposes, If you're going to use this code I assume you know how to do that yourself (If not i added some step by step comments in the code itself, I will not be providing any further help with this as I've done most of the work for you since original release)

Below is the new codes, the timer itself and what happens when it has elapsed.
Code:
internal void WelcomeBot()
        {
            if (WelcomeTask != null)
            {
                WelcomeTask.Dispose();
            }

            if (WelcomeTimer != null)
            {
                WelcomeTimer.Dispose();
            }

            if (this.UsersRooms.Count < 0 && WelcomeBotDeployed)
            {
                return; // User has created a room already / or had the bot deployed.
            }
            else
            {
                WelcomeBotDeployed = true; // set in database forever. bool (0/1)

                // Execute.
                Room NewRoom = this.CurrentRoom;
                Bot Noob = null;
                int X = 3 - 10;
                int Y = 3 - 10;

                // Bot Id Randomizer.
                Random Random = new Random();
                int BotId = Random.Next(1, 9999);

                List<RandomSpeech> Speech = new List<RandomSpeech>();

                RoomUser Bot = NewRoom.GetRoomUserManager().DeployBot(new RoomBot(BotId, this.CurrentRoomId, "bartender", "freeroam", "Disguised", "Welcome!", Noob.Figure, X, Y, 0, 4, 0, 0, 0, 0, ref Speech, "", 0, Noob.OwnerId, false, 0, false, 0), null);
                Bot.Chat("Welcome to the hotel!", false, 0);
                // Have the bot do whatever else here.

                WelcomeTimer = new System.Timers.Timer();
                WelcomeTimer.AutoReset = false;
                WelcomeTimer.Elapsed += WelcomeBot_Elapsed;
                WelcomeTimer.Interval = 60000; // time until the bot is kicked.

                WelcomeTask = new System.Threading.Tasks.Task(WelcomeTimer.Start);
                WelcomeTask.Start();
            }
        }

Code:
private void WelcomeBot_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            if (GetClient() == null)
            {
                WelcomeTask.Dispose();
                WelcomeTimer.Dispose();
                return;
            }

            Room Room = this.CurrentRoom;
            foreach (RoomUser User in Room.GetRoomUserManager().GetUserList().ToList())
            {
                if (User == null || !User.IsBot) // make sure you're removing the bot.
                    continue;

                RoomUser Bot = null;
                if (!Room.GetRoomUserManager().TryGetBot(User.BotData.Id, out Bot))
                    return;

                Room.GetRoomUserManager().RemoveBot(Bot.VirtualId, true);
                // end the timer and task.
                WelcomeTask.Dispose();
                WelcomeTimer.Dispose();
            }
        }

In the EnterRoom Method, "CheckFirstRoom" can be replaced with
Code:
WelcomeBot();
and you must put
Code:
public Timer WelcomeTimer;
public Task WelcomeTask;
in Habbo.cs
and it's simple as that.

Enjoy.
Would recommend you update the OP with this one. Nice release, it's good to see some activity in this section again.
 

Damien

Don't need glasses if you can C#
Feb 26, 2012
434
647
This is cancer. Just create a new BotAI and use the OnTimerTick method that exists withing instead of creating new threads.

arqIc4f0SSmBj-ld4C0hEQ.png
 
Last edited:

Users who are viewing this thread

Top