Skip to content

Instantly share code, notes, and snippets.

@markski1

markski1/SG.INC

Last active Jun 30, 2020
Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@markski1 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
You can’t perform that action at this time.