AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved Weird behavior with ShowMenu (Choose team) (https://forums.alliedmods.net/showthread.php?t=310522)

marcelowzd 09-06-2018 22:01

Weird behavior with ShowMenu (Choose team)
 
Hello AlliedModders.

First of all, i'm simply trying to block the Team Select Menu on join and show a custom menu with the following code.

PHP Code:

#include < amxmodx >
#include < engine >

const m_iMenuCode 205;

new const 
JOIN_TEAM_MENU_FIRST[ ] = "#Team_Select";
new const 
JOIN_TEAM_MENU_FIRST_SPEC[ ] = "#Team_Select_Spect";

new 
bool:g_bIsValidated33 ];

new 
g_iMsgShowMenu;

public 
plugin_init( )
{
    
g_iMsgShowMenu get_user_msgid"ShowMenu" );

    
register_messageg_iMsgShowMenu"OnOpenTextMenu" );

    
register_clcmd"chooseteam""OnJoinAttempt" );
    
register_clcmd"jointeam""OnJoinAttempt" );
    
register_clcmd"joinclass""OnJoinAttempt" );
}

public 
OnJoinAttemptiClient )
{
    return ( 
g_bIsValidatediClient ] ? PLUGIN_CONTINUE PLUGIN_HANDLED );
}

public 
OnOpenTextMenuiMsgIdiDestiClient // MESSAGE SHOWMENU
{
    if( !
is_user_connectediClient ) )
        return 
PLUGIN_CONTINUE;

    static 
szText64 ];

    
get_msg_arg_string4szTextcharsmaxszText ) );

    if( 
equalszTextJOIN_TEAM_MENU_FIRST ) || equalszTextJOIN_TEAM_MENU_FIRST_SPEC ) )
    {
        if( !
g_bIsValidatediClient ] )
        {
            
//set_task( 1.0, "TaskOpenMenu", iClient + 1537 );

            //ShowCustomJoinMenu( iClient );

            
log_amx"CALLED" );

            
set_pdata_intiClientm_iMenuCode); // Reset CS menu behavior

            
return PLUGIN_HANDLED;
        }
     }

    return 
PLUGIN_CONTINUE;


This code works IF and ONLY IF i remove set_task. If i remove set_task, the "log_amx" only appears one time and i can open the menu with a chat command, but if use the set_task part (or even if i try to open the menu directly in the function), i get several logged messages as the following and i can't use the menu at all since it appears again and again.

PHP Code:

L 09/06/2018 22:37:47: [Test.amxxCALLED
L 09
/06/2018 22:37:48: [Test.amxxCALLED
L 09
/06/2018 22:37:49: [Test.amxxCALLED
L 09
/06/2018 22:37:50: [Test.amxxCALLED
L 09
/06/2018 22:37:51: [Test.amxxCALLED 

I'm also blocking VGUI, but in VGUI it is working perfectly and it doesn't have anything to do with this part of the code.

The "TaskOpenMenu" is just a simple menu with both teams to choose (for now).

Some more information are: AMXX 1.8.3 +dev5151, Metamod-P 1.21p37.

So, i don't know what is causing the function to loop like it is doing now, any ideas?

HamletEagle 09-07-2018 09:22

Re: Weird behavior with ShowMenu (Choose team)
 
Can you post the full code?(I mean with ShowCustomJoinMenu and everything else needed to compile).
I tried the code you posted in 1.8.2, 5151 and 5208 and for me it works fine.

marcelowzd 09-07-2018 10:23

Re: Weird behavior with ShowMenu (Choose team)
 
Quote:

Originally Posted by HamletEagle (Post 2614142)
Can you post the full code?(I mean with ShowCustomJoinMenu and everything else needed to compile).
I tried the code you posted in 1.8.2, 5151 and 5208 and for me it works fine.

Sure.

PHP Code:

#include < amxmodx >
#include < engine >
#include < cstrike >
#include < fakemeta >

const m_iMenuCode 205;

new const 
JOIN_TEAM_MENU_FIRST[ ] = "#Team_Select";
new const 
JOIN_TEAM_MENU_FIRST_SPEC[ ] = "#Team_Select_Spect";
new const 
JOIN_TEAM_VGUI_MENU 2;

new 
bool:g_bValidated33 ];

new 
g_iMsgShowMenu;
new 
g_iMsgVGUI;

enum ( += )
{
    
CLASS_TYPE_NONE = -1,
    
CLASS_TYPE_A,
    
CLASS_TYPE_B,
    
CLASS_TYPE_C
};

new 
g_iClass33 ];

public 
plugin_init( )
{
    
g_iMsgVGUI get_user_msgid"VGUIMenu" );
    
g_iMsgShowMenu get_user_msgid"ShowMenu" );

    
register_messageg_iMsgShowMenu"OnOpenTextMenu" );
    
register_messageg_iMsgVGUI"OnOpenVGUIMenu" );

    
register_clcmd"chooseteam""OnJoinAttempt" );
    
