AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved Opening a menu (https://forums.alliedmods.net/showthread.php?t=317994)

shadow728988 08-08-2019 08:55

Opening a menu
 
How can i make it so that only one admin at a time is able to access the menu from a plugin.
For eg.
Code:

public checkformenu(id)
{
  if(menuopen==true)
    {
        client_print(id, "An admin is already using the menu")
      }
  else
        openmenu(id)
}

thank you for your help.

edon1337 08-08-2019 09:00

Re: Opening a menu
 
Post in Suggestion/Requests section if you don't know how to script.
PHP Code:

new bool:g_bMenuOpen;

public 
Menuid )
{
    if( 
g_bMenuOpen )
    {
        
client_printidprint_chat"Menu is already being used by another admin" );
        return 
PLUGIN_HANDLED;
    }
    
    
g_bMenuOpen true;
    
    new 
iMenu menu_create"Menu Title""MenuHandler" );
    
    
menu_additemiMenu"Item1" );
    
menu_additemiMenu"Item2" );
    
menu_additemiMenu"Item3" );
    
    
menu_displayidiMenu);
}

public 
MenuHandleridiMenuiItem )
{
    
g_bMenuOpen false;

    
// code



Natsheh 08-08-2019 10:27

Re: Opening a menu
 
This false due to menu override.

Check in a loop if a player has that menu opened.

edon1337 08-08-2019 11:00

Re: Opening a menu
 
Quote:

Originally Posted by Natsheh (Post 2662460)
This false due to menu override.

Check in a loop if a player has that menu opened.

What do you mean by 'menu override', he didn't mention creating multiple menus

Natsheh 08-08-2019 11:50

Re: Opening a menu
 
Menu override means opening a new menu while the old menu is being displayed which result in not calling the handler of the old menu that were displayed.

edon1337 08-08-2019 12:16

Re: Opening a menu
 
Quote:

Originally Posted by Natsheh (Post 2662475)
Menu override means opening a new menu while the old menu is being displayed which result in not calling the handler of the old menu that were displayed.

So how does looping through all players help in any way?

Natsheh 08-08-2019 12:49

Re: Opening a menu
 
To check if a player has the menu opened.

Mistrick 08-08-2019 14:49

Re: Opening a menu
 
Quote:

Originally Posted by Natsheh (Post 2662475)
Menu override means opening a new menu while the old menu is being displayed which result in not calling the handler of the old menu that were displayed.

You are wrong. AMXX closes menu when someone want to show another menu.
https://github.com/alliedmodders/amx...modx.cpp#L1306
https://github.com/alliedmodders/amx...modx.cpp#L1316
https://github.com/alliedmodders/amx...menus.cpp#L862

Natsheh 08-08-2019 16:07

Re: Opening a menu
 
Seems like it was an old bug not sure if it was fixed in v182

https://forums.alliedmods.net/showthread.php?p=407839


Still it will be much better to use player_menu_info to check if the user has the menu displayed since it covers most cases.


All times are GMT -4. The time now is 17:30.

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