AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   cs_set_user_bpammo not working (https://forums.alliedmods.net/showthread.php?t=330038)

LondoN 01-17-2021 18:18

cs_set_user_bpammo not working
 
Plugin Header

Code:

#define GUN_BITS (1<<CSW_P228|1<<CSW_GLOCK18|1<<CSW_USP|1<<CSW_DEAGLE|1<<CSW_FIVESEVEN|1<<CSW_ELITE|1<<CSW_M3|1<<CSW_XM1014|1<<CSW_TMP|1<<CSW_MP5NAVY|1<<CSW_MAC10|1<<CSW_UMP45|1<<CSW_P90|1<<CSW_AK47|1<<CSW_M4A1|1<<CSW_SCOUT|1<<CSW_SG552|1<<CSW_SG550|1<<CSW_GALIL|1<<CSW_FAMAS|1<<CSW_AWP|1<<CSW_G3SG1|1<<CSW_M249)

new const g_cPrimaryWeaponsName [ ] [ ]  =
{
        "M4A1 Automatic",
        "AK47 Kalashnikov",
        "Famas",
        "Galil",
        "M249 Machine Gun"
};

new const g_cPrimaryWeaponsEntity [ ] [ ] =
{
        "weapon_m4a1",
        "weapon_ak47",
        "weapon_famas",
        "weapon_galil",
        "weapon_m249"
};

where don't work:

Code:

public PRIMARY_WEAPONS_HANDLER ( iEntity, iMenu, iKey )
{
        if ( iKey == MENU_EXIT )
        {
                menu_destroy ( iMenu );
                return;
        }

        give_item ( iEntity, g_cPrimaryWeaponsEntity [ iKey ] );

        new iWeaponID = get_user_weapon ( iEntity );

        if ( GUN_BITS & (1<<iWeaponID) )
                cs_set_user_bpammo ( iEntity, iWeaponID, 90 );
}

it give's me the right weapon but don't give 90 bpammo for that weapon

CrazY. 01-18-2021 08:32

Re: cs_set_user_bpammo not working
 
If the give_item is from the fun module, this may fix the problem. If not, just make sure give_item returns the weapon entity index. If it doesn't work, try debbuging your code.

Code:
public PRIMARY_WEAPONS_HANDLER ( iEntity, iMenu, iKey ) {     if ( iKey == MENU_EXIT )     {         menu_destroy ( iMenu );         return;     }     new iWeaponEntity = give_item ( iEntity, g_cPrimaryWeaponsEntity [ iKey ] );     //new iWeaponID = get_user_weapon ( iEntity );     new iWeaponID = cs_get_weapon_id( iWeaponEntity );     if ( GUN_BITS & (1<<iWeaponID) )         cs_set_user_bpammo ( iEntity, iWeaponID, 90 ); }

By the way, you should be returning PLUGIN_HANDLED in menu handlers, as stated in the docs.
Quote:

* The handler function should always return PLUGIN_HANDLED to block
* any old menu handlers from potentially feeding on the menu, unless
* that is the desired functionality.
https://www.amxmodx.org/api/newmenus/menu_create

LondoN 01-18-2021 12:00

Re: cs_set_user_bpammo not working
 
Code:

new iWeaponEntID = fm_find_ent_by_owner ( -1, g_cPrimaryWeaponsEntity [ iKey ], iEntity )

        if ( iWeaponEntID && pev_valid ( iWeaponEntID ) )
                cs_set_user_bpammo ( iEntity, cs_get_weapon_id ( iWeaponEntID ), 90 );

i've changed the code this way, it's only solution that's working. i wan't to do the fastest way to give weapons in the handler. it was more good that i can work only with single module, not 3 (fun,fakemeta,cstrike)

If anyone can show me up a way to use single module natives to do this handler im opened<3

CrazY. 01-18-2021 13:11

Re: cs_set_user_bpammo not working
 
You may use whatever amount of modules is needed, but avoid fakemeta_util.


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

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