AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved Menu_additem, and menu handler error. (https://forums.alliedmods.net/showthread.php?t=315469)

ZaX 04-10-2019 04:07

Menu_additem, and menu handler error.
 
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

Airkish 04-10-2019 11:37

Re: Menu_additem, and menu handler error.
 
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)
    }



ZaX 04-10-2019 18:53

Re: Menu_additem, and menu handler error.
 
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

Airkish 04-11-2019 14:16

Re: Menu_additem, and menu handler error.
 
Quote:

Originally Posted by ZaX (Post 2647031)
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?

ZaX 04-12-2019 08:45

Re: Menu_additem, and menu handler error.
 
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.

Airkish 04-12-2019 13:33

Re: Menu_additem, and menu handler error.
 
Quote:

Originally Posted by ZaX (Post 2647192)
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.

ZaX 04-13-2019 05:27

Re: Menu_additem, and menu handler error.
 
What if I want to use native from another plugin to give guns? Like give_tornado_gun.

Airkish 04-13-2019 05:39

Re: Menu_additem, and menu handler error.
 
Quote:

Originally Posted by ZaX (Post 2647316)
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).

ZaX 04-13-2019 06:19

Re: Menu_additem, and menu handler error.
 
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?

SHIELD755 04-13-2019 06:29

Re: Menu_additem, and menu handler error.
 
Quote:

Originally Posted by ZaX (Post 2647324)
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 ?


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

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