Raised This Month: $12 Target: $400
 3% 

Help | Trying to remove item from menu


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
SynysteR
Junior Member
Join Date: Sep 2012
Old 02-17-2017 , 09:30   Help | Trying to remove item from menu
Reply With Quote #1

Hey, i am trying to make a command that will make admins have the option to be invisible in the !admins command, the thing is, if i type !admins 0, the menu will still remember my name because it put it there when i was on !admins 1 (default), i want to remove my name when i change to invisible but i dont really know how to do it, would love some help
Code:
#include <sourcemod>
#include <cstrike>
#include <sdktools>
#pragma semicolon 1

new Handle:g_adminListEnable = INVALID_HANDLE;
new Handle:AdminMenu = INVALID_HANDLE;
new Handle:ClientMenu = INVALID_HANDLE;

new count=0;
new check[MAXPLAYERS+1]={1,...};

public Plugin:myinfo =
{
	name = "Admins List",
	author = "Kyubi",
	description = "Shows a menu of online admins",
	version = "1.0"
}

public OnPluginStart()
{
	/*
		Regs
	*/
	RegConsoleCmd("sm_admins", Command_Admins);
	RegAdminCmd("sm_check", Command_Check, ADMFLAG_GENERIC);
	
	/*
		ConVars
	*/
	g_adminListEnable = CreateConVar("sm_enableadmins", "1", "Wether the admins menu works or not");
	AutoExecConfig(true);
}

public Action:Command_Admins(client, args)
{
	if(GetConVarInt(g_adminListEnable) == 1)
	{
		new String:arg1[32];
		GetCmdArg(1, arg1, sizeof(arg1));
		
		if(IsAdmin(client))
		{
			if(StrEqual(arg1, "0"))
			{
				check[client] = 0;
			}
			else if(StrEqual(arg1, "1"))
			{
				check[client] = 1;
			}
		}

		if(args <1)
		{
			AdminMenu = CreateMenu(AdminsMenu);
			ClientMenu = CreateMenu(ClientsMenu);
			SetMenuTitle(AdminMenu, "Admins Online:");
			SetMenuTitle(ClientMenu, "Admins Online:");
			
		
			for(new i = 1; i<MaxClients; i++)
			{
				if(IsClientInGame(i))
				{
					new AdminId:AdminID = GetUserAdmin(i);
					new AdminRoot = GetAdminFlags(AdminID, Access_Real);

					if(AdminID != INVALID_ADMIN_ID)
					{
						if(AdminRoot != ADMFLAG_ROOT)
						{
							decl String:AdminName[MAX_NAME_LENGTH];
							decl String:menuadmin[MAX_NAME_LENGTH];
							GetClientName(i, AdminName, sizeof(AdminName));
							Format(menuadmin, sizeof(menuadmin), "(Invisible) %s",AdminName);
							if(check[i] == 1)
							{
								AddMenuItem(AdminMenu, AdminName, AdminName, ITEMDRAW_DISABLED);
								AddMenuItem(ClientMenu, AdminName, AdminName, ITEMDRAW_DISABLED);
								count = 1;
							}
							if(check[i] == 0)
							{
								AddMenuItem(AdminMenu, menuadmin, menuadmin, ITEMDRAW_DISABLED);
								count = 1;
							}
						}
					}
				}
			}
			if(count ==0)
			{	
				AddMenuItem(AdminMenu,"","No Admins Online.", ITEMDRAW_DISABLED);
				AddMenuItem(ClientMenu, "", "No Admins Online.", ITEMDRAW_DISABLED);
			}
		
			if(IsAdmin(client))
			{
				DisplayMenu(AdminMenu, client, MENU_TIME_FOREVER);
				SetMenuExitButton(AdminMenu, true);
			}
			else
			{
				DisplayMenu(ClientMenu, client, MENU_TIME_FOREVER);
				SetMenuExitBackButton(ClientMenu, true);
			}
			count=0;
		}
	}
	return Plugin_Handled;
}

