Cstrike: Add cs_get_weapon_class() stock (weapon id -> class id)

Note: this has been modified a bit later in cs_is_valid_itemid() commit.
This commit is contained in:
Arkshine 2015-07-26 18:26:12 +02:00
parent 600a15a57b
commit 23b0450938
4 changed files with 98 additions and 10 deletions

View File

@ -56,7 +56,16 @@
#define CSI_SECAMMO 37 // Custom
#define CSI_MAX_COUNT 38
#define BITS_PISTOLS (1<<CSI_GLOCK18 | 1<<CSI_USP | 1<<CSI_P228 | 1<<CSI_DEAGLE | 1<<CSI_ELITE | 1<<CSI_FIVESEVEN)
#define CSI_ALL_WEAPONS CSW_ALL_WEAPONS
#define CSI_ALL_PISTOLS CSW_ALL_PISTOLS
#define CSI_ALL_SHOTGUNS CSW_ALL_SHOTGUNS
#define CSI_ALL_SMGS CSW_ALL_SMGS
#define CSI_ALL_RIFLES CSW_ALL_RIFLES
#define CSI_ALL_SNIPERRIFLES CSW_ALL_SNIPERRIFLES
#define CSI_ALL_MACHINEGUNS CSW_ALL_MACHINEGUNS
#define CSI_ALL_GRENADES CSW_ALL_GRENADES
#define CSI_ALL_ARMORS CSW_ALL_ARMORS
#define CSI_ALL_GUNS CSW_ALL_GUNS
/**
* Weapons Ids.
@ -96,6 +105,17 @@
#define CSW_SHIELDGUN 99
#define CSW_LAST_WEAPON CSW_P90
#define CSW_ALL_WEAPONS (~(1 << CSW_VEST))
#define CSW_ALL_PISTOLS (1 << CSW_P228 | 1 << CSW_ELITE | 1 << CSW_FIVESEVEN | 1 << CSW_USP | 1 << CSW_GLOCK18 | 1 << CSW_DEAGLE)
#define CSW_ALL_SHOTGUNS (1 << CSW_M3 | 1 << CSW_XM1014))
#define CSW_ALL_SMGS (1 << CSW_MAC10 | 1 << CSW_UMP45 | 1 << CSW_MP5NAVY | 1 << CSW_TMP | 1 << CSW_P90))
#define CSW_ALL_RIFLES (1 << CSW_AUG | 1 << CSW_GALIL | 1 << CSW_FAMAS | 1 << CSW_M4A1 | 1 << CSW_AK47 | 1 << CSW_SG552))
#define CSW_ALL_SNIPERRIFLES (1 << CSW_SCOUT | 1 << CSW_AWP | 1 << CSW_G3SG1 | 1 << CSW_SG550))
#define CSW_ALL_MACHINEGUNS (1 << CSW_M249))
#define CSW_ALL_GRENADES (1 << CSW_HEGRENADE | 1 << CSW_SMOKEGRENADE | 1 << CSW_FLASHBANG))
#define CSW_ALL_ARMORS (1 << CSW_VEST | 1 << CSW_VESTHELM)
#define CSW_ALL_GUNS (CSW_ALL_PISTOLS | CSW_ALL_SHOTGUNS | CSW_ALL_SMGS | CSW_ALL_RIFLES | CSW_ALL_SNIPERRIFLES | CSW_ALL_MACHINEGUNS)
/**
* Armoury entity ids for use with cs_get/set_armoury_type().
*/

View File

