Skip to content

Instantly share code, notes, and snippets.

@markski1
Last active June 30, 2020 07:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markski1/7a5c70f018932c3e0fca9439c03ba6c1 to your computer and use it in GitHub Desktop.
Save markski1/7a5c70f018932c3e0fca9439c03ba6c1 to your computer and use it in GitHub Desktop.
Calculate the amount of shotgun pellets that hit a target based on the given damage. Works for all kinds of shotgun.
/*
2019 by Markski. mrks.cf
The function CalculateSGHitPellets is for calculating the hit pellets of a Sawn-Off shotgun or a Pump Action shotgun.
The function CalculateCSGHitPellets is for calculating the hit pellets of a Combat shotgun.
The functions should only be called if the weaponid is the correct one for each. (Combat Shotgun: 27, Sawn-Off: 26, Pump Action: 25)
Both functions behave the same way.
They must receive the parameter "amount" from your OnPlayerGiveDamage callback in order to return the amount of hit pellets.
I.E. Call from the callback as CalculateSGHitPellets(amount);
They can optionally receive a second parameter to return a percentage of hit pellets instead of amount of hits pellets.
I.E. Call from the callback as CalculateSGHitPellets(amount, 1);
*/
stock CalculateSGHitPellets(Float:amount, percentage=0){
new Float:missedDamage = 49.5 - amount;
if (missedDamage == 0){
if (percentage == 0) return 15;
else return 100;
}
else{
new missedPellets = floatround(missedDamage / 3.30);
missedPellets = 15 - missedPellets;
if (percentage == 0) return missedPellets;
else return (missedPellets * 100) / 15;
}
}
stock CalculateCSGHitPellets(Float:amount, percentage=0){
new Float:missedDamage = 39.60 - amount;
if (missedDamage == 0){
if (percentage == 0) return 8;
else return 100;
}
else{
new missedPellets = floatround(missedDamage / 4.95);
missedPellets = 8 - missedPellets;
if (percentage == 0) return missedPellets;
else return (missedPellets * 100) / 8;
}
}
@markski1
Copy link
Author

markski1 commented Jun 30, 2020

An important bit after being reached about this: As can be observed on the code, the resulting percentages or pellet counts are a function of the damage reported. This will not work if your server does weapon damage changing, be it by memory hacking or any other method! Not without changing 3.30 (sg & sawsg damage) and 4.95 (spas) to the damages your script uses at least.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment