AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How to make callback with num_to_str() in menu? (https://forums.alliedmods.net/showthread.php?t=157049)

EclipseCP 05-15-2011 11:17

How to make callback with num_to_str() in menu?
 
Hello everyone. :)

I wanted to do a callback, but I can not because have num_to_str() and prevents me from putting "buffer" to "menu_additem"

PHP Code:


new menu[128],num[8], buffer[128], menuidi

// [...]

num_to_str(inumcharsmax(num))
        
buffer[0] = i
buffer
[1] = 0
menu_additem
(menuidmenunumADMIN_ALLmenu_makecallback("c_menu3")) 

notify me if not well expressed, use translator. :cry:

Greetings

Exolent[jNr] 05-15-2011 11:32

Re: How to make callback with num_to_str() in menu?
 
Show full code.

EclipseCP 05-15-2011 11:36

Re: How to make callback with num_to_str() in menu?
 
Sorry.

PHP Code:

public show_menu_test(id)
{
    new 
menu[128], lang[32], info[32], num[8], buffer[128], menuidi
    
    formatex
(menucharsmax(menu), "\yTest...")
    
    
menuid menu_create(menu"menu_test"

    for (
0sizeof(LANG_MODES); i++) 
    {
        if (
MAX_LIMIT[i] > g_test_count[id][i]) 
            
formatex(infocharsmax(info), "\r[\w%d\r/\w%d\r]"MAX_LIMIT[i] - g_test_count[id][i], MAX_LIMIT[i])
        else
            
formatex(infocharsmax(info), "\r[\y0\r/\w%d\r]"MAX_LIMIT[i])
        
        
formatex(menucharsmax(menu), "%s %s"LANG_MODES[i], info)
        
        
num_to_str(inumcharsmax(num))
        
        
buffer[0] = i
        buffer
[1] = 0
        menu_additem
(menuidmenubufferADMIN_ALLmenu_makecallback("c_menu3")) 
    }
    
    
// Sin exit
    
formatex(menucharsmax(menu), "%L"id"MENU_BACK")
    
menu_setprop(menuidMPROP_EXITNAMEmenu
    
    
menu_display(idmenuid


public 
menu_test(idmenuiditem)
{
    
// Menu was closed
    
if (item == MENU_EXIT)
    {
        
menu_destroy(menuid
        return 
PLUGIN_HANDLED;
    }
    
    new 
buffer[4], dummyitemid
    menu_item_getinfo
(menuiditemdummybuffercharsmax(buffer), __dummy)
    
    
test1 str_to_num(buffer
    
    
menu_destroy(menuid)
    
    
show_menu_player_list(id)
    
    return 
PLUGIN_HANDLED;
}

public 
c_menu3(idmenuiditem)
{
    
// Retrieve itemid
    
new buffer[6]
    new 
_accesscallback
    menu_item_getinfo
(menuiditem_accessbuffercharsmax(buffer), __callback)
    
    new 
buffer[0]
    
    if (
MAX_LIMIT[i] > g_admin_count[id][i]) 
        return 
ITEM_ENABLED
        
    
return ITEM_DISABLED        



Exolent[jNr] 05-15-2011 11:51

Re: How to make callback with num_to_str() in menu?
 
Are i and 0 the only data put in the buffer that you want transferred to the callback?

EclipseCP 05-18-2011 02:15

Re: How to make callback with num_to_str() in menu?
 
Quote:

Originally Posted by Exolent[jNr] (Post 1469903)
Are i and 0 the only data put in the buffer that you want transferred to the callback?

yes :) but I cannot because I have to put "num", and if I put "callback" always it appears as that I selected the option 1 :S

Exolent[jNr] 05-18-2011 02:18

Re: How to make callback with num_to_str() in menu?
 
The callback works almost the same as the menu handler.

The way you select the option from the callback is the exact same that you could with the menu handler.

Your buffer variable is useless.

EclipseCP 06-09-2011 07:10

Re: How to make callback with num_to_str() in menu?
 
sorry to revive, but the problem remains :/, it's like always choose the first option

PHP Code:

public show_menu_test(id)
{
    new 
menu[128], lang[32], info[32], buffer[128], menuidi
    
    formatex
(menucharsmax(menu), "\yTest...")
    
    
menuid menu_create(menu"menu_test"

    for (
0sizeof(LANG_MODES); i++) 
    {
        if (
MAX_LIMIT[i] > g_test_count[id][i]) 
            
formatex(infocharsmax(info), "\r[\w%d\r/\w%d\r]"MAX_LIMIT[i] - g_test_count[id][i], MAX_LIMIT[i])
        else
            
formatex(infocharsmax(info), "\r[\y0\r/\w%d\r]"MAX_LIMIT[i])
        
        
formatex(menucharsmax(menu), "%s %s"LANG_MODES[i], info)
        
        
num_to_str(ibuffercharsmax(buffer))
        
        
buffer[0] = i
        buffer
[1] = 0
        menu_additem
(menuidmenubufferADMIN_ALLmenu_makecallback("c_menu3")) 
    }
    
    
// Sin exit
    
formatex(menucharsmax(menu), "%L"id"MENU_BACK")
    
menu_setprop(menuidMPROP_EXITNAMEmenu
    
    
menu_display(idmenuid


public 
menu_test(idmenuiditem)
{
    
// Menu was closed
    
if (item == MENU_EXIT)
    {
        
menu_destroy(menuid
        return 
PLUGIN_HANDLED;
    }
    
    new 
buffer[4], dummyitemid
    menu_item_getinfo
(menuiditemdummybuffercharsmax(buffer), __dummy)
    
    switch (
str_to_num(buffer))
   { 
        case 
1client_print(idprint_center"Option 1")
        case 
2client_print(idprint_center"Option 2")
   }
    
    
menu_destroy(menuid)
    
    
show_menu_player_list(id)
    
    return 
PLUGIN_HANDLED;
}

public 
c_menu3(idmenuiditem)
{
    
// Retrieve itemid
    
new buffer[6]
    new 
_accesscallback
    menu_item_getinfo
(menuiditem_accessbuffercharsmax(buffer), __callback)
    
    new 
buffer[0]
    
    if (
MAX_LIMIT[i] > g_admin_count[id][i]) 
        return 
ITEM_ENABLED
        
    
return ITEM_DISABLED        


How should I do then?

Exolent[jNr] 06-09-2011 19:22

Re: How to make callback with num_to_str() in menu?
 
Remove these:
PHP Code:

        buffer[0] = i
        buffer
[1] = 

Change this:
PHP Code:

    new buffer[0

to this:
PHP Code:

    new str_to_num(buffer



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

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