AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How to hook menu display events (https://forums.alliedmods.net/showthread.php?t=335328)

Leech_v2 11-25-2021 02:18

How to hook menu display events
 
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?

jimaway 11-25-2021 05:56

Re: How to hook menu display events
 
Quote:

Originally Posted by Leech_v2 (Post 2764274)
I want to destroy the previous menu when the player opens any other menu.

why?
Quote:

Originally Posted by Leech_v2 (Post 2764274)
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.

CrazY. 11-29-2021 07:21

Re: How to hook menu display events
 
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.

Leech_v2 11-30-2021 02:47

Re: How to hook menu display events
 
Quote:

Originally Posted by CrazY. (Post 2764610)
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

CrazY. 11-30-2021 12:23

Re: How to hook menu display events
 
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


All times are GMT -4. The time now is 20:14.

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