Raised This Month: $ Target: $400
 0% 

new const need help


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
manfailui
Member
Join Date: Jun 2012
Location: Hong Kong
Old 09-29-2012 , 12:17   new const need help
Reply With Quote #1

hi everybody.this is my first post..
i come from hong kong...my eng is so poor...
Please forgive me
-----------------------------------------
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

Last edited by manfailui; 09-29-2012 at 12:44.
manfailui is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 09-29-2012 , 12:25   Re: new const need help
Reply With Quote #2

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.
__________________
What an elegant solution to a problem that doesn't need solving....

Last edited by Liverwiz; 09-29-2012 at 12:47.
Liverwiz is offline
manfailui
Member
Join Date: Jun 2012
Location: Hong Kong
Old 09-29-2012 , 12:31   Re: new const need help
Reply With Quote #3

Quote:
Originally Posted by Liverwiz View Post
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 is offline
manfailui
Member
Join Date: Jun 2012
Location: Hong Kong
Old 09-29-2012 , 12:47   Re: new const need help
Reply With Quote #4

Quote:
Originally Posted by Liverwiz View Post
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

Last edited by manfailui; 09-29-2012 at 12:48.
manfailui is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 09-29-2012 , 12:49   Re: new const need help
Reply With Quote #5

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.
__________________
What an elegant solution to a problem that doesn't need solving....
Liverwiz is offline
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 08:19.


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