Raised This Month: $51 Target: $400
 12% 

Strange bug about menus in new amxx menu system


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
lqlqlq
Senior Member
Join Date: Jan 2008
Old 01-20-2015 , 15:25   Strange bug about menus in new amxx menu system
Reply With Quote #1

Hello.
I use last hlds with last amxx and metamod 1.21.
I try to overwrite plmenu with some small plugin and i do this.
Now i have strange bug, when i choose player and reopen menu again, last choosen player is 'saved' and all options in menu is overwritten with this information (about last player)
id, item name and etc...
Took me 2 days with work and i dont find the problem. I try everything and nothing working.
I try to get id by name with find_player, i try with cmd_target, and directly to pass id by menu_Additem and get back with num_to_str from menu_item_getinfo.
Noting work. This is hell!

I give the code here and i want some with strong knowledge edit this mess for working fine.
Code:
#include <amxmodx>
#include <amxmisc>
new reason[32]
new damage
new target[33];
new type = 0;

public plugin_init()
{
register_plugin("slap/slay/kick reason", "val", "1.0");
register_clcmd("amx_kickmenu", "cmdKickMenu")
register_clcmd("amx_slapmenu", "cmdSlapMenu")
}

/////////////STOCKS
stock KickPlayer(id, szBuffer[], any:...)
{
static szReason[60]
vformat(szReason, charsmax(szReason), szBuffer, 3)
message_begin(MSG_ONE, SVC_DISCONNECT,_, id)
write_string(szReason)
message_end()
}


/////////////////////SLAP MENU////////////////////////////////
public cmdSlapMenu(id) {
    if(!(get_user_flags(id) & ADMIN_SLAY)) {
    return PLUGIN_HANDLED
    }
    type = 1;
	
    //Create a variable to hold the menu
    new menu = menu_create( "\rChoose a player!:", "menu_handler4" );

    //We will need to create some variables so we can loop through all the players
    new players[32], pnum,i, tempid;

    //Some variables to hold information about the players
    new szName[32],szUserId[32]

    //Fill players with available players
    get_players( players, pnum); 

    //Start looping through all players
    for ( i=0;i<pnum;i++ )
    {
        //Save a tempid so we do not re-index
        tempid = players[i];

        //Get the players name and userid as strings
        get_user_name( tempid, szName, charsmax( szName ) );

        //Add the item for this player
        menu_additem( menu,szName );
    }

    //We now have all players in the menu, lets display the menu
    menu_display( id, menu);

    return PLUGIN_HANDLED
}

public menu_handler4( id, menu, item )
{
    if ( item == MENU_EXIT )
    {
	    menu_destroy(menu);
        return PLUGIN_HANDLED;
    }
    new szData4[6], szName[64];
    new item,access, item_callback;
    menu_item_getinfo( menu, item,access, szData4,charsmax(szData4), szName,charsmax( szName ), item_callback );


	client_print(0,print_chat,"%s",szName)
	
	menu_destroy( menu );
    ChooseDamage(id)
	
    return PLUGIN_HANDLED;
}

/////////////////////KICK MENU////////////////////////////////
public cmdKickMenu(id) {
    if(!(get_user_flags(id) & ADMIN_KICK)) {
    return PLUGIN_HANDLED
    }

	type = 2;
    //Create a variable to hold the menu
    new menu = menu_create( "\rChoose a player!:", "menu_handler3" );

    //We will need to create some variables so we can loop through all the players
    new players[32], pnum, tempid;

    //Some variables to hold information about the players
    new szName[32],szUserId[32];

    //Fill players with available players
    get_players( players, pnum);

    //Start looping through all players
    for ( --pnum; pnum>=0; pnum-- )
    {
        //Save a tempid so we do not re-index
        tempid = players[pnum];

        //Get the players name and userid as strings
        get_user_name( tempid, szName, charsmax( szName ) );
        formatex(szUserId, charsmax(szUserId), "%d", get_user_userid(tempid))
		
        //Add the item for this player
        menu_additem( menu, szName,szUserId, 0 );
    }

    //We now have all players in the menu, lets display the menu
    menu_display( id, menu);

    return PLUGIN_HANDLED
}

public menu_handler3( id, menu, item )
{
    if ( item == MENU_EXIT )
    {
        return PLUGIN_HANDLED;
    }
    new szData3[6], szName[64];
    new item,access, item_callback;
    menu_item_getinfo( menu, item,access, szData3,charsmax(szData3), szName,charsmax( szName ), item_callback );

	target[id] = find_player("k", str_to_num(szData3))
	menu_destroy( menu );
    AwesomeMenu( id )
	
    return PLUGIN_HANDLED;
}


public ChooseDamage(id) {
new menu = menu_create( "\rChoose Damage!:", "menu_handler5" );
menu_additem( menu, "\w1 DMG", "", 0 );
menu_additem( menu, "\w5 DMG", "", 0 );
menu_additem( menu, "\w10 DMG", "", 0 );
menu_additem( menu, "\w50 DMG", "", 0 );
menu_additem( menu, "\wSLAY", "", 0 );
menu_setprop( menu, MPROP_EXIT, MEXIT_ALL );
menu_display( id, menu, 0 );
}

public menu_handler5( id, menu, item )
{
if ( item == MENU_EXIT )
{
menu_destroy( menu );
return PLUGIN_HANDLED;
}

new szData[6], szName[64];
new item_access, item_callback;
menu_item_getinfo( menu, item, item_access, szData,charsmax( szData ), szName,charsmax( szName ), item_callback );
    
switch( item )
{
                case 0:
                {
                  damage = 1;
                }
                case 1:
                {
                  damage = 5
                }
                case 2:
                {
                  damage = 10
                }
                case 3:
                {
                  damage = 50
                }
                case 4:
                {
                  damage = 999
                } 
}    
menu_destroy( menu );    
AwesomeMenu( id )
return PLUGIN_HANDLED;
}