@ -155,7 +155,18 @@ public stock const Float:NULL_VECTOR[3];
#define CSW_VEST 31 // Custom
#define CSW_VESTHELM 32 // Custom
#define CSW_SHIELDGUN 99
#define CSW_ALLWEAPONS (~(1<<CSW_VEST))
#define CSW_LAST_WEAPON CSW_P90
stock const CSW_ALL_WEAPONS = (~(1<<CSW_VEST));
stock const CSW_ALL_PISTOLS = (1<<CSW_P228 | 1<<CSW_ELITE | 1<<CSW_FIVESEVEN | 1<<CSW_USP | 1<<CSW_GLOCK18 | 1<<CSW_DEAGLE);
stock const CSW_ALL_SHOTGUNS = (1<<CSW_M3 | 1<<CSW_XM1014);
stock const CSW_ALL_SMGS = (1<<CSW_MAC10 | 1<<CSW_UMP45 | 1<<CSW_MP5NAVY | 1<<CSW_TMP | 1<<CSW_P90);
stock const CSW_ALL_RIFLES = (1<<CSW_AUG | 1<<CSW_GALIL | 1<<CSW_FAMAS | 1<<CSW_M4A1 | 1<<CSW_AK47 | 1<<CSW_SG552);
stock const CSW_ALL_SNIPERRIFLES = (1<<CSW_SCOUT | 1<<CSW_AWP | 1<<CSW_G3SG1 | 1<<CSW_SG550);
stock const CSW_ALL_MACHINEGUNS = (1<<CSW_M249);
stock const CSW_ALL_GRENADES = (1<<CSW_HEGRENADE | 1<<CSW_SMOKEGRENADE | 1<<CSW_FLASHBANG);
stock const CSW_ALL_ARMORS = (1<<CSW_VEST | 1<<CSW_VESTHELM);
stock const CSW_ALL_GUNS = (CSW_ALL_PISTOLS | CSW_ALL_SHOTGUNS | CSW_ALL_SMGS | CSW_ALL_RIFLES | CSW_ALL_SNIPERRIFLES | CSW_ALL_MACHINEGUNS);
/**
* HI weapon constants

View File

@ -1054,14 +1054,6 @@ native any:cs_get_item_id(const name[], &CsWeaponClassType:classid = CS_WEAPONCL
*/
native bool:cs_get_translated_item_alias(const alias[], itemname[], maxlength);
/**
*
*/
stock cs_get_weapon_class(weapon_id)
{
}
/**
* Returns some information about a weapon.
*
@ -1073,6 +1065,58 @@ stock cs_get_weapon_class(weapon_id)
*/
native any:cs_get_weapon_info(weapon_id, CsWeaponInfo:type);
/**
* Returns a weapon class id associated with a weapon id.
*
* @param weapon_id Weapon id (CSI_* constants)
*
* @return Weapon class id (CS_WEAPONCLASS_* constants)
*/
stock CsWeaponClassType:cs_get_weapon_class(weapon_id)
{
new CsWeaponClassType:type = CS_WEAPONCLASS_NONE;
if (CSI_NONE <= weapon_id <= CSI_LAST_WEAPON || weapon_id == CSI_SHIELDGUN || weapon_id == CSI_SHIELD)
{
new const bits = (1 << weapon_id);
if (bits & (1 << CSI_KNIFE))
{
type = CS_WEAPONCLASS_KNIFE;
}
else if(bits & CSI_ALL_PISTOLS || weapon_id == CSI_SHIELDGUN || weapon_id == CSI_SHIELD)
{
type = CS_WEAPONCLASS_PISTOL;
}
else if(bits & CSI_ALL_GRENADES)
{
type = CS_WEAPONCLASS_GRENADE;
}
else if(bits & CSI_ALL_SMGS)
{
type = CS_WEAPONCLASS_SUBMACHINEGUN;
}
else if(bits & CSI_ALL_SHOTGUNS)
{
type = CS_WEAPONCLASS_SHOTGUN;
}
else if(bits & CSI_ALL_MACHINEGUNS)
{
type = CS_WEAPONCLASS_MACHINEGUN;
}
else if(bits & CSI_ALL_RIFLES)
{
type = CS_WEAPONCLASS_RIFLE;
}
else if(bits & CSI_ALL_SNIPERRIFLES)
{
type = CS_WEAPONCLASS_SNIPERRIFLE;
}
}
return type;
}
/**
* Called when CS internally fires a command to a player.
*

View File

@ -123,6 +123,7 @@ enum
#define CSI_DEAGLE CSW_DEAGLE
#define CSI_SG552 CSW_SG552
#define CSI_AK47 CSW_AK47
#define CSI_KNIFE CSW_KNIFE
#define CSI_P90 CSW_P90
#define CSI_SHIELDGUN CSW_SHIELDGUN // The real CS value, use CSI_SHELD instead.
#define CSI_VEST CSW_VEST // Custom
@ -133,6 +134,18 @@ enum
#define CSI_PRIAMMO 36 // Custom
#define CSI_SECAMMO 37 // Custom
#define CSI_MAX_COUNT 38
#define CSI_LAST_WEAPON CSW_LAST_WEAPON
#define CSI_ALL_WEAPONS CSW_ALL_WEAPONS
#define CSI_ALL_PISTOLS CSW_ALL_PISTOLS
#define CSI_ALL_SHOTGUNS CSW_ALL_SHOTGUNS
#define CSI_ALL_SMGS CSW_ALL_SMGS
#define CSI_ALL_RIFLES CSW_ALL_RIFLES
#define CSI_ALL_SNIPERRIFLES CSW_ALL_SNIPERRIFLES
#define CSI_ALL_MACHINEGUNS CSW_ALL_MACHINEGUNS
#define CSI_ALL_GRENADES CSW_ALL_GRENADES
#define CSI_ALL_ARMORS CSW_ALL_ARMORS
#define CSI_ALL_GUNS CSW_ALL_GUNS
/**
* Player's movements constants.