From 9111520bbd3e41f28acaed5e9b4ebfc7eb9ba1f6 Mon Sep 17 00:00:00 2001 From: WoutProvost Date: Mon, 12 Dec 2022 00:49:54 +0100 Subject: [PATCH] Add weapon constants and methods --- README.md | 7 ++ util/weapon.inc | 217 +++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 221 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4bc9023..d5855ab 100644 --- a/README.md +++ b/README.md @@ -232,11 +232,18 @@ forward OnPlayerUnpause(playerid); --> ### Weapon.inc ```pawn +#define MAX_WEAPONS 47 #define INVALID_WEAPON_ID -1 +#define WEAPON_FISTS 0 +#define WEAPON_NIGHTVISION 44 +#define WEAPON_INFRARED 45 #define MAX_WEAPON_NAME 31 bool:IsValidWeapon(weaponid); GetWeaponModel(weaponid); +bool:IsWeaponSprintAllowed(weaponid); +bool:IsWeaponCrouchAllowed(weaponid); +Float:GetWeaponDamage(weaponid); Float:GetWeaponVehicleDamage(weaponid); bool:IsMeleeWeapon(weaponid); GetWeaponName(weaponid, name[], len); diff --git a/util/weapon.inc b/util/weapon.inc index 53a7c7e..de5e2d0 100644 --- a/util/weapon.inc +++ b/util/weapon.inc @@ -3,6 +3,13 @@ #endif #define _mainweapon_included +// WEAPON AMOUNT LIMIT +/** + * -DESCRIPTION: + * -Defines the weapon amount limit. + */ +#define MAX_WEAPONS 47 + // INVALID WEAPON /** * -DESCRIPTION: @@ -10,6 +17,15 @@ */ #define INVALID_WEAPON_ID -1 +// WEAPON ID +/** + * -DESCRIPTION: + * -Defines some missing weapon ID constants. + */ +#define WEAPON_FISTS 0 +#define WEAPON_NIGHTVISION 44 +#define WEAPON_INFRARED 45 + // NAMES /** * -DESCRIPTION: @@ -47,7 +63,7 @@ static const MainWeapon_WeaponNames[][] = { */ // native bool:IsValidWeapon(weaponid); // Fake native stock bool:IsValidWeapon(weaponid) { - if((weaponid >= 0 && weaponid <= 18) || (weaponid >= 22 && weaponid <= 46)) { + if((weaponid >= 0 && weaponid <= 18) || (weaponid >= 22 && weaponid < MAX_WEAPONS)) { return true; } return false; @@ -89,12 +105,207 @@ static const MainWeapon_WeaponModels[] = { */ // native GetWeaponModel(weaponid); // Fake native stock GetWeaponModel(weaponid) { - if(weaponid >= 0 && weaponid <= 46) { + if(weaponid >= 0 && weaponid < MAX_WEAPONS) { return MainWeapon_WeaponModels[weaponid]; } return INVALID_MODEL_ID; } +// IS WEAPON SPRINT ALLOWED +/** + * -DESCRIPTION: + * -Get whether a weapon ID allows sprinting. + * -PARAMETERS: + * -weaponid: The ID of the weapon to get whether it allows sprinting. + * -RETURN VALUES: + * -true: The function executed successfully. The weapon ID allows sprinting. + * -false: The function executed successfully. The weapon ID does not allow sprinting. + */ +// native bool:IsWeaponSprintAllowed(weaponid); // Fake native +stock bool:IsWeaponSprintAllowed(weaponid) { + switch(weaponid) { + case WEAPON_FISTS: return true; + case WEAPON_BRASSKNUCKLE: return true; + case WEAPON_GOLFCLUB: return true; + case WEAPON_NITESTICK: return true; + case WEAPON_KNIFE: return true; + case WEAPON_BAT: return false; + case WEAPON_SHOVEL: return false; + case WEAPON_POOLSTICK: return false; + case WEAPON_KATANA: return true; + case WEAPON_CHAINSAW: return false; + case WEAPON_DILDO: return true; + case WEAPON_DILDO2: return true; + case WEAPON_VIBRATOR: return true; + case WEAPON_VIBRATOR2: return true; + case WEAPON_FLOWER: return true; + case WEAPON_CANE: return true; + case WEAPON_GRENADE: return true; + case WEAPON_TEARGAS: return true; + case WEAPON_MOLTOV: return true; + case 19: return false; + case 20: return false; + case 21: return false; + case WEAPON_COLT45: return true; + case WEAPON_SILENCED: return true; + case WEAPON_DEAGLE: return true; + case WEAPON_SHOTGUN: return false; + case WEAPON_SAWEDOFF: return true; + case WEAPON_SHOTGSPA: return false; + case WEAPON_UZI: return true; + case WEAPON_MP5: return true; + case WEAPON_AK47: return false; + case WEAPON_M4: return false; + case WEAPON_TEC9: return true; + case WEAPON_RIFLE: return false; + case WEAPON_SNIPER: return false; + case WEAPON_ROCKETLAUNCHER: return false; + case WEAPON_HEATSEEKER: return false; + case WEAPON_FLAMETHROWER: return false; + case WEAPON_MINIGUN: return false; + case WEAPON_SATCHEL: return true; + case WEAPON_BOMB: return true; + case WEAPON_SPRAYCAN: return true; + case WEAPON_FIREEXTINGUISHER: return true; + case WEAPON_CAMERA: return true; + case WEAPON_NIGHTVISION: return true; + case WEAPON_INFRARED: return true; + case WEAPON_PARACHUTE: return true; + } + return false; +} + +// IS WEAPON CROUCH ALLOWED +/** + * -DESCRIPTION: + * -Get whether a weapon ID allows crouching. + * -PARAMETERS: + * -weaponid: The ID of the weapon to get whether it allows crouching. + * -RETURN VALUES: + * -true: The function executed successfully. The weapon ID allows crouching. + * -false: The function executed successfully. The weapon ID does not allow crouching. + */ +// native bool:IsWeaponCrouchAllowed(weaponid); // Fake native +stock bool:IsWeaponCrouchAllowed(weaponid) { + switch(weaponid) { + case WEAPON_FISTS: return true; + case WEAPON_BRASSKNUCKLE: return true; + case WEAPON_GOLFCLUB: return true; + case WEAPON_NITESTICK: return true; + case WEAPON_KNIFE: return true; + case WEAPON_BAT: return true; + case WEAPON_SHOVEL: return true; + case WEAPON_POOLSTICK: return true; + case WEAPON_KATANA: return true; + case WEAPON_CHAINSAW: return true; + case WEAPON_DILDO: return true; + case WEAPON_DILDO2: return true; + case WEAPON_VIBRATOR: return true; + case WEAPON_VIBRATOR2: return true; + case WEAPON_FLOWER: return true; + case WEAPON_CANE: return true; + case WEAPON_GRENADE: return false; + case WEAPON_TEARGAS: return false; + case WEAPON_MOLTOV: return false; + case 19: return false; + case 20: return false; + case 21: return false; + case WEAPON_COLT45: return true; + case WEAPON_SILENCED: return true; + case WEAPON_DEAGLE: return true; + case WEAPON_SHOTGUN: return true; + case WEAPON_SAWEDOFF: return true; + case WEAPON_SHOTGSPA: return true; + case WEAPON_UZI: return true; + case WEAPON_MP5: return true; + case WEAPON_AK47: return true; + case WEAPON_M4: return true; + case WEAPON_TEC9: return true; + case WEAPON_RIFLE: return true; + case WEAPON_SNIPER: return true; + case WEAPON_ROCKETLAUNCHER: return false; + case WEAPON_HEATSEEKER: return false; + case WEAPON_FLAMETHROWER: return false; + case WEAPON_MINIGUN: return false; + case WEAPON_SATCHEL: return false; + case WEAPON_BOMB: return true; + case WEAPON_SPRAYCAN: return true; + case WEAPON_FIREEXTINGUISHER: return false; + case WEAPON_CAMERA: return false; + case WEAPON_NIGHTVISION: return true; + case WEAPON_INFRARED: return true; + case WEAPON_PARACHUTE: return true; + } + return false; +} + +// GET WEAPON DAMAGE +/** + * -DESCRIPTION: + * -Get a weapon's damage. + * -PARAMETERS: + * -weaponid: The ID of the weapon to get the damage of. + * -RETURN VALUES: + * -valid damage: The function executed successfully. + * -0.0: + * -The function executed successfully. The weaponid doesn't have a non-zero damage. + * -The function failed to execute. An invalid weaponid was given. + */ +// native Float:GetWeaponDamage(weaponid); // Fake native +stock Float:GetWeaponDamage(weaponid) { + new Float:damage = 0.0; + switch(weaponid) { + case WEAPON_FISTS: damage = 5.0; + case WEAPON_BRASSKNUCKLE: damage = 5.0; + case WEAPON_GOLFCLUB: damage = 5.0; + case WEAPON_NITESTICK: damage = 5.0; + case WEAPON_KNIFE: damage = 5.0; + case WEAPON_BAT: damage = 5.0; + case WEAPON_SHOVEL: damage = 5.0; + case WEAPON_POOLSTICK: damage = 5.0; + case WEAPON_KATANA: damage = 5.0; + case WEAPON_CHAINSAW: damage = 5.0; + case WEAPON_DILDO: damage = 5.0; + case WEAPON_DILDO2: damage = 5.0; + case WEAPON_VIBRATOR: damage = 5.0; + case WEAPON_VIBRATOR2: damage = 5.0; + case WEAPON_FLOWER: damage = 5.0; + case WEAPON_CANE: damage = 5.0; + case WEAPON_GRENADE: damage = 5.0; + case WEAPON_TEARGAS: damage = 5.0; + case WEAPON_MOLTOV: damage = 5.0; + case 19: damage = 0.0; + case 20: damage = 0.0; + case 21: damage = 0.0; + case WEAPON_COLT45: damage = 8.25; + case WEAPON_SILENCED: damage = 13.2; + case WEAPON_DEAGLE: damage = 46.2; + case WEAPON_SHOTGUN: damage = 30.0; + case WEAPON_SAWEDOFF: damage = 30.0; + case WEAPON_SHOTGSPA: damage = 30.0; + case WEAPON_UZI: damage = 6.60; + case WEAPON_MP5: damage = 8.25; + case WEAPON_AK47: damage = 9.90; + case WEAPON_M4: damage = 9.90; + case WEAPON_TEC9: damage = 6.60; + case WEAPON_RIFLE: damage = 24.8; + case WEAPON_SNIPER: damage = 41.3; + case WEAPON_ROCKETLAUNCHER: damage = 5.0; + case WEAPON_HEATSEEKER: damage = 5.0; + case WEAPON_FLAMETHROWER: damage = 5.0; + case WEAPON_MINIGUN: damage = 46.2; + case WEAPON_SATCHEL: damage = 5.0; + case WEAPON_BOMB: damage = 5.0; + case WEAPON_SPRAYCAN: damage = 5.0; + case WEAPON_FIREEXTINGUISHER: damage = 5.0; + case WEAPON_CAMERA: damage = 0.0; + case WEAPON_NIGHTVISION: damage = 0.0; + case WEAPON_INFRARED: damage = 0.0; + case WEAPON_PARACHUTE: damage = 0.0; + } + return damage; +} + // GET WEAPON VEHICLE DAMAGE /** * -DESCRIPTION: @@ -166,7 +377,7 @@ stock bool:IsMeleeWeapon(weaponid) { */ // native GetWeaponName(weaponid, name[], len); // Fake native stock MainWeapon_GetWeaponName(weaponid, name[], len) { - if(weaponid >= 0 && weaponid <= 46) { + if(weaponid >= 0 && weaponid < MAX_WEAPONS) { // NAMES return strmid(name, MainWeapon_WeaponNames[weaponid], 0, len, len); }