How about this then.
Console command npccountall will send "X Bots are active!" to all players that are alive and not asleep.
Chat command /npccount will send that message just to the person that sent the request.
They will need to have permission ChatNPCCounter.use since its not a command you want to use often because it could be used to spam the server with.
using System.Collections.Generic;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("NPC Counter", "bmgjet", "1.0.0")]
public class ChatNPCCounter : RustPlugin
{
#region Initialization
private const string permCount = "ChatNPCCounter.use";
private void Init()
{
permission.RegisterPermission(permCount, this);
lang.RegisterMessages(new Dictionary<string, string>
{
["NPCMessage"] = "{0} Bots are active!"
}, this);
}
#endregion
#region Commands
[ChatCommand("npccount")]
private void DoCount(BasePlayer player)
{
if (player.IPlayer.HasPermission(permCount)){ player.ChatMessage(string.Format(lang.GetMessage("NPCMessage", this, player.IPlayer.Id), CountNPCs().ToString())); }
}
[ConsoleCommand("npccountall")]
private void Cmd2(ConsoleSystem.Arg arg)
{
if (arg.IsAdmin)
{
Broadcast("NPCMessage", CountNPCs().ToString());
}
}
#endregion
#region Helpers
public int CountNPCs()
{
Dictionary<ulong, Vector3> NPCPlayers = new Dictionary<ulong, Vector3>();
foreach (var npcs in GameObject.FindObjectsOfType<NPCPlayerApex>())
{
if (!NPCPlayers.ContainsKey(npcs.userID))
NPCPlayers.Add(npcs.userID, npcs.transform.position);
}
foreach (var npcs in GameObject.FindObjectsOfType<HumanNPC>())
{
if (!NPCPlayers.ContainsKey(npcs.userID))
NPCPlayers.Add(npcs.userID, npcs.transform.position);
}
foreach (var npcs in GameObject.FindObjectsOfType<HumanNPCNew>())
{
if (!NPCPlayers.ContainsKey(npcs.userID))
NPCPlayers.Add(npcs.userID, npcs.transform.position);
}
foreach (var npcs in GameObject.FindObjectsOfType<ScientistNPC>())
{
if (!NPCPlayers.ContainsKey(npcs.userID))
NPCPlayers.Add(npcs.userID, npcs.transform.position);
}
foreach (var npcs in GameObject.FindObjectsOfType<ScientistNPCNew>())
{
if (!NPCPlayers.ContainsKey(npcs.userID))
NPCPlayers.Add(npcs.userID, npcs.transform.position);
}
foreach (var npcs in GameObject.FindObjectsOfType<NPCMurderer>())
{
if (!NPCPlayers.ContainsKey(npcs.userID))
NPCPlayers.Add(npcs.userID, npcs.transform.position);
}
foreach (var npcs in GameObject.FindObjectsOfType<NPCPlayer>())
{
if (!NPCPlayers.ContainsKey(npcs.userID))
NPCPlayers.Add(npcs.userID, npcs.transform.position);
}
return NPCPlayers.Count;
}
private void Broadcast(string key, params object[] args)
{
foreach (var player in BasePlayer.allPlayerList)
{
if (player.IsAlive() && !player.IsSleeping())
{
player.ChatMessage(string.Format(lang.GetMessage(key, this, player.IPlayer.Id), args));
}
}
}
#endregion
}
}