Skip to content

Instantly share code, notes, and snippets.

@markski1 markski1/SG.INC
Last active Aug 3, 2019

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;
}
}
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.