public AdminsMenu(Handle:menu, MenuAction:action, param1, param2)
{

}

public ClientsMenu(Handle:menu, MenuAction:action, param1, param2)
{

}

bool:IsAdmin(client)
{
	if (CheckCommandAccess(client, "sm_admin", 2, false))
	{
		return true;
	}
	return false;
}

public Action:Command_Check(client, args)
{
	if(check[client] == 1)
		PrintToChat(client, "check = 1");
	if(check[client] == 0)
		PrintToChat(client, "check = 0");
}
SynysteR is offline
OSWO
Senior Member
Join Date: Jul 2015
Location: United Kingdom, London
Old 02-17-2017 , 09:40   Re: Help | Trying to remove item from menu
Reply With Quote #2

So you want a Menu for users to show Admins currently online? But you want the option for Admins to "Hide" themself from that Menu too?
__________________
SourceTimer | WeaponSkins++ | BasePlugins++ https://github.com/OSCAR-WOS
OSWO is offline
SynysteR
Junior Member
Join Date: Sep 2012
Old 02-17-2017 , 09:43   Re: Help | Trying to remove item from menu
Reply With Quote #3

Quote:
Originally Posted by OSWO View Post
So you want a Menu for users to show Admins currently online? But you want the option for Admins to "Hide" themself from that Menu too?
yes exactly
SynysteR is offline
OSWO
Senior Member
Join Date: Jul 2015
Location: United Kingdom, London
Old 02-17-2017 , 09:48   Re: Help | Trying to remove item from menu
Reply With Quote #4

Give me 10 minutes, I'll get something written for you
__________________
SourceTimer | WeaponSkins++ | BasePlugins++ https://github.com/OSCAR-WOS
OSWO is offline
SynysteR
Junior Member
Join Date: Sep 2012
Old 02-17-2017 , 09:49   Re: Help | Trying to remove item from menu
Reply With Quote #5

Quote:
Originally Posted by OSWO View Post
Give me 10 minutes, I'll get something written for you
Thanks, however im doing this just for the sake of learning, so i would love some help with my code
SynysteR is offline
OSWO
Senior Member
Join Date: Jul 2015
Location: United Kingdom, London
Old 02-17-2017 , 10:08   Re: Help | Trying to remove item from menu
Reply With Quote #6

If there's something not working, or you want changed, let me know. I tried to comment everything possible.

PHP Code:
#pragma semicolon 1
#pragma newdecls required

#define PLUGIN_AUTHOR "Oscar Wos (OSWO)"
#define PLUGIN_VERSION "1.00"

#include <sourcemod>

ConVar gCn_Enabled;

bool gB_Invisible[MAXPLAYERS 1];

public 
Plugin myinfo =
{
    
name "Show Admins",
    
author PLUGIN_AUTHOR,
    
description "Admin Menu - Requested by (SynysteR)",
    
version PLUGIN_VERSION,
    
url "https://steamcommunity.com/id/oswo"
};

public 
void OnClientPostAdminCheck(int I_Client) {
    
//Reseting Variables
    
ResetVariables(I_Client);
}

public 
void OnClientDisconnect(int I_Client) {
    
//Reseting Variables
    
ResetVariables(I_Client);
}

public 
void OnPluginStart() {
    
//Registering The Command
    
RegConsoleCmd("sm_admins"Command_Admins"Show Avaliable Admins Online");

    
//ConVar Management
    
gCn_Enabled CreateConVar("showadmins_enable""1""Enables the Show Admins Menu"_true0.00true1.00);
    
AutoExecConfig(true"showadmins");
}

public 
Action Command_Admins(int I_Clientint I_Args) {
    if (
gCn_Enabled.BoolValue) {
        
MainMenu(I_Client);
    }

    return 
Plugin_Handled;
}

