s1lentq / reapi

AMX Mod X module, using API regamedll & rehlds
GNU General Public License v3.0
159 stars 104 forks source link

[Feature Request] Check if player has a custom item #149

Open twisterniq opened 5 years ago

twisterniq commented 5 years ago

Title. At the moment we have rg_has_item_by_name to check if player has a specified item, but we can't check if it's a custom item. Maybe extend that native adding the third argument bool:custom = false? Or create a new one.

At the moment I use that method to check if player has custom item:

bool:func_HasUserCustomWeapon(id)
{
    new iEntWeapon = rg_get_user_weaponent(id, any:WEAPON_ID, PRIMARY_WEAPON_SLOT);
    return bool:(iEntWeapon && iEntWeapon != NULLENT && IsCustomWeapon(iEntWeapon));
}

const CSW_ALL_PISTOLS       = (1<<CSW_P228  | 1<<CSW_ELITE | 1<<CSW_FIVESEVEN | 1<<CSW_USP | 1<<CSW_GLOCK18 | 1<<CSW_DEAGLE);
const CSW_ALL_SHOTGUNS      = (1<<CSW_M3    | 1<<CSW_XM1014);
const CSW_ALL_SMGS          = (1<<CSW_MAC10 | 1<<CSW_UMP45 | 1<<CSW_MP5NAVY | 1<<CSW_TMP  | 1<<CSW_P90);
const CSW_ALL_RIFLES        = (1<<CSW_AUG   | 1<<CSW_GALIL | 1<<CSW_FAMAS   | 1<<CSW_M4A1 | 1<<CSW_AK47 | 1<<CSW_SG552);
const CSW_ALL_SNIPERRIFLES  = (1<<CSW_SCOUT | 1<<CSW_AWP   | 1<<CSW_G3SG1   | 1<<CSW_SG550);
const CSW_ALL_MACHINEGUNS   = (1<<CSW_M249);
const CSW_ALL_GRENADES      = (1<<CSW_HEGRENADE | 1<<CSW_SMOKEGRENADE | 1<<CSW_FLASHBANG);
const CSW_ALL_GUNS          = (CSW_ALL_PISTOLS | CSW_ALL_SHOTGUNS | CSW_ALL_SMGS | CSW_ALL_RIFLES | CSW_ALL_SNIPERRIFLES | CSW_ALL_MACHINEGUNS);

const CSW_PRIMARIES_BITSUM  = (CSW_ALL_SHOTGUNS|CSW_ALL_SMGS|CSW_ALL_RIFLES|CSW_ALL_SNIPERRIFLES|CSW_ALL_MACHINEGUNS);

stock rg_get_user_weaponent(id, iWeaponIdType, InventorySlotType:iSlot = NONE_SLOT)
{
    new iWeapon;

    if(!iSlot)
    {
        if(CSW_PRIMARIES_BITSUM & (1<<iWeaponIdType))
            iSlot = PRIMARY_WEAPON_SLOT;
        else if(CSW_ALL_PISTOLS & (1<<iWeaponIdType))
            iSlot = PISTOL_SLOT;
        else if(iWeaponIdType == CSW_KNIFE)
            iSlot = KNIFE_SLOT;
        else if(CSW_ALL_GRENADES & (1<<iWeaponIdType))
            iSlot = GRENADE_SLOT;
        else if(iWeaponIdType == CSW_C4)
            iSlot = C4_SLOT;
    }

    iWeapon = get_member(id, m_rgpPlayerItems, iSlot);

    while(is_entity(iWeapon))
    {
        if(get_member(iWeapon, m_iId) == iWeaponIdType)
            return iWeapon;

        iWeapon = get_member(iWeapon, m_pNext);
    }

    return 0;
}
afwn90cj93201nixr2e1re commented 4 years ago

Better to implement rg_has_item_by_id, and then check anything that u want.