Simple UserlistSolved

I've tried to create a very simple Userlist. I got the Userlist but including the steam-id.

Players (1): Dr.D.Bug[xxxxxxxxxxxxxxxx]

What shall i change to get only the UserName?

void player(BasePlayer player)
{
List<BasePlayer> list = BasePlayer.activePlayerList.ToList();
SendMessage(player, "Players ({0}): {1}", list.Count, string.Join(", ", list));
}

Sorry for that simple question ;-)

 

You'd need to get the userID and displayName form the BasePlayer rather than just making the whole player a string.

This is what i used hope this can get you closer to your goal:::::

using System.Text;​


[Command("playerlist")]
        private void plCommand(IPlayer iplayer, string command, string[] args)
        {
            var player = iplayer.Object as BasePlayer;
            StringBuilder stringBuilder = new StringBuilder();
            var count = 1;
            foreach (var p in BasePlayer.activePlayerList)
            {
                if(p.net.connection.authLevel == 2)
                {
                    stringBuilder.AppendLine($"{count}: <color=purple>(OWNER)</color> <color=green>{p.displayName}</color>");
                    count++;
                }
                else
                {
                    if (p.net.connection.authLevel == 1)
                    {
                        stringBuilder.AppendLine($"{count}: <color=purple>(ADMIN)</color> <color=green>{p.displayName}</color>");
                        count++;
                    }
                    else
                    {
                        if (p.IPlayer.BelongsToGroup("")) //if you have mod groups
                        { 
                            stringBuilder.AppendLine($"{count}: <color=purple>(MOD)</color> <color=green>{p.displayName}</color>"); 
                            count++;
                        }
                        else
                        {
                            stringBuilder.AppendLine($"{count}: <color=green>{p.displayName}</color>");
                            count++;
                        }
                    }
                }
            }
            PrintPluginMessageToChat(player, stringBuilder.ToString());
            
        }​

it outputs to chat list of all active players
so you could use BasePlayer.FindAwakeOrSleeping() to get all players or BasePlayer.allPlayerList


Edit : If you use RustAdmin , dont use [Command("playerlist")]
bc RustAdmin uses that in console for there list and then breaks RustAdmin's Playerlist.
so rather use [Command("players")]



Merged post

 private void PrintPluginMessageToChat(BasePlayer player, string message)
        {
            player.ChatMessage("<b><size=16>[<color=#ffa500ff>" + this.Name + "</color>]</size></b>\n" + message);
        }

forgot this is my method to print to chat

Thanks Wulf, thanks NooBlet, it helped me to understand a lot more. This is now my simple code. Shurely not perfect but working ;-) Any comments or improvements?

        void SendMessage(BasePlayer player, string msg, params object[] args)
        {
            PrintToChat(player, msg, args);
        }

        [ChatCommand("players")]
        void Players(BasePlayer player)
        {
            char[] separator = {',', ' '};
            activplayers.Clear();
            StringBuilder sb = new StringBuilder();
            List<BasePlayer> list = BasePlayer.activePlayerList.ToList();
            sb.Append($"Players online({list.Count}): ");
            for (int i = 0; i < list.Count; i++)
            {
                BasePlayer basePlayer = list[i];
                sb.Append($" {basePlayer.displayName},");
            }
            SendMessage(player, sb.ToString().TrimEnd(separator));
        }
Locked automatically