Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
//This script is for use in quickly calculating a RANGED fumble result in the Hackmaster RPG system.
//This script is best triggered by a macro setup like the one on the following line
//!RangFumb ?{Enter the number you missed the target by}
//The macro only asks for one value, making it super easy. If you wanted you could also activate the script by entering, "!RangFumb #" into the chat.
//The script rolls a d1000 and adds the value entered with the macro * 10 to determine the fumble result, just as if you'd rolled a real die.
//There's a few variables used to keep track of penalties and penalty durations for sprains, pulls, muscle tears, etc. They are also used for penetrating dice.
//If all goes well, the script will even return multiple results for the rare terrible fumble result of above 1100!
//In some cases the script will get too many repeating results above 1100, resulting in an near infinite loop. To control for this, the script will break out of the loop after 20 iterations.
//If the script needs to break out because of too many iterations, your character has likely died due to their glaring incompetence. Please turn your character sheet over to the DM for processing.
//Thanks to Warklaw, Scott C, and The Aaron for their help in designing this script.
on('chat:message', function(rang) {
var cmdNam;
var msgtxt;
cmdNam = '!RangFumb ';
msgtxt = rang.content;
if(rang.type == 'api' && msgtxt.indexOf(cmdNam) !== -1) {
var missdif = msgtxt.slice(cmdNam.length);
var selfinj = 1;
var rangfumbroll;
var penalty = 0;
var penaltydur = 0;
var pen = 0;
var pendur = 0;
var pendur1 = 0;
var count = 1;
var error = 0;
rangfumbroll = randomInteger(1000)+(Number(missdif)*10);
if (rangfumbroll%2 == 1)
{sendChat("Fumble", "Defender gains a free attack!");}
do
{//log(rangfumbroll);
sendChat("Fumble", "Fumble result is " + rangfumbroll + ".");
if (rangfumbroll < 201)
{sendChat("Fumble", "No special ill effect.");}
else
{if (rangfumbroll < 217)
{sendChat("Fumble", "Sweat in your eyes, -1 attack for 10 seconds.");}
else
{if (rangfumbroll < 233)
{sendChat("Fumble", "Blood in your eyes, -3 attack for 10 seconds.");}
else
{if (rangfumbroll < 248)
{sendChat("Fumble", "Arrow whistles by head of random ally in field of fire. Distraction causes them to be automatically hit by their opponent and the ally's count resets.");}
else
{if (rangfumbroll < 264)
{penaltydur = randomInteger(4);
pendur = penaltydur;
while (pendur == 4)
{pendur = randomInteger(4);
penaltydur = penaltydur + pendur - 1;}
sendChat("Fumble", "Distracted by glare; add " + penaltydur + " seconds wait time before next attack and -4 penalty to Attack whilst so distracted.");}
else
{if (rangfumbroll < 277)
{sendChat("Fumble", "Boot/footgear breaks, -1 to attack until repaired or discarded.");}
else
{if (rangfumbroll < 319)
{sendChat("Fumble", "Backpack, pouch, or other container strap breaks, -1 to attack until item repaired or discarded.");}
else
{if (rangfumbroll < 344)
{sendChat("Fumble", "Belt, girdle, etc. breaks, -1 to attack until item repaired or discarded.");}
else
{if (rangfumbroll < 365)
{sendChat("Fumble", "Armor loosened, -1 to attack until readjusted (by redonning or by another person helping for 10 seconds).");}
else
{if (rangfumbroll < 371)
{sendChat("Fumble", "Armor strap breaks and -2 to attack until repaired.");}
else
{if (rangfumbroll < 437)
{sendChat("Fumble", "Bowstring breaks, Bow useless until replaced.");}
else
{if (rangfumbroll < 509)
{sendChat("Fumble", "String Notch chipped, -1 to attack.");}
else
{if (rangfumbroll < 563)
{sendChat("Fumble", "String Notch badly chipped, -2 to attack.");}
else
{if (rangfumbroll < 581)
{sendChat("Fumble", "Limb cracked, -25% to damage.");}
else
{if (rangfumbroll < 590)
{sendChat("Fumble", "Limb badly cracked, -50% to damage.");}
else
{if (rangfumbroll < 617)
{sendChat("Fumble", "Limb broken (useless).");}
else
{if (rangfumbroll < 631)
{penaltydur = randomInteger(4);
sendChat("Fumble", "Overextend, +" + penaltydur + " seconds penalty to next attack, -2 to next defense roll.");}
else
{if (rangfumbroll < 645)
{penalty = randomInteger(4) + 1;
penaltydur = randomInteger(6);
sendChat("Fumble", "Graze nearest ally in field of fire. Though insufficient to cause a wound, bewildered distraction causes them to suffer a +" + penaltydur + " seconds penalty to next attack and a -" + penalty + " to hit penalty on next attack roll. If the ally is a spellcaster in the midst of casting a spell this counts as 'Caster struck by blow absorbed by body armor' for spell mishaps.");}
else
{if (rangfumbroll < 659)
{penaltydur = randomInteger(4);
sendChat("Fumble", "Off balance, +" + penaltydur + " seconds to next attack.");}
else
{if (rangfumbroll < 673)
{penaltydur = randomInteger(8);
sendChat("Fumble", "Really Overextend, +" + penaltydur + " seconds penalty to next shot.");}
else
{if (rangfumbroll < 687)
{penalty = randomInteger(20);
pen = penalty;
if (pen == 20)
{while (pen > 5)
{pen = randomInteger(6);
penalty = penalty + pen - 1;}}
penalty = penalty + 6;
sendChat("Fumble", "Slip, make a Feat of Agility check vs. " + penalty + " or fall prone and suffer a -6 to all defense and attack rolls for 10 seconds. Righting oneself requires 3 seconds plus time to gather dropped objects.");}
else
{if (rangfumbroll < 695)
{penalty = randomInteger(3);
if (penalty == 1)
{penaltydur = randomInteger(3);}
else
{if (penalty == 2)
{penaltydur = randomInteger(3) + randomInteger(3);}
else
{if (penalty == 3)
{penaltydur = randomInteger(3) + randomInteger(3) + randomInteger(3);}}}
selfinj = randomInteger(6);
if (selfinj == 6)
{penaltydur = penaltydur * 1.5;
sendChat("Fumble", "Muscle tear in right wrist. -" + penalty + " attack penalty. Injury heals over " + penaltydur + " weeks.");}
else
{sendChat("Fumble", "Right wrist is sprained/hyperextended. -" + penalty + " attack penalty. Injury heals over " + penaltydur + " weeks.");}}
else
{if (rangfumbroll < 699)
{penalty = randomInteger(3);
if (penalty == 1)
{penaltydur = randomInteger(3);}
else
{if (penalty == 2)
{penaltydur = randomInteger(3) + randomInteger(3);}
else
{if (penalty == 3)
{penaltydur = randomInteger(3) + randomInteger(3) + randomInteger(3);}}}
selfinj = randomInteger(6);
if (selfinj == 6)
{penaltydur = penaltydur * 1.5;
sendChat("Fumble", "Muscle tear in left wrist. -" + penalty + " attack penalty. Injury heals over " + penaltydur + " weeks.");}
else
{sendChat("Fumble", "Left wrist is sprained/hyperextended. -" + penalty + " attack penalty. Injury heals over " + penaltydur + " weeks.");}}
else
{if (rangfumbroll < 705)
{penalty = randomInteger(3);
if (penalty == 1)
{penaltydur = randomInteger(3);}
else
{if (penalty == 2)
{penaltydur = randomInteger(3) + randomInteger(3);}
else
{if (penalty == 3)
{penaltydur = randomInteger(3) + randomInteger(3) + randomInteger(3);}}}
selfinj = randomInteger(6);
if (selfinj == 6)
{penaltydur = penaltydur * 1.5;
sendChat("Fumble", "Muscle tear in right shoulder. -" + penalty + " attack penalty. Injury heals over " + penaltydur + " weeks.");}
else
{sendChat("Fumble", "Right shoulder is sprained/hyperextended. -" + penalty + " attack penalty. Injury heals over " + penaltydur + " weeks.");}}
else
{if (rangfumbroll < 709)
{penalty = randomInteger(3);
if (penalty == 1)
{penaltydur = randomInteger(3);}
else
{if (penalty == 2)
{penaltydur = randomInteger(3) + randomInteger(3);}
else
{if (penalty == 3)
{penaltydur = randomInteger(3) + randomInteger(3) + randomInteger(3);}}}
selfinj = randomInteger(6);
if (selfinj == 6)
{penaltydur = penaltydur * 1.5;
sendChat("Fumble", "Muscle tear in left shoulder. -" + penalty + " attack penalty. Injury heals over " + penaltydur + " weeks.");}
else
{sendChat("Fumble", "Left shoulder is sprained/hyperextended. -" + penalty + " attack penalty. Injury heals over " + penaltydur + " weeks.");}}
else
{if (rangfumbroll < 713)
{penalty = randomInteger(3);
if (penalty == 1)
{penaltydur = randomInteger(3);}
else
{if (penalty == 2)
{penaltydur = randomInteger(3) + randomInteger(3);}
else
{if (penalty == 3)
{penaltydur = randomInteger(3) + randomInteger(3) + randomInteger(3);}}}
selfinj = randomInteger(6);
if (selfinj == 6)
{penaltydur = penaltydur * 1.5;
sendChat("Fumble", "Muscle tear in right elbow. -" + penalty + " attack penalty. Injury heals over " + penaltydur + " weeks.");}
else
{sendChat("Fumble", "Right elbow is sprained/hyperextended. -" + penalty + " attack penalty. Injury heals over " + penaltydur + " weeks.");}}
else
{if (rangfumbroll < 717)
{penalty = randomInteger(3);
if (penalty == 1)
{penaltydur = randomInteger(3);}
else
{if (penalty == 2)
{penaltydur = randomInteger(3) + randomInteger(3);}
else
{if (penalty == 3)
{penaltydur = randomInteger(3) + randomInteger(3) + randomInteger(3);}}}
selfinj = randomInteger(6);
if (selfinj == 6)
{penaltydur = penaltydur * 1.5;
sendChat("Fumble", "Muscle tear in left elbow. -" + penalty + " attack penalty. Injury heals over " + penaltydur + " weeks.");}
else
{sendChat("Fumble", "Left elbow is sprained/hyperextended. -" + penalty + " attack penalty. Injury heals over " + penaltydur + " weeks.");}}
else
{if (rangfumbroll < 723)
{penalty = randomInteger(3);
if (penalty == 1)
{penaltydur = randomInteger(3);}
else
{if (penalty == 2)
{penaltydur = randomInteger(3) + randomInteger(3);}
else
{if (penalty == 3)
{penaltydur = randomInteger(3) + randomInteger(3) + randomInteger(3);}}}
selfinj = randomInteger(6);
if (selfinj == 6)
{penaltydur = penaltydur * 1.5;
sendChat("Fumble", "Muscle tear in neck. -" + penalty + " attack penalty. Injury heals over " + penaltydur + " weeks.");}
else
{sendChat("Fumble", "Neck is sprained/hyperextended. -" + penalty + " attack penalty. Injury heals over " + penaltydur + " weeks.");}}
else
{if (rangfumbroll < 729)
{penalty = randomInteger(3);
if (penalty == 1)
{penaltydur = randomInteger(3);}
else
{if (penalty == 2)
{penaltydur = randomInteger(3) + randomInteger(3);}
else
{if (penalty == 3)
{penaltydur = randomInteger(3) + randomInteger(3) + randomInteger(3);}}}
selfinj = randomInteger(6);
if (selfinj == 6)
{penaltydur = penaltydur * 1.5;
sendChat("Fumble", "Muscle tear in back. -" + penalty + " attack penalty. Injury heals over " + penaltydur + " weeks.");}
else
{sendChat("Fumble", "Back is sprained/hyperextended. -" + penalty + " attack penalty. Injury heals over " + penaltydur + " weeks.");}}
else
{if (rangfumbroll < 734)
{penalty = randomInteger(4);
pen = penalty;
while (pen == 4)
{pen = randomInteger(4);
penalty = penalty + pen - 1;}
pen = penalty;
penaltydur = 0;
selfinj = randomInteger(6);
if (selfinj == 6)
{while (pen > 0)
{pendur = randomInteger(3);
pendur1 = pendur;
while (pendur == 3)
{pendur = randomInteger(3);
pendur1 = pendur1 + pendur - 1;}
penaltydur = penaltydur + pendur1;
pen = pen - 0.5;}
sendChat("Fumble", "Torn ligament in forearm. -" + penalty + " attack penalty. Injury heals over " + penaltydur + " weeks, but half the penalty is permanent.");}
else
{while (pen > 0)
{pendur = randomInteger(3);
penaltydur = penaltydur + pendur;
pen = pen - 1;}
sendChat("Fumble", "Muscle in forearm is strained/pulled. -" + penalty + " attack penalty. Injury heals over " + penaltydur + " weeks.");}}
else
{if (rangfumbroll < 739)
{penalty = randomInteger(4);
pen = penalty;
while (pen == 4)
{pen = randomInteger(4);
penalty = penalty + pen - 1;}
pen = penalty;
penaltydur = 0;
selfinj = randomInteger(6);
if (selfinj == 6)
{while (pen > 0)
{pendur = randomInteger(3);
pendur1 = pendur;
while (pendur == 3)
{pendur = randomInteger(3);
pendur1 = pendur1 + pendur - 1;}
penaltydur = penaltydur + pendur1;
pen = pen - 0.5;}
sendChat("Fumble", "Torn ligament in bicep. -" + penalty + " attack penalty. Injury heals over " + penaltydur + " weeks, but half the penalty is permanent.");}
else
{while (pen > 0)
{pendur = randomInteger(3);
penaltydur = penaltydur + pendur;
pen = pen - 1;}
sendChat("Fumble", "Muscle in bicep is strained/pulled. -" + penalty + " attack penalty. Injury heals over " + penaltydur + " weeks.");}}
else
{if (rangfumbroll < 744)
{penalty = randomInteger(4);
pen = penalty;
while (pen == 4)
{pen = randomInteger(4);
penalty = penalty + pen - 1;}
pen = penalty;
penaltydur = 0;
selfinj = randomInteger(6);
if (selfinj == 6)
{while (pen > 0)
{pendur = randomInteger(3);
pendur1 = pendur;
while (pendur == 3)
{pendur = randomInteger(3);
pendur1 = pendur1 + pendur - 1;}
penaltydur = penaltydur + pendur1;
pen = pen - 0.5;}
sendChat("Fumble", "Torn ligament in tricep. -" + penalty + " attack penalty. Injury heals over " + penaltydur + " weeks, but half the penalty is permanent.");}
else
{while (pen > 0)
{pendur = randomInteger(3);
penaltydur = penaltydur + pendur;
pen = pen - 1;}
sendChat("Fumble", "Muscle in tricep is strained/pulled. -" + penalty + " attack penalty. Injury heals over " + penaltydur + " weeks.");}}
else
{if (rangfumbroll < 749)
{penalty = randomInteger(4);
pen = penalty;
while (pen == 4)
{pen = randomInteger(4);
penalty = penalty + pen - 1;}
pen = penalty;
penaltydur = 0;
selfinj = randomInteger(6);
if (selfinj == 6)
{while (pen > 0)
{pendur = randomInteger(3);
pendur1 = pendur;
while (pendur == 3)
{pendur = randomInteger(3);
pendur1 = pendur1 + pendur - 1;}
penaltydur = penaltydur + pendur1;
pen = pen - 0.5;}
sendChat("Fumble", "Torn ligament in lower back. -" + penalty + " attack penalty. Injury heals over " + penaltydur + " weeks, but half the penalty is permanent.");}
else
{while (pen > 0)
{pendur = randomInteger(3);
penaltydur = penaltydur + pendur;
pen = pen - 1;}
sendChat("Fumble", "Muscle in lower back is strained/pulled. -" + penalty + " attack penalty. Injury heals over " + penaltydur + " weeks.");}}
else
{if (rangfumbroll < 754)
{penalty = randomInteger(4);
pen = penalty;
while (pen == 4)
{pen = randomInteger(4);
penalty = penalty + pen - 1;}
pen = penalty;
penaltydur = 0;
selfinj = randomInteger(6);
if (selfinj == 6)
{while (pen > 0)
{pendur = randomInteger(3);
pendur1 = pendur;
while (pendur == 3)
{pendur = randomInteger(3);
pendur1 = pendur1 + pendur - 1;}
penaltydur = penaltydur + pendur1;
pen = pen - 0.5;}
sendChat("Fumble", "Torn ligament in side. -" + penalty + " attack penalty. Injury heals over " + penaltydur + " weeks, but half the penalty is permanent.");}
else
{while (pen > 0)
{pendur = randomInteger(3);
penaltydur = penaltydur + pendur;
pen = pen - 1;}
sendChat("Fumble", "Muscle in side is strained/pulled. -" + penalty + " attack penalty. Injury heals over " + penaltydur + " weeks.");}}
else
{if (rangfumbroll < 759)
{penalty = randomInteger(4);
pen = penalty;
while (pen == 4)
{pen = randomInteger(4);
penalty = penalty + pen - 1;}
pen = penalty;
penaltydur = 0;
selfinj = randomInteger(6);
if (selfinj == 6)
{while (pen > 0)
{pendur = randomInteger(3);
pendur1 = pendur;
while (pendur == 3)
{pendur = randomInteger(3);
pendur1 = pendur1 + pendur - 1;}
penaltydur = penaltydur + pendur1;
pen = pen - 0.5;}
sendChat("Fumble", "Torn ligament in upper back. -" + penalty + " attack penalty. Injury heals over " + penaltydur + " weeks, but half the penalty is permanent.");}
else
{while (pen > 0)
{pendur = randomInteger(3);
penaltydur = penaltydur + pendur;
pen = pen - 1;}
sendChat("Fumble", "Muscle in upper back is strained/pulled. -" + penalty + " attack penalty. Injury heals over " + penaltydur + " weeks.");}}
else
{if (rangfumbroll < 764)
{penalty = randomInteger(4);
pen = penalty;
while (pen == 4)
{pen = randomInteger(4);
penalty = penalty + pen - 1;}
pen = penalty;
penaltydur = 0;
selfinj = randomInteger(6);
if (selfinj == 6)
{while (pen > 0)
{pendur = randomInteger(3);
pendur1 = pendur;
while (pendur == 3)
{pendur = randomInteger(3);
pendur1 = pendur1 + pendur - 1;}
penaltydur = penaltydur + pendur1;
pen = pen - 0.5;}
sendChat("Fumble", "Torn ligament in left shoulder. -" + penalty + " attack penalty. Injury heals over " + penaltydur + " weeks, but half the penalty is permanent.");}
else
{while (pen > 0)
{pendur = randomInteger(3);
penaltydur = penaltydur + pendur;
pen = pen - 1;}
sendChat("Fumble", "Muscle in left shoulder is strained/pulled. -" + penalty + " attack penalty. Injury heals over " + penaltydur + " weeks.");}}
else
{if (rangfumbroll < 769)
{penalty = randomInteger(4);
pen = penalty;
while (pen == 4)
{pen = randomInteger(4);
penalty = penalty + pen - 1;}
pen = penalty;
penaltydur = 0;
selfinj = randomInteger(6);
if (selfinj == 6)
{while (pen > 0)
{pendur = randomInteger(3);
pendur1 = pendur;
while (pendur == 3)
{pendur = randomInteger(3);
pendur1 = pendur1 + pendur - 1;}
penaltydur = penaltydur + pendur1;
pen = pen - 0.5;}
sendChat("Fumble", "Torn ligament in right shoulder. -" + penalty + " attack penalty. Injury heals over " + penaltydur + " weeks, but half the penalty is permanent.");}
else
{while (pen > 0)
{pendur = randomInteger(3);
penaltydur = penaltydur + pendur;
pen = pen - 1;}
sendChat("Fumble", "Muscle in right shoulder is strained/pulled. -" + penalty + " attack penalty. Injury heals over " + penaltydur + " weeks.");}}
else
{if (rangfumbroll < 775)
{penalty = randomInteger(4);
pen = penalty;
while (pen == 4)
{pen = randomInteger(4);
penalty = penalty + pen - 1;}
pen = penalty;
penaltydur = 0;
selfinj = randomInteger(6);
if (selfinj == 6)
{while (pen > 0)
{pendur = randomInteger(3);
pendur1 = pendur;
while (pendur == 3)
{pendur = randomInteger(3);
pendur1 = pendur1 + pendur - 1;}
penaltydur = penaltydur + pendur1;
pen = pen - 0.5;}
sendChat("Fumble", "Torn ligament in neck. -" + penalty + " attack penalty. Injury heals over " + penaltydur + " weeks, but half the penalty is permanent.");}
else
{while (pen > 0)
{pendur = randomInteger(3);
penaltydur = penaltydur + pendur;
pen = pen - 1;}
sendChat("Fumble", "Muscle in neck is strained/pulled. -" + penalty + " attack penalty. Injury heals over " + penaltydur + " weeks.");}}
else
{if (rangfumbroll < 865)
{sendChat("Fumble", "Automatically hit a random ally in the field of fire. Roll damage dice and add strength bonus (if applicable), but do not add bonuses from talents or specialization.");}
else
{if (rangfumbroll < 942)
{sendChat("Fumble", "Drop bow at feet.");}
else
{if (rangfumbroll < 965)
{sendChat("Fumble", "Drop bow 2 feet away.");}
else
{if (rangfumbroll < 983)
{sendChat("Fumble", "Drop bow 3 feet away.");}
else
{if (rangfumbroll < 1045)
{sendChat("Fumble", "Bowstring breaks, Bow useless until replaced.");}
else
{if (rangfumbroll < 1101)
{penalty = randomInteger(20);
pen = penalty;
if (pen == 20)
{while (pen > 5)
{pen = randomInteger(6);
penalty = penalty + pen - 1;}}
sendChat("Fumble", "Shoot own hand or foot. Roll damage dice and add strength bonus (if applicable), but do not add bonuses from talents or specialization. Attempt a Feat of Agility check vs. " + penalty + " to sustain only half damage.");}
else
{if (rangfumbroll < 1201)
{count = count + 2;
sendChat("Fumble", "Double results! If identical results are obtained, then add the durations together.");
//log("At roll 1 Count " + count);
}
else
{count = count + 3;
sendChat("Fumble", "Triple results! If identical results are obtained, then add the durations together.");
//log("At roll 2 Count " + count);
}
}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
count = count - 1;
error = error + 1;
if (error > 19)
{break;}
rangfumbroll = randomInteger(1000)+(Number(missdif)*10);
//log("Count" + count);
} while (count > 0)
if (error > 19)
{sendChat("Fumble", "You got too many additional results and the script might crash! You have " + count + " additional results left to roll. You can try using the script again or roll the results individually on your own.");
sendChat("Fumble", "Or you could just accept your inevitable death. That's on you.");}
return;};
});
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.