Raised This Month: $32 Target: $400
 8% 

grey out menu entries


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
napster_10
Senior Member
Join Date: May 2016
Old 05-23-2019 , 12:03   grey out menu entries
Reply With Quote #1

hi,

how can i grey out menu entries with a custom flag?

so if you dont have the flag for certain commands in the menu, it will be still showen but not clickable!
napster_10 is offline
Kolapsicle
Senior Member
Join Date: Oct 2014
Old 05-23-2019 , 12:33   Re: grey out menu entries
Reply With Quote #2

You can find menu defines in the menus.inc file.

Code:
#define ITEMDRAW_DEFAULT		(0)		/**< Item should be drawn normally */
#define ITEMDRAW_DISABLED		(1<<0)	/**< Item is drawn but not selectable */
#define ITEMDRAW_RAWLINE		(1<<1)	/**< Item should be a raw line, without a slot */
#define ITEMDRAW_NOTEXT			(1<<2)	/**< No text should be drawn */
#define ITEMDRAW_SPACER			(1<<3)	/**< Item should be drawn as a spacer, if possible */
#define ITEMDRAW_IGNORE	((1<<1)|(1<<2))	/**< Item should be completely ignored (rawline + notext) */
#define ITEMDRAW_CONTROL		(1<<4)	/**< Item is control text (back/next/exit) */
PHP Code:
Menu.AddItem("info""display"ITEMDRAW_DISABLED); 
Kolapsicle is offline
napster_10
Senior Member
Join Date: May 2016
Old 05-23-2019 , 12:45   Re: grey out menu entries
Reply With Quote #3

ok nice thx and how can i check for flags?
napster_10 is offline
Kolapsicle
Senior Member
Join Date: Oct 2014
Old 05-23-2019 , 13:01   Re: grey out menu entries
Reply With Quote #4

Using GetUserAdmin to return an AdminId methodmap, you can check for AdminFlag's with HasFlag. The second parameter, AdmAccessMode let's you determine if the client has a particular flag, or gets the flag from a group.

PHP Code:
Menu.AddItem("info""display"GetUserAdmin(client).HasFlag(Admin_ReservationAccess_Real) ? ITEMDRAW_DEFAULT ITEMDRAW_DISABLED); 

Last edited by Kolapsicle; 05-23-2019 at 13:17.
Kolapsicle is offline
napster_10
Senior Member
Join Date: May 2016
Old 05-23-2019 , 18:08   Re: grey out menu entries
Reply With Quote #5

ok thx that helps alot but maan i'm so overchallenged right now haha

what i want to do is to add a flag for certain commands in a config file from which a menu gets build

