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

Menu disable


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
leandro442
Member
Join Date: Sep 2013
Location: Portugal
Old 01-27-2021 , 18:01   Menu disable
Reply With Quote #1

good evening ! I have a question and I wanted help, I'm still at the beginning of the logic that involves the menus and I wanted help to disable a menu item, I wanted to know what I need to use to disable a menu option in the first round and be only possible to use that menu option once
leandro442 is offline
MAGNAT2645
Senior Member
Join Date: Nov 2015
Location: AlliedMods.net
Old 01-28-2021 , 06:27   Re: Menu disable
Reply With Quote #2

To disable specific item, you can put ITEMDRAW_DISABLED to its flags.
When you add menu item:
Code:
hMenu.AddItem( "info", "Text", ITEMDRAW_DISABLED );
Here's full example:
Code:
int g_iRounds = 0;
bool g_bSelected[MAXPLAYERS + 1] = { false, ... };

public void OnPluginStart() {
	RegConsoleCmd( "sm_menu", OpenMenu );
	HookEvent( "round_start", OnRoundStart, EventHookMode_PostNoCopy );
}

public void OnMapStart() {
	g_iRounds = 0;
}

public void OnRoundStart(Event event, const char[] name, bool dontBroadcast) {
	g_iRounds++;
}

public Action OpenMenu(int client, int args) {
	Menu hMenu = new Menu( MyMenuHandler );
	hMenu.SetTitle( "TITLE" );
	hMenu.AddItem( "1st", "First" );

	// disable second item if client selected it earlier or if first round
	hMenu.AddItem( "2nd", "Second", ( g_bSelected[client] || g_iRounds <= 1 ) ? ITEMDRAW_DISABLED : ITEMDRAW_DEFAULT );

	hMenu.AddItem( "3rd", "Third" );
	hMenu.Display( client, MENU_TIME_FOREVER );

	return Plugin_Handled;
}

public int MyMenuHandler(Menu menu, MenuAction action, int param1, int param2) {
	switch ( action ) {
		case MenuAction_Select: {
			char szInfo[16], szDisplay[32];
			menu.GetItem( param2, szInfo, sizeof szInfo, _, szDisplay, sizeof szDisplay );

			if ( strcmp( szInfo, "2nd" ) == 0 )
				g_bSelected[param1] = true;

			PrintToChat( param1, "You've selected %s Item.", szDisplay );
		}
		case MenuAction_End: menu.Close();
	}
}

public void OnClientPutInServer(int client) {
	g_bSelected[client] = false;
}

public void OnClientDisconnect(int client) {
	g_bSelected[client] = false;
}
Didn't test because i don't play CS:S (or CS:GO) but it should work.
__________________
MAGNAT2645 is offline
leandro442
Member
Join Date: Sep 2013
Location: Portugal
Old 01-28-2021 , 10:29   Re: Menu disable
Reply With Quote #3

Thx!! and who i can put he just can select one time for round?
leandro442 is offline
MAGNAT2645
Senior Member
Join Date: Nov 2015
Location: AlliedMods.net
Old 01-29-2021 , 05:29   Re: Menu disable
Reply With Quote #4

That's just an example, you need to build your own logic (using event hooks and counters etc.) for all your needs.
__________________
MAGNAT2645 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 00:31.


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