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

Solved Menu_additem, and menu handler error.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ZaX
Senior Member
Join Date: Jan 2015
Old 04-10-2019 , 04:07   Menu_additem, and menu handler error.
Reply With Quote #1

Hey,

I want to use menu_additem for specific level to show him his item.
So starting with this =>

PHP Code:
new const g_szWeaponsPrimaryList[] =
{
    
"\rTMP ^n",         // 0
    
"\rMAC10 ^n",         // 1
    
"\rUMP-45 ^n",         // 2
    
"\rM3 ^n"          // 3 
Then here is the menu

PHP Code:
    new iMenu menu_create("\wChoose Guns""iMenuHandler")

    for(new 
0sizeof g_szWeaponsPrimaryListi++)
    {
        switch(
crxranks_get_user_level(id))
        {
            case 
0
            { 
                
menu_additem(iMenug_szWeaponsPrimaryList[0], ""// case 0
                
break;
            }
            case 
1:
            {
                
menu_additem(iMenug_szWeaponsPrimaryList[1], ""// case 1
                
break;
            }
            case 
2:
            {
                
menu_additem(iMenug_szWeaponsPrimaryList[2], ""// case 2
                
break;
            }
            case 
3:
            {
                
menu_additem(iMenug_szWeaponsPrimaryList[3], ""// case 3
                
break;
            } 
Everything is fine now, and the menu is showing for the levels i checked, but in the menu handler which is iMenuHandler its excuting only the first case for all, =>
PHP Code:
public iMenuHandler(idiMenuitem)
{
    if(
item == MENU_EXIT)
    {
        
menu_destroy(iMenu)
        return 
PLUGIN_HANDLED
    
}

    switch(
item)
    {
        case 
0:
        {
            if((
cs_get_user_team(id) == CS_TEAM_CT) && (crxranks_get_user_level(id) >= 0))
            {
                
strip_weapons(idPRIMARY_ONLY)
                
strip_weapons(idSECONDARY_ONLY)

                
give_item(id"weapon_tmp")
                
cs_set_user_bpammo(idCSW_TMP200)
            }
        }
        case 
1:
        {
            if((
cs_get_user_team(id) == CS_TEAM_CT) && (crxranks_get_user_level(id) >= 1))
            {
                
strip_weapons(idPRIMARY_ONLY)
                
strip_weapons(idSECONDARY_ONLY)

                
give_item(id"weapon_mac10")
                
cs_set_user_bpammo(idCSW_MAC10200)
            }
        }
        case 
2:
        {
            if((
cs_get_user_team(id) == CS_TEAM_CT) && (crxranks_get_user_level(id) >= 2))
            {
                
strip_weapons(idPRIMARY_ONLY)
                
strip_weapons(idSECONDARY_ONLY)

                
give_item(id"weapon_ump45")
                
cs_set_user_bpammo(idCSW_UMP45200)

            }
        }
        case 
3:
        {
            if((
cs_get_user_team(id) == CS_TEAM_CT) && (crxranks_get_user_level(id) >= 3))
            {
                
strip_weapons(idPRIMARY_ONLY)
                
strip_weapons(idSECONDARY_ONLY)

                
give_item(id"weapon_m3")
                
cs_set_user_bpammo(idCSW_M3200)
            }
        } 
What could be wrong? Now level 3 guy has [M3] on the menu, when he selects it he gets the TMP.
only case 0 is excuting

Last edited by ZaX; 04-14-2019 at 17:22. Reason: old code
ZaX is offline
Airkish
AlliedModders Donor
Join Date: Apr 2016
Location: Lithuania
Old 04-10-2019 , 11:37   Re: Menu_additem, and menu handler error.
Reply With Quote #2

PHP Code:
new const g_szWeaponsPrimaryList[] =
{
    
"\rTMP ^n",
    
"\rMAC10 ^n",
    
"\rUMP-45 ^n",
    
"\rM3 ^n"
}

new const 
g_szWeaponNames[][] =
{
    
"weapon_tmp",
    
"weapon_mac10",
    
"weapon_ump45",
    
"weapon_m3"
}

new const 
g_iWeapons[4] =
{
    
CSW_TMP,
    
CSW_MAC10,
    
CSW_UMP45,
    
CSW_M3

PHP Code:
new iMenu menu_create("\wChoose Guns""iMenuHandler")

for(new 
0sizeof(g_szWeaponsPrimaryList); i++)
{
    if(
!= crxranks_get_user_level(id)) {
        continue;
    }
    
menu_additem(iMenug_szWeaponsPrimaryList[i], "");

PHP Code:
public iMenuHandler(idiMenuitem)
{
    if(
item == MENU_EXIT)
    {
        
menu_destroy(iMenu)
        return 
PLUGIN_HANDLED
    
}

    if(
cs_get_user_team(id) == CS_TEAM_CT)
    {
        
strip_weapons(idPRIMARY_ONLY)
        
strip_weapons(idSECONDARY_ONLY)

        
give_item(idg_szWeaponNames[item])
        
cs_set_user_bpammo(idg_iWeapons[item], 200)
    }

__________________

Last edited by Airkish; 04-11-2019 at 14:20.
Airkish is offline
ZaX
Senior Member
Join Date: Jan 2015
Old 04-10-2019 , 18:53   Re: Menu_additem, and menu handler error.
Reply With Quote #3

This is not what I needed, I mean I could make this, but I dont want the items to be shown for everyone, just the levels I have specified

In the menu register => switch(crxranks_get_user_level(id)) .. I hope you get me

The problem is in the menu handler, case 0 is executing for all items, which means if someone who have level 3, he choses the M3 (case 3 in the menu register), he gets TMP which is case 0 in the handler
ZaX is offline
Airkish
AlliedModders Donor
Join Date: Apr 2016
Location: Lithuania
Old 04-11-2019 , 14:16   Re: Menu_additem, and menu handler error.
Reply With Quote #4

Quote:
Originally Posted by ZaX View Post
This is not what I needed, I mean I could make this, but I dont want the items to be shown for everyone, just the levels I have specified

In the menu register => switch(crxranks_get_user_level(id)) .. I hope you get me

The problem is in the menu handler, case 0 is executing for all items, which means if someone who have level 3, he choses the M3 (case 3 in the menu register), he gets TMP which is case 0 in the handler
That's exactly what my code does, have you even tested?
__________________
Airkish is offline
ZaX
Senior Member
Join Date: Jan 2015
Old 04-12-2019 , 08:45   Re: Menu_additem, and menu handler error.
Reply With Quote #5

But what is the reason that my code is executing only 'case 0' ? With your code, I can use only 1-2-3-4-5-... in order and I cant use like case 5..7, level 5 to 7.
ZaX is offline
Airkish
AlliedModders Donor
Join Date: Apr 2016
Location: Lithuania
Old 04-12-2019 , 13:33   Re: Menu_additem, and menu handler error.
Reply With Quote #6

Quote:
Originally Posted by ZaX View Post
But what is the reason that my code is executing only 'case 0' ? With your code, I can use only 1-2-3-4-5-... in order and I cant use like case 5..7, level 5 to 7.
Because you are adding only 1 menu item depending on user's level which always results in case 0.

My loop executes max 4 times (sizeof(g_szWeaponsPrimaryList) == 4).
Add more weapons or loop till max level.
__________________

Last edited by Airkish; 04-12-2019 at 13:36.
Airkish is offline
ZaX
Senior Member
Join Date: Jan 2015
Old 04-13-2019 , 05:27   Re: Menu_additem, and menu handler error.
Reply With Quote #7

What if I want to use native from another plugin to give guns? Like give_tornado_gun.
ZaX is offline
Airkish
AlliedModders Donor
Join Date: Apr 2016
Location: Lithuania
Old 04-13-2019 , 05:39   Re: Menu_additem, and menu handler error.
Reply With Quote #8

Quote:
Originally Posted by ZaX View Post
What if I want to use native from another plugin to give guns? Like give_tornado_gun.
change give_item(params) to give_tornado_gun(params).
__________________
Airkish is offline
ZaX
Senior Member
Join Date: Jan 2015
Old 04-13-2019 , 06:19   Re: Menu_additem, and menu handler error.
Reply With Quote #9

I think you didnt get what I mean, im using normal guns (from cs 1.6) and natives from other guns,

Well I need to do if(item == x) or use switch in the handler.. I cant use both give_item and native

PS: Is there anyway I can make me code to work?

Last edited by ZaX; 04-13-2019 at 06:21.
ZaX is offline
SHIELD755
Veteran Member
Join Date: Feb 2018
Location: FROM MARVEL STUDIO
Old 04-13-2019 , 06:29   Re: Menu_additem, and menu handler error.
Reply With Quote #10

Quote:
Originally Posted by ZaX View Post
I think you didnt get what I mean, im using normal guns (from cs 1.6) and natives from other guns,

Well I need to do if(item == x) or use switch in the handler.. I cant use both give_item and native

PS: Is there anyway I can make me code to work?
you mean that if any player reach X level than you have to give gun from another plugin

for example :-

player reach level 20 than he will get golden ak47 (for example) from another plugin or golden ak 47 plugin ? am i correct ?
__________________
SED LYF !!!

Last edited by SHIELD755; 04-13-2019 at 06:29.
SHIELD755 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 11:21.


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