View Single Post
Author Message
Donatello4620
New Member
Join Date: Jul 2018
Old 08-22-2018 , 16:15   [TF2/ANY?] Online admin list concept
Reply With Quote #1

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_toggleadminshowonlineADMIN_FLAG"Toggle online status on admin list.");

    if (
GetClientCount(true) > 0) {
        for (
int i 1<= MaxClientsi++) {
            if (
IsClientConnected(i)) {
                
OnClientPostAdminCheck(i);
            }
        }
    }
}

public 
void OnClientPostAdminCheck(int client)
{
    if (
GetAdminFlag(GetUserAdmin(client), ADMIN_FLAG2Access_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 clientint 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 clientint 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<= MaxClientsi++) {
        if ((
IsClientConnected(i) && GetAdminFlag(GetUserAdmin(i), ADMIN_FLAG2Access_Effective)) && admin_show_online[i]) {
            
Format(admin_namesizeof(admin_name), "%N"i);
            
main_menu.AddItem("x"admin_nameITEMDRAW_DISABLED);
        }
    }
    if (!
GetMenuItemCount(main_menu)) {
        
main_menu.AddItem("x""No admins online!"ITEMDRAW_DISABLED);
    }

    
main_menu.ExitButton true;

    
main_menu.Display(clientMENU_TIME_FOREVER);
}

public 
int admin_list(Menu menuMenuAction actionint param1int 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

Last edited by Donatello4620; 08-23-2018 at 16:39.
Donatello4620 is offline