AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   new const need help (https://forums.alliedmods.net/showthread.php?t=197143)

manfailui 09-29-2012 12:17

new const need help
 
hi everybody.this is my first post..
i come from hong kong...my eng is so poor...
Please forgive me:3:3
-----------------------------------------
PHP Code:

#define MAX_ITEM_TYPE 3

new const item_name[MAX_ITEM_TYPE][] =
{
    
a,
    
b,
    
c
}

new const 
item_type[][] =
{
    
code_a,
    
code_b,
    
code_c
}

public 
code_a(id)
{
    
user_kill(id)
}

public 
code_b(id)
{
    
client_print(idprint_chat"you're choose the item b")
}

public 
code_c(id)
{
    
give_item(id"weapon_ak47")


i want to use menu make it work

like this

PHP Code:

public top_menu(id)
{
    new 
szInfo[60]
    new 
szTempid[32]
    
    
formatex(szInfo59"menu")
    new 
menu menu_create(szInfo "top_menu2")
    
    for(new 
0MAX_ITEM_TYPEi++)
    {
        new 
szItems[60]
        
formatex(szItems59"&s"item_name[i])
        
num_to_str(iszTempid31)
        
menu_additem(menuszItemsszTempid0)
    }
    
    
menu_setprop(menuMPROP_EXITMEXIT_ALL)
    
menu_display(idmenu0)
    
    return 
PLUGIN_HANDLED
}

public 
top_menu2(id menu item
{
    if(
item == MENU_EXIT)
    return 
PLUGIN_HANDLED
    
    
new data[6], iName[64]
    new 
accesscallback
    menu_item_getinfo
(menuitemaccessdata,5iName63callback)

    new 
str_to_num(data)
    
    
item_type[id][i//<------here..=_=
    
    
menu_destroy(menu)
    return 
PLUGIN_HANDLED


But it is sure not work
who can help me and make it work
thank you

Liverwiz 09-29-2012 12:25

Re: new const need help
 
try instead of making MAX_ITEM_TYPE a define. make it a global var and give it a value in plugin_init upon compilation.
As such....

PHP Code:

new MAX_ITEM_TYPE

new const item_name[][] =
{
    
"a",
    
"b",
    
"c"
}

public 
plugin_init()
    
MAX_ITEM_TYPE sizeof(item_name

Also make sure that the last item in an array DOES NOT have a comma after it. And everything that is supposed to be a string is inside quotes. I corrected the first array as an example. You do the rest.

manfailui 09-29-2012 12:31

Re: new const need help
 
Quote:

Originally Posted by Liverwiz (Post 1808962)
try instead of making MAX_ITEM_TYPE a define. make it a global var and give it a value in plugin_init upon compilation.
As such....

PHP Code:

new MAX_ITEM_TYPE

new const item_name[MAX_ITEM_TYPE][] =
{
    
"a",
    
"b",
    
"c"
}

public 
plugin_init()
    
MAX_ITEM_TYPE sizeof(item_name

Also make sure that the last item in an array DOES NOT have a comma after it. And everything that is supposed to be a string is inside quotes. I corrected the first array as an example. You do the rest.

ok thank you first..i try later

manfailui 09-29-2012 12:47

Re: new const need help
 
Quote:

Originally Posted by Liverwiz (Post 1808962)
try instead of making MAX_ITEM_TYPE a define. make it a global var and give it a value in plugin_init upon compilation.
As such....

PHP Code:

new MAX_ITEM_TYPE

new const item_name[MAX_ITEM_TYPE][] =
{
    
"a",
    
"b",
    
"c"
}

public 
plugin_init()
    
MAX_ITEM_TYPE sizeof(item_name

Also make sure that the last item in an array DOES NOT have a comma after it. And everything that is supposed to be a string is inside quotes. I corrected the first array as an example. You do the rest.

no..i want to use new const and switch(key) in menu to trigger the code block

Liverwiz 09-29-2012 12:49

Re: new const need help
 
IMPORTANT NOTE: you must remove MAX_ITEM_TYPE from your array declaration. Otherwise it will not compile. I forgot about that, but i fixed my above code now.


All times are GMT -4. The time now is 08:19.

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