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

How to hook menu display events


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Leech_v2
Senior Member
Join Date: Mar 2011
Location: Chinese GuangDong
Old 11-25-2021 , 02:18   How to hook menu display events
Reply With Quote #1

I want to destroy the previous menu when the player opens any other menu.
Therefore, I think "menu display event" or "menu hidden event" or "menu overwritten event" is needed.
But I didn't find any key words related to this.
Do you have any good ideas?
Leech_v2 is offline
jimaway
Heeeere's Jimmy!
Join Date: Jan 2009
Location: Estonia
Old 11-25-2021 , 05:56   Re: How to hook menu display events
Reply With Quote #2

Quote:
Originally Posted by Leech_v2 View Post
I want to destroy the previous menu when the player opens any other menu.
why?
Quote:
Originally Posted by Leech_v2 View Post
I think "menu display event" or "menu hidden event" or "menu overwritten event" is needed.
But I didn't find any key words related to this.
Do you have any good ideas?
https://wiki.alliedmods.net/Half-lif...vents#ShowMenu not sure if this works with client side menus, you'll have to test.
jimaway is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 11-29-2021 , 07:21   Re: How to hook menu display events
Reply With Quote #3

Assuming you want to hook amxx menus as well, the above suggestion will not work alone.
What you can do is combine that with orpheu. Hook amxx show_menu, Menu:: Display and Menu::Close, there is no alternative.

If you need that for VGUI menus it's hacky. You'll have to hook the message VGUIMenu, dispatch a Close Event on the current menu and Display Event on the menu that is being displayed.

There may be an alternative but you will have to explain what you are trying to do and why you need that.
__________________









Last edited by CrazY.; 11-29-2021 at 07:28.
CrazY. is offline
Leech_v2
Senior Member
Join Date: Mar 2011
Location: Chinese GuangDong
Old 11-30-2021 , 02:47   Re: How to hook menu display events
Reply With Quote #4

Quote:
Originally Posted by CrazY. View Post
Assuming you want to hook amxx menus as well, the above suggestion will not work alone.
What you can do is combine that with orpheu. Hook amxx show_menu, Menu:: Display and Menu::Close, there is no alternative.

If you need that for VGUI menus it's hacky. You'll have to hook the message VGUIMenu, dispatch a Close Event on the current menu and Display Event on the menu that is being displayed.

There may be an alternative but you will have to explain what you are trying to do and why you need that.
Players can create menus repeatedly by pressing z, x, c, or otherwise to accumulate menu objects on the server
Leech_v2 is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 11-30-2021 , 12:23   Re: How to hook menu display events
Reply With Quote #5

If you're referring to radio1-3 these don't create handlers that must be freed as they use the "old menu" style.
Only the ones created with menu_create must be freed, all you really need is to destroy them on their callback. If the player is currently viewing a menu created with menu_create and open another menu or diconnect, amxx does automatically call MENU_EXIT.

Here's a simple plugin for testing.
Code:
#include <amxmodx>


public plugin_init()
{
	register_plugin("plugin", "version", "author")

	register_clcmd("say menu", "CmdMenu")
}

public CmdMenu(index)
{
	Menu1(index)
}

Menu1(index, page=0)
{
	new menu = menu_create("Menu 1", "Menu1Handler")
	menu_additem(menu, "menu 2")
	menu_display(index, menu, clamp(page, 0, menu_pages(menu) - 1))
}

public Menu1Handler(index, menu, item)
{
	switch (item)
	{
		case 0:
		{
			Menu2(index)
		}
	}

	menu_destroy(menu)
	return PLUGIN_HANDLED
}

Menu2(index)
{
	new menu = menu_create("Menu 2", "Menu2Handler")
	menu_additem(menu, "item 1")
	menu_display(index, menu, 0)
}

public Menu2Handler(index, menu, item)
{
	client_print(index, print_chat, "^t item %d", item)
	switch (item)
	{
		case MENU_EXIT:
		{
			if (is_user_connected(index))
			{
				Menu1(index)
			}
		}
	}

	menu_destroy(menu)
	return PLUGIN_HANDLED
}
As for the game menus as radio1,radio2,radio3,etc., it seems like amxx doesn't call MENU_EXIT on the newmenu and doesn't destroy the handler either, this wasn't noticed by the dev team maybe? I'm not sure, but you can fix that with a plugin by hooking ShowMenu as the first suggestion, getting the player current menu with player_menu_info and destroy it.

To be honest newmenus should be completly reworked or at least have an option to remove items as with cellarray and celltrie, so instead of creating a new handler every time you open a menu, you would create it one time on plugin_init for example as you do with most things in amxx
__________________








CrazY. 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 20:12.


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