so the cfg is like that:
PHP Code:
"Donor"
{
    
"Graffitis"
    
{
        
"items"
        
{
            
"sm_sprays" "!sprays - Choose a graffiti"
        
}
    }
    
"Chatcolors and Chattag"
    
{
        
"items"
        
{
            
"sm_changetag" "!changetag - Change your Tag"
            "sm_colors" "!colors - Change your Tag-Name-Chat-color"
        
}
    }

i need to add a flag like this:

PHP Code:
"Donor"
{
    
"Graffitis"
    
{
        
"items"
        
{
            
"sm_sprays" "!sprays - Choose a graffiti" "Admin_Custom3"
        
}
    }
    
"Chatcolors and Chattag"
    
{
        
"items"
        
{
            
"sm_changetag" "!changetag - Change your Tag" "Admin_Custom4"
            "sm_colors" "!colors - Change your Tag-Name-Chat-color" "Admin_Custom3"
        
}
    }


then somewhere in this parser section i need to read out the flag but i have no idea where and how -.-

PHP Code:
public OnMapStart() {
    new 
String:hc[PLATFORM_MAX_PATH];
    
BuildPath(Path_SMhcsizeof(hc), "configs/donors.cfg");
    
ParseConfigFile(hc);
}

bool:ParseConfigFile(const String:file[]) {
    if (
g_DonorMenus != INVALID_HANDLE) {
        
ClearArray(g_DonorMenus);
        
CloseHandle(g_DonorMenus);
        
g_DonorMenus INVALID_HANDLE;
    }

    new 
Handle:parser SMC_CreateParser();
    
SMC_SetReaders(parserConfig_NewSectionConfig_KeyValueConfig_EndSection);
    
SMC_SetParseEnd(parserConfig_End);

    new 
line 0;
    new 
col 0;
    new 
String:error[128];
    new 
SMCError:result SMC_ParseFile(parserfilelinecol);
    
CloseHandle(parser);

    if (
result != SMCError_Okay) {
        
SMC_GetErrorString(resulterrorsizeof(error));
        
LogError("%s on line %d, col %d of %s"errorlinecolfile);
    }

    return (
result == SMCError_Okay);
}

public 
SMCResult:Config_NewSection(Handle:parser, const String:section[], bool:quotes) {
    
g_configLevel++;
    if (
g_configLevel == 1) {
        new 
hmenu[DonorMenu];
        
strcopy(hmenu[dname], sizeof(hmenu[dname]), section);
        
hmenu[items] = CreateDataPack();
        
hmenu[itemct] = 0;
        if (
g_DonorMenus == INVALID_HANDLE)
            
g_DonorMenus CreateArray(sizeof(hmenu));
        
PushArrayArray(g_DonorMenushmenu[0]);
    }
    return 
SMCParse_Continue;
}

public 
SMCResult:Config_KeyValue(Handle:parser, const String:key[], const String:value[], bool:key_quotesbool:value_quotes) {
    new 
msize GetArraySize(g_DonorMenus);
    new 
hmenu[DonorMenu];
    
GetArrayArray(g_DonorMenusmsize-1hmenu[0]);
    switch (
g_configLevel) {
        case 
1: {
            if(
strcmp(key"title"false) == 0)
                
strcopy(hmenu[title], sizeof(hmenu[title]), value);
            if(
strcmp(key"type"false) == 0) {
                if(
strcmp(value"text"false) == 0)
                    
hmenu[type] = DonorMenuType_Text;
                else
                    
hmenu[type] = DonorMenuType_List;
            }
        }
        case 
2: {
            
WritePackString(hmenu[items], key);
            
WritePackString(hmenu[items], value);
            
hmenu[itemct]++;
        }
    }
    
SetArrayArray(g_DonorMenusmsize-1hmenu[0]);
    return 
SMCParse_Continue;
}
public 
SMCResult:Config_EndSection(Handle:parser) {
    
g_configLevel--;
    if (
g_configLevel == 1) {
        new 
hmenu[DonorMenu];
        new 
msize GetArraySize(g_DonorMenus);
        
GetArrayArray(g_DonorMenusmsize-1hmenu[0]);
        
ResetPack(hmenu[items]);
    }
    return 
SMCParse_Continue;
}

public 
Config_End(Handle:parserbool:haltedbool:failed) {
    if (
failed)
        
SetFailState("DonorMenu: Plugin Configuration Error");

then i need to do the if statement in here i guess marked with ////////////////////////////

PHP Code:
public Help_MainMenuHandler(Handle:menuMenuAction:actionparam1param2) {
    if (
action == MenuAction_End) {
        
CloseHandle(menu);
    } else if (
action == MenuAction_Select) {
        new 
msize GetArraySize(g_DonorMenus);
        if (
param2 == msize) { // Admins
            
new Handle:adminMenu CreateMenu(Help_MenuHandler);
            
SetMenuExitBackButton(adminMenutrue);
            
SetMenuTitle(adminMenu"Online Admins\n ");
            new 
maxc GetMaxClients();
            new 
String:aname[64];
            for (new 
1maxc; ++i) {
                if (
IsClientConnected(i) && IsClientInGame(i) && !IsFakeClient(i) && (GetUserFlagBits(i) & ADMFLAG_GENERIC) == ADMFLAG_GENERIC) {
                    
GetClientName(ianamesizeof(aname));
                    
AddMenuItem(adminMenuanameanameITEMDRAW_DISABLED);
                }
            }
            
DisplayMenu(adminMenuparam130);
        } else { 
// Menu from config file
            
if (param2 <= msize) {
                new 
hmenu[DonorMenu];
                
GetArrayArray(g_DonorMenusparam2hmenu[0]);
                new 
String:mtitle[512];
                
Format(mtitlesizeof(mtitle), "%s\n "hmenu[title]);
                if (
hmenu[type] == DonorMenuType_Text) {
                    new 
Handle:cpanel CreatePanel();
                    
SetPanelTitle(cpanelmtitle);
                    new 
String:text[128];
                    new 
String:junk[128];
                    for (new 
0hmenu[itemct]; ++i) {
                        
ReadPackString(hmenu[items], junksizeof(junk));
                        
ReadPackString(hmenu[items], textsizeof(text));
                        
DrawPanelText(cpaneltext);
                    }
                    for (new 
07; ++j)
                        
DrawPanelItem(cpanel" "ITEMDRAW_NOTEXT);
                    
DrawPanelText(cpanel" ");
                    
DrawPanelItem(cpanel"Back"ITEMDRAW_CONTROL);
                    
DrawPanelItem(cpanel" "ITEMDRAW_NOTEXT);
                    
DrawPanelText(cpanel" ");
                    
DrawPanelItem(cpanel"Exit"ITEMDRAW_CONTROL);
                    
ResetPack(hmenu[items]);
                    
SendPanelToClient(cpanelparam1Help_MenuHandler30);
                    
CloseHandle(cpanel);
                } else {
                    new 
Handle:cmenu CreateMenu(Help_CustomMenuHandler);
                    
SetMenuExitBackButton(cmenutrue);
                    
SetMenuTitle(cmenumtitle);
                    new 
String:cmd[128];
                    new 
String:desc[128];
                    for (new 
0hmenu[itemct]; ++i) {
                        
ReadPackString(hmenu[items], cmdsizeof(cmd));
                        
ReadPackString(hmenu[items], descsizeof(desc));
                        new 
drawstyle ITEMDRAW_DEFAULT;
                        if (
strlen(cmd) == 0)
                            
drawstyle ITEMDRAW_DISABLED;
                        
/////////////////////////if client has flag from config file then drawstyle = ITEMDRAW_DEFAULT else drawstyle = ITEMDRAW_DISABLED ////////////////////////////    
                        
AddMenuItem(cmenucmddescdrawstyle);
                    }
                    
ResetPack(hmenu[items]);
                    
DisplayMenu(cmenuparam130);
                }
            }
        }
    }


i hope someone can help me

Last edited by napster_10; 05-23-2019 at 18:10.
napster_10 is offline
Kolapsicle
Senior Member
Join Date: Oct 2014
Old 05-24-2019 , 10:25   Re: grey out menu entries
Reply With Quote #6

I've never used the SMC parser, and I may be wrong, but I don't expect it supports parsing two values per key. Have you considered using command overrides?
Kolapsicle is offline
napster_10
Senior Member
Join Date: May 2016
Old 05-24-2019 , 12:21   Re: grey out menu entries
Reply With Quote #7

i do use overrides of course because when people know the command they could simply type in the command in chat or console.

i just want to have a vip menu where all commands are visible but only the clients with the correct flags can use it and rest is on ITEMDRAW_DISABLED.

so is there any other way to do it if its not possible with smc parser?

Last edited by napster_10; 05-24-2019 at 12:22.
napster_10 is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 05-24-2019 , 12:36   Re: grey out menu entries
Reply With Quote #8

While it's not the standard menu API, the TopMenus API (used by the Admin menu) allows you to set permissions on menu items; items will only be displayed to users who have the correct permissions.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 05-24-2019 at 12:38.
Powerlord is offline
napster_10
Senior Member
Join Date: May 2016
Old 05-24-2019 , 13:16   Re: grey out menu entries
Reply With Quote #9

ok but then i cant grey out items? the items just don't appear in the menu
napster_10 is offline
Kolapsicle
Senior Member
Join Date: Oct 2014
Old 05-24-2019 , 14:13   Re: grey out menu entries
Reply With Quote #10

Another option is CheckCommandAccess. You'll have to call it for each config key you wish to check against.

PHP Code:
char key[] = "sm_rcon";
Menu.AddItem("info""display"CheckCommandAccess(clientkeyADMFLAG_RCON) ? ITEMDRAW_DEFAULT ITEMDRAW_DISABLED); 
Kolapsicle is offline
Reply



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 17:00.


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