/*
* Shows a menu which is supposed to be destroyed when another one is shown.
* It does a certain check and then calls menu_display().
* Use instead of menu_display().
*
* @return - same as menu_display().
*/
stock ShowLocalMenu(client, menu, page = 0);
/*
* Shows a menu which is NOT supposed to be destroyed when another one is shown.
* It does a certain check and then calls menu_display().
* Use instead of menu_display().
*
* @return - same as menu_display().
*/
stock ShowGlobalMenu(client, menu, page = 0);
/*
* Destroys a menu which was previously shown with ShowLocalMenu() function.
* Use instead of menu_destroy().
*
* @return - same as menu_destroy().
*
* Note - It requires the index of player as first parameter, unlike menu_destroy().
* Note - For global menus, which were shown with ShowGlobalMenu() or menu_display(),
* use menu_destroy() instead.
*/
stock DestroyLocalMenu(client, menu);
#include <amxmodx>
#include <safemenu>
public plugin_init()
{
register_clcmd("say /test", "OnSayTest");
}
public OnSayTest(client)
{
new menu = menu_create("Test Menu", "OnMenu");
menu_additem(menu, "Item");
ShowLocalMenu(client, menu);
return PLUGIN_HANDLED;
}
public OnMenu(client, menu, item)
{
client_print(0, print_chat, "test");
DestroyLocalMenu(client, menu);
return PLUGIN_HANDLED;
}
Only when I press 1 or 0 it works.
It doesn't call OnMenu(), it destroys menus which were displayed using Show[Local|Global]Menu() when another Show[Local|Global]Menu() is used. So as long as all the plugins use Show[Local|Global]Menu() instead of menu_display(), only a maximum of 1 temporary ("local") menu is held in the memory for players separately. Without this an unlimited amount of memory leak would be possible.
I could've made it call the menu (OnMenu()) with item as MENU_EXIT, but it wouldn't be any different, really.
You can check it by creating menu A and showing it, then creating menu B and showing it without first destroying menu A. You'll see how menu A has an ID of 0 while menu B has an ID of 1. However menu A is no longer available, so the next menu (C) will have an ID of 0.