AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   General (https://forums.alliedmods.net/forumdisplay.php?f=7)
-   -   newmenus problem. (https://forums.alliedmods.net/showthread.php?t=270366)

luxor 08-19-2015 15:40

newmenus problem.
 
How can i check if a player has a menu open or closed ?
i mean... i create a menu with menu_create (added some items with menu_additem blablabla) after I displayed it menu_display to that player.... but another plugin used show_menu( 0, 0, "^n", 1 ); to destroy all menus from all players... and when the first plugin auto-destroyed the menu (created with menu_create) i receive an error... like that :

L 08/18/2015 - 23:26:42: Start of error session.
L 08/18/2015 - 23:26:42: Info (map "de_dust2") (file "addons/amxmodx/logs/error_20150818.log")
L 08/18/2015 - 23:26:42: Invalid menu id 3(5)
L 08/18/2015 - 23:26:42: [AMXX] Displaying debug trace (plugin "plugin.amxx", version "1.0")
L 08/18/2015 - 23:26:42: [AMXX] Run time error 10: native error (native "menu_destroy")
L 08/18/2015 - 23:26:42: [AMXX] [0] race.sma::Auto-Refuse (line 317)

the issue is that we don't have a menu_exists... (http://www.amxmodx.org/api/newmenus) and when i call the menu_destroy native, the menu is already destroyed.

Nextra 08-20-2015 02:27

Re: newmenus problem.
 
For starters there is player_menu_info() which allows you to check if a menu is being displayed to the player, and which one it is.

But I don't think that is your problem, your problem is probably that you don't correctly handle your menu being closed. When another plugin overwrites your menu, your menu callback is fired with MENU_EXIT (as you can see here and here). Your plugin handles that event and probably destroys the menu. It makes no sense to call menu_destroy() again on the menu, so this behavior is expected.

Unless you can show me a test case where the menu really is destroyed without your plugin noticing it, I don't believe this is an issue with AMXX.

luxor 08-20-2015 04:18

Re: newmenus problem.
 
My plugin.
Code:

public RaceMenu_Handler(id, menu, item) // there is a hander to another menu... but here is created the problematic menu.
{
        if ( item == MENU_EXIT )
        {
                menu_destroy(menu);
                return PLUGIN_HANDLED;
        }
       
        new data[6], name[MAX_NAME_LENGTH];
        new _acces, item_callback;
        menu_item_getinfo(menu, item, _acces, data, charsmax(data), name, charsmax(name), item_callback);
       
        new userid = str_to_num(data);
        new player = find_player("k", userid);
       
        if ( player )
        {
                new name[MAX_NAME_LENGTH];
                get_user_name(player, name, charsmax(name));
                new Text[121];
                formatex(Text, charsmax(Text), "%s challenged you to a race :", name);
                new Menu = menu_create(Text, "Answers_SubMenu"); // there is the Menu.
             
                formatex(Text, charsmax(Text), "Accept the challenge." );
                menu_additem(Menu, Text, "1", 0);
             
                formatex(Text, charsmax(Text), "No thanks." );
                menu_additem(Menu, Text, "2", 0);
 
                menu_setprop(Menu, MPROP_EXIT , MEXIT_ALL);
                menu_display(player, Menu, 0);

                new index[10];
                num_to_str(player, index, charsmax(index));
                isnotAfk[player] = false;
                set_task(15.0, "Refuse", Menu, index, charsmax(index));
 
                return PLUGIN_HANDLED;
        }
        menu_destroy(menu);
        return PLUGIN_HANDLED;
}

public Refuse(index[], Menu)
{
        new id = str_to_num(index);
        if ( !isnotAfk[id] ) // this is for knowing if menu was closed.
        {
                menu_destroy(Menu); // there menu is destroyed
        }
}

but another plugin is sending show_menu( 0, 0, "^n", 1 ); from time to time (i deleted the source and i feel too lazy to recreate it).

now i looked after player_menu_info() and it should solve my problem... but anyway how can i know if this is my menu, not another menu.. because maybe i don't want to close any menu, just my menu.

ps: yea.. this can work too
Code:

....
new auxMenu;
player_menu_info(id, _, auxMenu);
if (myMenu == auxMenu)
{
  menu_destroy(auxMenu)
}
...

but this look like a hard way.. a menu_exists can be more usefull, like that :

Code:

...
if (menu_exists(myMenu)) // 1 : 0
{
  menu_destroy(myMenu)
}
...

thats my opinion...

Nextra 08-20-2015 08:19

Re: newmenus problem.
 
To put it bluntly menu_exists(menu) is crappy API design. Menu ids are reused by AMXX and not owned by plugins, so that native would not help. Even if that weren't the case, your plugin can very easily tell if a menu has been destroyed or not by assigning it to an array and remembering the menu id by itself.

You forgot to post the code to your "Answers_SubMenu" handler, but here's a rough outline of what would solve your problem:

PHP Code:

public RaceMenu_Handler(idmenuitem) {
// ...
   
new menu menu_create(Text"Answers_SubMenu");
   
challenge_menu[id] = menu// save the menu id
// ...
}

public 
Answers_SubMenu(idmenuitem) {
// ...
   
challenge_menu[id] = -1// reset the menu id to an invalid id
// ...
}

public 
Refuse(id) {
   if (
challenge_menu[id] != -1)
      
menu_destroy(challenge_menu[id]); // only destroy if the menu still exists


Depending on how your current "Answers_SubMenu" looks your code would break even if the player presses exit manually. The code above is how you should usually solve this.

luxor 08-20-2015 09:09

Re: newmenus problem.
 
Quote:

Originally Posted by Nextra (Post 2335172)
You forgot to post the code to your "Answers_SubMenu" handler, but here's a rough outline of what would solve your problem:

it is useless, not here is the problem...

Quote:

Originally Posted by Nextra (Post 2335172)
PHP Code:

public RaceMenu_Handler(idmenuitem) {
// ...
   
new menu menu_create(Text"Answers_SubMenu");
   
challenge_menu[id] = menu// save the menu id
// ...
}

public 
Answers_SubMenu(idmenuitem) {
// ...
   
challenge_menu[id] = -1// reset the menu id to an invalid id
// ...
}

public 
Refuse(id) {
   if (
challenge_menu[id] != -1)
      
menu_destroy(challenge_menu[id]); // only destroy if the menu still exists


Depending on how your current "Answers_SubMenu" looks your code would break even if the player presses exit manually. The code above is how you should usually solve this.

Answers_SubMenu won't be called, because another menu will display and will close my menu..

All the things will happen in this way :
1. menu created and desplayed from RaceMenu_Handler - my plugin
2. menu will be closed/distroyed and Answers_SubMenu won't be called - another plugin (which i deleted the source :| )
3. refuse will be called and a error will be appear - my plugin


so.. if is not an issue, and a new native menu_exists can't be created... how cand i know if my menu is destroyed or not ? tell me...

Arkshine 08-20-2015 09:36

Re: newmenus problem.
 
What AMXX version do you use? If you're using 1.8.3-dev, Answers_SubMenu will be called for sure.

luxor 08-20-2015 10:33

Re: newmenus problem.
 
]meta list
Currently loaded plugins:
description stat pend file vers src load unlod
[ 1] AMX Mod X RUN - amxmodx_mm_i386. v1.8.3-d ini Start ANY
[ 2] CStrike RUN - cstrike_amxx_i38 v1.8.3-d pl2 ANY ANY
[ 3] FakeMeta RUN - fakemeta_amxx_i3 v1.8.3-d pl2 ANY ANY
[ 4] Engine RUN - engine_amxx_i386 v1.8.3-d pl2 ANY ANY
[ 5] Ham Sandwich RUN - hamsandwich_amxx v1.8.3-d pl2 ANY ANY
[ 6] MySQL RUN - mysql_amxx_i386. v1.8.3-d pl2 ANY ANY
[ 7] Fun RUN - fun_amxx_i386.so v1.8.3-d pl2 ANY ANY
[ 8] CSX RUN - csx_amxx_i386.so v1.8.3-d pl2 ANY ANY
8 plugins, 8 running

Arkshine 08-20-2015 10:44

Re: newmenus problem.
 
Then I don't see the issue ; Nextra showed you in a link, that when show_menu is called, if there is already a newmenu displayed, the callback will be called. What said Nextra should solve your issue.

Make sure you're using latest dev build.

Mordekay 08-20-2015 10:44

Re: newmenus problem.
 
Nice fail edited meta list.

Nextra 08-20-2015 10:45

Re: newmenus problem.
 
We fixed precisely this scenario in 1.8.3 by ensuring that the menu handler will be called if other plugins overwrite your menu. Your issue is that you are trying to destroy the menu twice, which strongly points towards Answers_SubMenu being called. It is called, destroys the menu and then the timer hits and attempts to destroy it again.


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

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