register_clcmd"jointeam""OnJoinAttempt" );
    
register_clcmd"joinclass""OnJoinAttempt" );
}

public 
client_putinserveriClient )

    
g_bValidatediClient ] = false;

    
g_iClassiClient ] = CLASS_TYPE_NONE;
}

public 
OnJoinAttemptiClient )
{
    return ( 
g_bValidatediClient ] ? PLUGIN_CONTINUE PLUGIN_HANDLED );
}

public 
OnOpenTextMenuiMsgIdiDestiClient // MESSAGE SHOWMENU
{
    if( !
is_user_connectediClient ) )
        return 
PLUGIN_CONTINUE;

    static 
szText64 ];

    
get_msg_arg_string4szTextcharsmaxszText ) );

    if( 
equalszTextJOIN_TEAM_MENU_FIRST ) || equalszTextJOIN_TEAM_MENU_FIRST_SPEC ) )
    {
        if( !
g_bValidatediClient ] )
        {
            
set_task1.0"TaskOpenMenu"iClient 1537 );

            
log_amx"CALLED" );

            
set_pdata_intiClientm_iMenuCode); // Reset CS menu behavior

            
return PLUGIN_HANDLED;
        }
     }

    return 
PLUGIN_CONTINUE;
}

public 
OnOpenVGUIMenuiMsgIdiDestiClient )
{
    if( !
is_user_connectediClient ) )
        return 
PLUGIN_CONTINUE;
    
    new 
iOption get_msg_arg_int);

    if( 
iOption != JOIN_TEAM_VGUI_MENU )
        return 
PLUGIN_CONTINUE;

    if( !
g_bValidatediClient ] )
    {
        
OnJoinMenuOpeniClient );

        return 
PLUGIN_HANDLED;
    }

    return 
PLUGIN_CONTINUE;
}

public 
TaskOpenMenuiClient )
{
    
iClient -= 1537;

    if( !
is_user_connectediClient ) )
        return 
PLUGIN_CONTINUE;

    
OnJoinMenuOpeniClient );

    return 
PLUGIN_CONTINUE;
}

public 
OnJoinMenuOpeniClient )
{
    new 
hMenu menu_create"\r[ Menu ]\wJoin Menu""JoinMenuHandler" );
    
    
menu_additemhMenu"Team CT""");
    
menu_additemhMenu"Team TR""");
    
    
menu_setprophMenuMPROP_EXITMEXIT_NEVER );
    
    
menu_displayiClienthMenu);
}

public 
JoinMenuHandleriClienthMenuiItem )
{
    if( 
iItem )
    {
        
menu_destroyhMenu );
    
        return 
PLUGIN_HANDLED;
    }

    
cs_set_user_teamiClient, ( iItem == CS_TEAM_CT CS_TEAM_T ) );

    new 
hSubMenu menu_create"\r[ Menu ] \wChoose the class""TeamClassMenuHandler" );

    
menu_additemhSubMenu"Class 1""");
    
menu_additemhSubMenu"Class 2""");
    
menu_additemhSubMenu"Class 3""");

    
menu_setprophSubMenuMPROP_EXITMEXIT_NEVER );

    
menu_displayiClienthSubMenu);

    
menu_destroyhMenu );
    
    return 
PLUGIN_HANDLED;
}

public 
TeamClassMenuHandleriClienthMenuiItem )
{
    if( 
iItem )
    {
        
menu_destroyhMenu );

        return 
PLUGIN_HANDLED;
    }

    
g_iClassiClient ] = iItem;

    
g_bValidatediClient ] = true;

    
menu_destroyhMenu );

    return 
PLUGIN_HANDLED;


EDIT: It stopped looping but now my game crashes with the following message:

MESSAGE_END called, but message buffer from .dll had overflowed

HamletEagle 09-10-2018 04:16

Re: Weird behavior with ShowMenu (Choose team)
 
Try any build after(preferably the latest version): https://github.com/alliedmodders/amxmodx/pull/537

marcelowzd 09-10-2018 08:32

Re: Weird behavior with ShowMenu (Choose team)
 
Quote:

Originally Posted by HamletEagle (Post 2614506)
Try any build after(preferably the latest version): https://github.com/alliedmodders/amxmodx/pull/537

You're right, just tested with AMXX 1.9.0 +dev5215 and it worked fine. Thanks for your time.


All times are GMT -4. The time now is 12:53.

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