Skip to content

Commit

Permalink
Add weapon constants and methods
Browse files Browse the repository at this point in the history
  • Loading branch information
WoutProvost committed Dec 11, 2022
1 parent 409ac9f commit 9111520
Show file tree
Hide file tree
Showing 2 changed files with 221 additions and 3 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
217 changes: 214 additions & 3 deletions util/weapon.inc
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,29 @@
#endif
#define _mainweapon_included

// WEAPON AMOUNT LIMIT
/**
* -DESCRIPTION:
* -Defines the weapon amount limit.
*/
#define MAX_WEAPONS 47

// INVALID WEAPON
/**
* -DESCRIPTION:
* -Defines an invalid weapon ID.
*/
#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:
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 9111520

Please sign in to comment.