Coding Plus Emu Features / Commands

Status
Not open for further replies.

Jerry

not rly active lol
Jul 8, 2013
1,956
522
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Plus.Database.Interfaces;
using System.Data;

namespace Plus.HabboHotel.Rooms.Chat.Commands.Moderator.Fun
{
    class UsersOnlineCommand : IChatCommand
    {
        public string PermissionRequired
        {
            get { return "command_usersonline"; }
        }
        public string Parameters
        {
            get { return ""; }
        }
        public string Description
        {
            get { return "Displays the current users online"; }
        }
        public void Execute(GameClients.GameClient Session, Rooms.Room Room, string[] Params)
        {
            string Output = "Current Users Online:\r";
            Output += "-----------------------\r";

            using (IQueryAdapter Adapter = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                Adapter.SetQuery("SELECT username FROM users WHERE online = '1'");
                Adapter.RunQuery();

                DataTable Table = Adapter.getTable();

                if (Table != null)
                {
                    foreach (DataRow Row in Table.Rows)
                    {
                        Output += Row["Username"].ToString() + "\r";
                    }
                }
                else
                {
                    Output += "There must be hidden users online!";
                }
            }
            Session.SendNotification(Output);
        }
    }
}
Y use queries when you can just use LINQ? Great service, btw.
 
May 1, 2015
467
152
I did the afk command for you. I'm going to let you do the :back command since it's pretty easy and the opposite of this minus the sleep composer and setting the IsAsleep & IsBrb to false.
I only added the IsBrb so you can use it and disable the user from gaining credits while away.
Set the applyeffect to 0 when coding the back command.
Code:
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;
using Plus.Communication.Packets.Outgoing.Rooms.Avatar;
using Plus.HabboHotel.Rooms;
using Plus.HabboHotel.Items;

using Plus.Communication.Packets.Outgoing.Rooms.Chat;

using Plus.Communication.Packets.Outgoing.Inventory.Furni;
using Plus.Database.Interfaces;

namespace Plus.HabboHotel.Rooms.Chat.Commands.User
{
    class AfkCommand : IChatCommand
    {
        public string PermissionRequired
        {
            get { return "command_afk"; }
        }

        public string Parameters
        {
            get { return ""; }
        }

        public string Description
        {
            get { return "Go AFK"; }
        }

        public void Execute(GameClients.GameClient Session, Rooms.Room Room, string[] Params)
        {
            RoomUser User = Room.GetRoomUserManager().GetRoomUserByHabbo(Session.GetHabbo().Id);
            User.IsAsleep = true;
            User.GetClient().GetHabbo().IsBrb = true;
            Room.SendMessage(new SleepComposer(User, true));
            User.ApplyEffect(187);
            Room.SendMessage(new ShoutComposer(User.VirtualId, "* " + Session.GetHabbo().Username + "  is now AFK! *", 1, User.LastBubble));
        }
    }
}
 

Jerry

not rly active lol
Jul 8, 2013
1,956
522
What are the benefits of using LINQ expressions? Never used them before.
Don't know how to exactly word this, but the benefits of using LINQ expressions are that:
  • The performance are better than SQL queries.
  • You can get the keys and values stored directly from the dictionary (or concurrent dictionary) without using mysql queries.
  • Using LINQ over SQL queries can speed up the SQL server because relying on SQL queries too much may overload the SQL server, especially if there's a lot of visitors.
Basically, LINQ is like getting stored or cached data from a dictionary. Here's an example of the :eek:nline command in LINQ (it doesn't use sql queries):
e7a8602e63d94c7ca7c1592d9f0851d3.png

adcad7d77ffd4422b7acf8c75d82cbd5.png


If you have a table that isn't cached in the emulator, then you may create a list and store the data to it, here's an example:
7c2bd513b3fb4e82904bcfe90f211a60.png


And how the list is being used:
d9cd4667fdc24813a13326d52a7e02b9.png


It's best that you use LINQ more often because it can speed up both the emulator and mysql server. I tried, if somebody has a better explanation, then feel free to correct my post.
 

CosmoPeak

PeakRP.com
May 15, 2016
271
268
The point isn't to "use LINQ", but to not access the database for everything. Accessing the database is slow. Accessing a variable (dictionary/list/whatever) will always be much faster and on most occasions, there will be classes or mechanisms in Plus to handle DB calls for you. LINQ doesn't actually have any effect here.

For example, getting users, groups, rooms, etc should be handled by the manager classes, as they cache what is returned and you get a proper GameClient/Group/Room object. The same goes for getting offline Habbos with Plus.getHabboById. The result is cached (if the same user is called for again, it won't need to access the database a second time) and you get a proper Habbo object which is much easier to use.
 
Jan 7, 2016
194
15
Event alert is coded in R2 or are you using R1?
 
Code:
this.Register("eventalert", new EventAlertCommand());
Add this under moderators in HabboHotel\Rooms\Chat\Commands\CommandManager under the rank you would like to do so and under the events folder, Copy "EventAlertCommand.cs" to the ranks you want it under e.g. HabboHotel\Rooms\Chat\Commands\Moderator and so on.
 

Platinum

Hello!
Sep 2, 2012
295
282
@Velaski I remember you doing this bro, maybe you both can give this a shot perhaps

Command: Translator

Purpose: You choose language you want to translate to, then you type in the chat in english and it automatically translates to whatever language you chose.
 

Velaski

winner
Aug 4, 2015
562
165
@Velaski I remember you doing this bro, maybe you both can give this a shot perhaps

Command: Translator

Purpose: You choose language you want to translate to, then you type in the chat in english and it automatically translates to whatever language you chose.
I'll find the emulator I put it in when I get home. It's in HoloRP EMU aswell so credits to @Jerry. It's hard to implement for some people but I'll do a step tutorial for it.
 

HolaBox

New Member
Feb 20, 2017
27
2
For your online users command, if the hotel has a lot of users online it will cause problems with the notification due to it being a static height. If you want the online user list to be in a scrollable form you can change line 49 from:

Session.SendNotification(Output);
-to-
Session.SendPacket(new MOTDNotificationComposer(Output));

You will also need to include this line below the others at the top of the page:
using Plus.Communication.Packets.Outgoing.Notifications;

Mine didn't seem to like the 'SendPacket' part :(

Coded this pay command for Hobba Hotel, they didn't use it so here you go it's nothing special.
Code:
* code removed *

Works like a charm, many thanks for sharing!

My pay command, figured I'd release.
Code:
* removed *

I was going to use your version as it tells them they received x from x, but..

Severity Code Description Project File Line Suppression State Error CS1061 'RoomUserManager' does not contain a definition for 'GetRoomUserByUsername' and no extension method 'GetRoomUserByUsername' accepting a first argument of type 'RoomUserManager' could be found (are you missing a using directive or an assembly reference?).
 
Jan 7, 2016
194
15
Room.SendPacket("Ass") is a way for R2 to get the message sent when a command is ran, so if it does that change SendPacket to .SendMessage if you are using R1. I've converted a few commands from R1 to R2 due to the fact R2 uses packets for messages in commands.
 
@HolaBox Let me know which version of the emulator you are using and I'll re-code it to work for your version.
 
Status
Not open for further replies.

Users who are viewing this thread

Top