public 
int AdminsMenuHandle(Menu M_MenuMenuAction mA_Actionint I_Param1int I_Param2) {
    if (
mA_Action == MenuAction_Select) {
        if (
I_Param2 == 0) {
            if (
CheckCommandAccess(I_Param1""ADMFLAG_GENERICtrue)) {
                
gB_Invisible[I_Param1] = !gB_Invisible[I_Param1];

                
PrintToChat(I_Param1"[\x07Admin\x01] Invisibility Now: %s", (gB_Invisible[I_Param1] ? "\x06Invisible" "\x07Visable"));
                
MainMenu(I_Param1);
            }
        }
    }
}

void MainMenu(int I_Client) {
    
char C_buffer[512];
    
Menu M_Menu = new Menu(AdminsMenuHandle);
    
bool B_RootUser;

    
//Clean Title
    
FormatEx(C_buffersizeof(C_buffer), "Show Admins\n");
    
FormatEx(C_buffersizeof(C_buffer), "%s \n"C_buffer);
    
M_Menu.SetTitle(C_buffer);

    
B_RootUser CheckCommandAccess(I_Client""ADMFLAG_ROOTtrue);

    
//No need to grab AdminID, etc.
    
if (CheckCommandAccess(I_Client""ADMFLAG_GENERICtrue)) {
        
FormatEx(C_buffersizeof(C_buffer), "Toggle Invisibility - Currently: %s", (gB_Invisible[I_Client]) ? "Invisible" "Visable");
        
M_Menu.AddItem(C_bufferC_buffer);
    }

    
//Loop and Check Admins + If they're Invisible
    
for (int i 1<= MaxClientsi++) {
        if (
IsValidClient(i)) {
            if (
CheckCommandAccess(i""ADMFLAG_GENERICtrue)) {
                if (
B_RootUser && gB_Invisible[i]) {
                    
FormatEx(C_buffersizeof(C_buffer), "%N (Invisible)"i);
                } else if (!
gB_Invisible[i]) {
                    
FormatEx(C_buffersizeof(C_buffer), "%N"i);
                }

                
M_Menu.AddItem(C_bufferC_bufferITEMDRAW_DISABLED);
            }
        }
    }

    
M_Menu.Display(I_Client0);
}

void ResetVariables(int I_Client) {
    
gB_Invisible[I_Client] = false;
}