public AwesomeMenu( id ) {
new menu = menu_create( "\rChoose Reason!:", "menu_handler" );
menu_additem( menu, "\wRetry", "", 0 );
menu_additem( menu, "\wAir", "", 0 );
menu_additem( menu, "\wNekanen", "", 0 );
menu_additem( menu, "\wBez baza", "", 0 );
menu_additem( menu, "\wDruga prichina", "", 0 );
menu_setprop( menu, MPROP_EXIT, MEXIT_ALL );
menu_display( id, menu, 0 );
}

public menu_handler( id, menu, item )
{
if ( item == MENU_EXIT )
{
menu_destroy( menu );
return PLUGIN_HANDLED;
}

new szData[6], szName[64];
new item_access, item_callback;
menu_item_getinfo( menu, item, item_access, szData,charsmax( szData ), szName,charsmax( szName ), item_callback );
    
switch( item )
{
                case 0:
                {
                   format(reason,charsmax(reason),"Retry")
                }
                case 1:
                {
                    format(reason,charsmax(reason),"Air")
                }
                case 2:
                {
                     format(reason,charsmax(reason),"Nekanen")
                }
                case 3:
                {
                     format(reason,charsmax(reason),"Bez baza")
                }
                case 4:
                {
                     format(reason,charsmax(reason),"Druga prichina")
                }
}

menu_destroy( menu );
Punish(id)
return PLUGIN_HANDLED;
}

public Punish(id) {

//slap
if(type == 1) {

if (is_user_alive( target[id] ) )
{
        user_slap(target[id],damage)
        new name[32]
        get_user_name(id,name,31)
        new name2[32]
        get_user_name(target[id],name2,31)
        client_print(0,print_chat,"Admin %s has slapped %s with %d damage, Reason: %s",name,name2,damage,reason)
}

} 
//kick
else if(type == 2){

if (is_user_connected( target[id] ) )
{
        KickPlayer(target[id],reason)
        new name[32]
        get_user_name(id,name,31)
        new name2[32]
        get_user_name(target[id],name2,31)
        client_print(0,print_chat,"Admin %s has kicked %s, Reason: %s",name,name2,reason)
}
	
}

//clear
target[id] = 0
type = 0
damage = 0
//end clear
return PLUGIN_HANDLED;
}
lqlqlq is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 01-20-2015 , 16:29   Re: Strange bug about menus in new amxx menu system
Reply With Quote #2

Answer is simple when you try to add item as player you dont add the player info which is his id,

Example : when you looping throw players add the id of each player in menu additem info.

More ex..

PHP Code:
new sInfo[2], players[32], pnumsname[32]
get_players(playerspnum// getting all the connected players
for ( new 0pnums i++)
{
sInfo[0] = players[i]
sInfo[1] = 0
get_user_name
(players[i], namecharsmax(name))
menu_additem(menuidnamesInfo0)


Last edited by Natsheh; 01-20-2015 at 16:34.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
lqlqlq
Senior Member
Join Date: Jan 2008
Old 01-20-2015 , 17:02   Re: Strange bug about menus in new amxx menu system
Reply With Quote #3

I try with that - not working.
The script is messy in handle function for the menus.
menu_item_getinfo bring back wrong information and maybe its a bug in new versions of amxx.
lqlqlq is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 01-20-2015 , 17:31   Re: Strange bug about menus in new amxx menu system
Reply With Quote #4

"last amxx", means 1.8.3-dev?
__________________
Arkshine is offline
lqlqlq
Senior Member
Join Date: Jan 2008
Old 01-20-2015 , 17:50   Re: Strange bug about menus in new amxx menu system
Reply With Quote #5

Yes i use 4493 build.

I added some debugging with client_print (sees in the code)
Players correctly added to menu, but when i choose only first is correct, when i choose again (information is for previous player, not changed)


I think its a bug in this versions of amxx.

edit:
I switch to 4532 and bug is still exists.

Arkshine, please test this plugn. Put before all plugins in plugins.ini and type amx_slapmenu and test it.
See the client_print debug.

Last edited by lqlqlq; 01-20-2015 at 17:56.
lqlqlq is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 01-21-2015 , 00:24   Re: Strange bug about menus in new amxx menu system
Reply With Quote #6

Did check again slap menu function very carefully and you will see y forget to add the infoo.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
lqlqlq
Senior Member
Join Date: Jan 2008
Old 01-21-2015 , 09:05   Re: Strange bug about menus in new amxx menu system
Reply With Quote #7

tell me what i missing ?
lqlqlq is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 01-21-2015 , 11:44   Re: Strange bug about menus in new amxx menu system
Reply With Quote #8

Check cmdSlapMenu(id) function.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
lqlqlq
Senior Member
Join Date: Jan 2008
Old 01-21-2015 , 13:25   Re: Strange bug about menus in new amxx menu system
Reply With Quote #9

Dude, i try to pass id, but without success.
I pass only names and i get in handle function. But not working... Every name is the same as first choosed.
I can get id from names by find_player function.
client_print(0,print_chat,"%s",szName) (this is the debug)

I'm not newbie.

Last edited by lqlqlq; 01-21-2015 at 13:25.
lqlqlq is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 01-21-2015 , 13:58   Re: Strange bug about menus in new amxx menu system
Reply With Quote #10

Let me tell you something this is the worst kick and slap menu I ever seen!

& you seems a newbie
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 07:43.


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