AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [SOLVED] menu callback trouble (https://forums.alliedmods.net/showthread.php?t=204831)

Blizzard_87 01-03-2013 21:18

[SOLVED] menu callback trouble
 
ive got the callback working for admin check... its disabled when your not admin....

but when player is ALIVE it still shows menu item in white and showing enabled....

PHP Code:

public Revive_callback(idDM_Menuitem)
{
    new 
data[6], szName[64];
    new 
accesscallback;
    

    
menu_item_getinfo(DM_Menuitemaccessdata,charsmax(data), szName,charsmax(szName), callback);

    new 
tempid str_to_num(data);
    
    if( !
is_user_alivetempid ) )
    {
        return 
ITEM_ENABLED;
    }    

    return 
ITEM_DISABLED;


this is the menu and handler

PHP Code:

public DM_MainMenu(id)
{
    new 
DM_Menu menu_create("\rDeathMatch Main Menu:^n\yMade By Blizzard""DM_MainMenu_Handler");
    
    
    
menu_additem(DM_Menu"Change Team""1");
    
menu_additem(DM_Menu"Re-Enable Class Menu""2");
    
menu_additem(DM_Menu"Class Information^n""3");
    
menu_additem(DM_Menu"Respawn""4"0g_ReviveCallback);
    
menu_additem(DM_Menu"Admin Menu""5"0g_AdminCallback);
    
    
    
menu_setprop(DM_MenuMPROP_EXITMEXIT_ALL);
    
    
menu_display(idDM_Menu);
    
    return 
PLUGIN_HANDLED;
    
}

public 
DM_MainMenu_Handler(idDM_Menuitem)
{
    if( 
item == MENU_EXIT )
    {        
        
Check_No_Class(id);
                    
        
menu_destroy(DM_Menu);
        return 
PLUGIN_HANDLED;
    }

    new 
data[6], szName[64];
    new 
accesscallback;
    
    
menu_item_getinfo(DM_Menuitemaccessdatacharsmax(data), szNamecharsmax(szName), callback);
    
    new 
key str_to_num(data);
    
    switch( 
key )
    {
        case 
1// Change Team Menu
        
{
            
Change_Team_Menu(id);
        }
        
        case 
2// Re-Enable Class Menu
        
{
            
client_cmd(id"enable");
            
Check_No_Class(id);
        }
        
        case 
3// Class Information
        
{
            
client_cmd(id"ClassInfo");
            
Check_No_Class(id);
        }
        
        case 
4:
        {
            if(!
is_user_alive(id))
            {
                
ExecuteHamB(Ham_CS_RoundRespawnid);
            }
            
            
Check_No_Class(id);
        }
        case 
5:
        {
            
Show_Admin_Menu(id);
        }
        
    }
    
    
    
menu_destroy(DM_Menu);    
    return 
PLUGIN_HANDLED;


i cant find what ive done wrong since ive made sure to do it all correct from the TUT.

fysiks 01-03-2013 22:39

Re: menu callback trouble
 
"data" does not contain the player's id.

Blizzard_87 01-03-2013 22:59

Re: menu callback trouble
 
Quote:

Originally Posted by fysiks (Post 1866640)
"data" does not contain the player's id.

ok. but my admin check callback works....

why would it work for one but not the other?

fysiks 01-04-2013 01:59

Re: menu callback trouble
 
Quote:

Originally Posted by Blizzard_87 (Post 1866648)
ok. but my admin check callback works....

why would it work for one but not the other?

How can I answer that question without the code??

Blizzard_87 01-04-2013 03:41

Re: menu callback trouble
 
Quote:

Originally Posted by fysiks (Post 1866700)
How can I answer that question without the code??

i tried to understand what you ment... is there any other way to explain it lol dumbed down version?

AngeIII 01-04-2013 06:02

Re: menu callback trouble
 
you doesn't show the g_AdminCallback code.

Blizzard_87 01-04-2013 06:10

Re: menu callback trouble
 
PHP Code:

// Admin Check Callback
public Admin_callback(idDM_Menuitem)
{
    new 
data[6], szName[64];
    new 
accesscallback;
    

    
menu_item_getinfo(DM_Menuitemaccessdata,charsmax(data), szName,charsmax(szName), callback);

    new 
tempid str_to_num(data);
    
    if( 
is_user_admintempid ) )
    {
        return 
ITEM_DISABLED;
    }    

    return 
ITEM_ENABLED;



ConnorMcLeod 01-04-2013 06:25

Re: menu callback trouble
 
As a side note, for admin items you don't need to make a callback.
Code:

/**
 * Adds an menu to a menu.
 *
 * @param menu                        Menu resource identifier.
 * @param name                        Item text to display.
 * @param info                        Item info string for internal information.
 * @param paccess                Access required by the player viewing the menu.
 * @param callback                If set to a valid ID from menu_makecallback(), the
 *                                                callback will be invoked before drawing the item.
 * @noreturn
 * @error                                Invalid menu resource.
 */
native menu_additem(menu, const name[], const info[]="", paccess=0, callback=-1);

Just set paccess variable to ADMIN_ADMIN and it should work.

PHP Code:

menu_additem(DM_Menu"Admin Menu""5"0g_AdminCallback

->

PHP Code:

menu_additem(DM_Menu"Admin Menu""5"ADMIN_ADMIN


2nd tip, you don't need to get item info and ton convert it to an integer to retrieve key, just use item instead :

PHP Code:

    new data[6], szName[64];
    new 
accesscallback;
    
    
menu_item_getinfo(DM_Menuitemaccessdatacharsmax(data), szNamecharsmax(szName), callback);
    
    new 
key str_to_num(data);
    
    switch( 
key )
    {
        case 
1// Change Team Menu 

->

PHP Code:

    switch( item )
    {
        case 
0// Change Team Menu 

item starts at 0 when your code was making key start at 1, this is the only difference.

Blizzard_87 01-04-2013 07:18

Re: menu callback trouble
 
@Conner. Thanks for your help... and i understood it fairly easy.

PHP Code:

// Revive Callback
public Revive_callback(idDM_Menuitem)
{
    new 
data[6], szName[64];
    new 
accesscallback;
    
    
menu_item_getinfo(DM_Menuitemaccessdata,charsmax(data), szName,charsmax(szName), callback);

    
//new tempid = str_to_num(data);
    // didnt need to check tempid as its the player opening menu themselves
    
    
if( is_user_aliveid ) )
    {
        return 
ITEM_DISABLED;
    }    

    return 
ITEM_ENABLED;


got the respawn callback working too :P

thanks everyone

@fysiks. i now understand what you meant about the DATA not containing players ID.

bLacK-bLooD 01-05-2013 03:47

Re: menu callback trouble
 
Quote:

Originally Posted by ConnorMcLeod (Post 1866778)

Just set paccess variable to ADMIN_ADMIN and it should work.

PHP Code:

menu_additem(DM_Menu"Admin Menu""5"0g_AdminCallback

->

PHP Code:

menu_additem(DM_Menu"Admin Menu""5"ADMIN_ADMIN


Nevertheless, if i set ADMIN_ADMIN who will be able to acces it? I have done this to my menu and i have all the flags(abcdefghijklmnopqrstu) and however i can't acces it because i don't have acces.

Edit :

Damn, bad morning... I just modified from ADMIN_ADMIN to ADMIN_MENU and it's working. *Case solved*


All times are GMT -4. The time now is 13:44.

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