stock bool IsValidClient(int I_Client) {
    if (
I_Client >= && (I_Client <= MaxClients) && IsValidEntity(I_Client) && IsClientConnected(I_Client) && IsClientInGame(I_Client) && !IsFakeClient(I_Client)) {
        return 
true;
    }

    return 
false;

Edit: I added a check if the Admin is a RootUser so it shows Invisible Admins to them.
__________________
SourceTimer | WeaponSkins++ | BasePlugins++ https://github.com/OSCAR-WOS

Last edited by OSWO; 02-17-2017 at 10:13. Reason: CheckCommandAccess Fix
OSWO is offline
SynysteR
Junior Member
Join Date: Sep 2012
Old 02-17-2017 , 10:15   Re: Help | Trying to remove item from menu
Reply With Quote #7

Quote:
Originally Posted by OSWO View Post
If there's something not working, or you want changed, let me know. I tried to comment everything possible.

PHP Code:
#pragma semicolon 1
#pragma newdecls required

#define PLUGIN_AUTHOR "Oscar Wos (OSWO)"
#define PLUGIN_VERSION "1.00"

#include <sourcemod>

ConVar gCn_Enabled;

bool gB_Invisible[MAXPLAYERS 1];

public 
Plugin myinfo =
{
    
name "Show Admins",
    
author PLUGIN_AUTHOR,
    
description "Admin Menu - Requested by (SynysteR)",
    
version PLUGIN_VERSION,
    
url "https://steamcommunity.com/id/oswo"
};

public 
void OnClientPostAdminCheck(int I_Client) {
    
//Reseting Variables
    
ResetVariables(I_Client);
}

public 
void OnClientDisconnect(int I_Client) {
    
//Reseting Variables
    
ResetVariables(I_Client);
}

public 
void OnPluginStart() {
    
//Registering The Command
    
RegConsoleCmd("sm_admins"Command_Admins"Show Avaliable Admins Online");

    
//ConVar Management
    
gCn_Enabled CreateConVar("showadmins_enable""1""Enables the Show Admins Menu"_true0.00true1.00);
    
AutoExecConfig(true"showadmins");
}

public 
Action Command_Admins(int I_Clientint I_Args) {
    if (
gCn_Enabled.BoolValue) {
        
MainMenu(I_Client);
    }

    return 
Plugin_Handled;
}

public 
int AdminsMenuHandle(Menu M_MenuMenuAction mA_Actionint I_Param1int I_Param2) {
    if (
mA_Action == MenuAction_Select) {
        if (
I_Param2 == 0) {
            if (
CheckCommandAccess(I_Param1""ADMFLAG_GENERICtrue)) {
                
gB_Invisible[I_Param1] = !gB_Invisible[I_Param1];

                
PrintToChat(I_Param1"[\x07Admin\x01] Invisibility Now: %s", (gB_Invisible[I_Param1] ? "\x06Invisible" "\x07Visable"));
                
MainMenu(I_Param1);
            }
        }
    }
}

void MainMenu(int I_Client) {
    
char C_buffer[512];
    
Menu M_Menu = new Menu(AdminsMenuHandle);

    
//Clean Title
    
FormatEx(C_buffersizeof(C_buffer), "Show Admins\n");
    
FormatEx(C_buffersizeof(C_buffer), "%s \n"C_buffer);
    
M_Menu.SetTitle(C_buffer);

    
//No need to grab AdminID, etc.
    
if (CheckCommandAccess(I_Client""ADMFLAG_GENERICtrue)) {
        
FormatEx(C_buffersizeof(C_buffer), "Toggle Invisibility - Currently: %s", (gB_Invisible[I_Client]) ? "Invisible" "Visable");
        
M_Menu.AddItem(C_bufferC_buffer);
    }

    
//Loop and Check Admins + If they're Invisible
    
for (int i 1<= MaxClientsi++) {
        if (
IsValidClient(i)) {
            if (
CheckCommandAccess(i""ADMFLAG_GENERICtrue) && !gB_Invisible[i]) {
                
FormatEx(C_buffersizeof(C_buffer), "%N"i);
                
M_Menu.AddItem(C_bufferC_bufferITEMDRAW_DISABLED);
            }
        }
    }

    
M_Menu.Display(I_Client0);
}

void ResetVariables(int I_Client) {
    
gB_Invisible[I_Client] = false;
}

stock bool IsValidClient(int I_Client) {
    if (
I_Client >= && (I_Client <= MaxClients) && IsValidEntity(I_Client) && IsClientConnected(I_Client) && IsClientInGame(I_Client) && !IsFakeClient(I_Client)) {
        return 
true;
    }

    return 
false;

Thank you very much for your time and effort, im sure it will work great, but could you possibly help me with my code? it's not a plugin that i need, im just building it for the sake of challenge and learning.

i would like to know how can i make my code work (probably by removing the admin from the menu if he wrote !admins 0, however i dont know how to do it).

Last edited by SynysteR; 02-17-2017 at 10:15.
SynysteR is offline
OSWO
Senior Member
Join Date: Jul 2015
Location: United Kingdom, London
Old 02-17-2017 , 10:17   Re: Help | Trying to remove item from menu
Reply With Quote #8

The best way of learning (for me) is through reading other peoples code. That has been the most effective way of learning for me. You can pick up tricks, and easier methods like that.
__________________
SourceTimer | WeaponSkins++ | BasePlugins++ https://github.com/OSCAR-WOS

Last edited by OSWO; 02-17-2017 at 10:17.
OSWO is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 08:32.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode