PHP Code:
#include <sourcemod>
#include <morecolors>
#pragma newdecls required
#pragma semicolon 1
#define ADMIN_FLAG ADMFLAG_CUSTOM1 // set your flag here
#define ADMIN_FLAG2 Admin_Custom1 // set your flag here
bool admin_show_online[MAXPLAYERS + 1] = {false, ...};
public Plugin myinfo = {
name = "Show admins",
author = "Donatello4620",
description = "Shows online admins.",
version = "1.0"
};
public void OnPluginStart() {
RegConsoleCmd("sm_admins", cmd_admins, "List online admins.");
RegAdminCmd("sm_adminshowonline", cmd_toggleadminshowonline, ADMIN_FLAG, "Toggle online status on admin list.");
if (GetClientCount(true) > 0) {
for (int i = 1; i <= MaxClients; i++) {
if (IsClientConnected(i)) {
OnClientPostAdminCheck(i);
}
}
}
}
public void OnClientPostAdminCheck(int client)
{
if (GetAdminFlag(GetUserAdmin(client), ADMIN_FLAG2, Access_Effective) && !admin_show_online[client])
{
admin_show_online[client] = true;
}
}
public void OnClientDisconnect(int client)
{
if (admin_show_online[client])
{
admin_show_online[client] = false;
}
}
public Action cmd_toggleadminshowonline(int client, int args) {
if (!client) {
ReplyToCommand(client, ">> You can only use this command in-game!");
return Plugin_Handled;
}
toggle_admin_show_online_status(client);
return Plugin_Handled;
}
void toggle_admin_show_online_status(int client) {
if (admin_show_online[client]) {
admin_show_online[client] = false;
CReplyToCommand(client, "{ORANGE}>> You are now {RED}hidden {ORANGE}from the online admins list.");
LogAction(client, -1, "\"%L\" hid his/herself from the admin list", client);
} else {
admin_show_online[client] = true;
CReplyToCommand(client, "{ORANGE}>> You are now {GREEN}visible {ORANGE}from the online admins list");
LogAction(client, -1, "\"%L\" made his/herself visible from the admin list", client);
}
}
public Action cmd_admins(int client, int args) {
if (!client) {
ReplyToCommand(client, ">> This command only works in-game.");
return Plugin_Handled;
}
open_admins_menu(client);
LogAction(client, -1, "\"%L\" used sm_admins", client);
return Plugin_Handled;
}
void open_admins_menu(int client) {
Menu main_menu = new Menu(admin_list);
char admin_name[MAX_NAME_LENGTH];
main_menu.SetTitle("Online Admins");
for (int i = 1; i <= MaxClients; i++) {
if ((IsClientConnected(i) && GetAdminFlag(GetUserAdmin(i), ADMIN_FLAG2, Access_Effective)) && admin_show_online[i]) {
Format(admin_name, sizeof(admin_name), "%N", i);
main_menu.AddItem("x", admin_name, ITEMDRAW_DISABLED);
}
}
if (!GetMenuItemCount(main_menu)) {
main_menu.AddItem("x", "No admins online!", ITEMDRAW_DISABLED);
}
main_menu.ExitButton = true;
main_menu.Display(client, MENU_TIME_FOREVER);
}
public int admin_list(Menu menu, MenuAction action, int param1, int param2){
if (action == MenuAction_End) {
delete menu;
}
}
Feel free to use in your plugins, don't need to give me credit or anything. (Would be appreciated though :ppp)
Works with latest Sourcemod build (Tested on TF2 only)
Code may not be the best/messy but no errors on compiling whatsoever