Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

[Help]Dice Script w/ Percentage of Success

1401204088

Edited 1401204157
Good Afternoon Knowledgeable API scriptors, I will be running a game this weekend that has some difficult math associated with dice rolls. It requires two digit math as well as calculating percentages for the type of strikes in combat. I couldn't get a simplified macro working for me, as the percentages were too difficult for me to figure out. What i need this macro/API script to do is the following. In this example, we'll assume the attacker has a Strike chance of (68) & the target has a defense value of (12) My strike chance for swinging my sword is (68) The macro then asks you to input your target's Defense Value (12) The Macro then asks you to input total modifiers (-10 for attacking in darkness, for example) My chance to hit is (68)-(14)-(10)=44% chance to hit on a 1d100 However, I would like the rolled to determine the following If I roll a Natural '00', I "Fumble" If I roll 30+ over the hit number, the target "Ripostes" If I toll greater than the hit number(44), I "Miss" If I roll the hit number (44) or less, I "Normal Strike" If i roll 50%(1/2) of hit number(44) or less, I "Pressing Strike" If i roll 20%(1/5) of hit number(44) or less, I "Solid Strike" If i roll 5%(1/20) of hit number(44) or less, I "Critical Strike" My complete and utter gratitude to those that help me with this Macro/API script. Please let me know if this type of rolling is impossible or too difficult for current scripting or macros. -William
1401207767

Edited 1401207820
Lithl
Pro
Sheet Author
API Scripter
Syntax: !strike defense modifier Example: !strike @{target|Defense} ?{Modifiers|0} The value of Modifiers may be positive or negative. (Assumption: Tokens are linked to character sheets, and characters have an attribute named "Defense". "?{Target Defense}" could replace the @target, of course.) on('chat:message', function(msg) { if (msg.type != 'api') return; var parts = msg.content.split(' '); var command = parts.shift().substring(1); if (command != 'strike') return; if (parts.length < 2) { sendChat('SYSTEM', '!strike command requires target defense and roll modifiers.'); return; } var defense = parseInt(parts[0]); var modifiers = parseInt(parts[1]); if (isNaN(defense) || isNaN(modifiers)) { sendChat('SYSTEM', 'Error parsing parameters.'); return; } var who = findObjs({ type: 'player', displayname: msg.who.indexOf(' (GM)') > -1 ? msg.who.substring(0, msg.who.indexOf(' (GM)')) : msg.who })[0]; // Assumption: No two players share a display name var character; if (who) { character = findObjs({ type: 'character', controlledby: who.id })[0]; // Assumption: No player controls more than one character } else { character = findObjs({ type: 'character', name: msg.who })[0]; } var roll = randomInteger(100); // Note: The 3D dice will not appear var strike = getAttrByName(character.id, 'Strike'); // Assumption: Characters have an attribute named "Strike" // Note: getAttrByName will not be available on main server until Wednesday 5/28 var toHit = strike - defense + modifiers; var connectText = character.get('name'); if (roll == 100) { connectText += ' fumbles!'; } else if (roll >= toHit + 30) { connectText += '\'s opponent ripostes!'; } else if (roll > toHit) { connectText += ' misses.'; } else if (roll <= toHit * 0.05) { connectText += ' makes a critical strike!'; } else if (roll <= toHit * 0.2) { connectText += ' makes a solid strike!'; } else if (roll <= toHit * 0.5) { connectText += ' makes a pressing strike!'; } else if (roll <= toHit) { connectText += ' strikes the target.'; } else { connectText = 'There is an error in the !strike logic'; } connectText += ' (' + ('0' + roll).slice(-2) + ' vs ' + toHit + ')'; sendChat('SYSTEM', connectText); });
1401208160

Edited 1401208428
Thanks a lot Brian! I couldn't have scripted that myself, API scripting certainly is a wonder to those of us who aren't unfamiliar. I will try this macro out when the update hits on Wednesday & let you know how it went. Thanks again, William
1401210314
Lithl
Pro
Sheet Author
API Scripter
Instead of the getAttrByName line, you could also use the following: var strike = findObjs({ type: 'attribute', characterid: character.id, name: 'Strike' })[0]; if (!strike) { sendChat('SYSTEM', 'Error: Character ' + character.get('name') + ' does not have attribute "Strike"'); return; } strike = strike.get('current'); getAttrByName is simply shorter, and accounts for default values found on the character sheets coming up on Wednesday. Of course, Wednesday isn't very far away, so it's easy to wait. =) As a Mentor, you can also test the script on the dev server, which already has access to getAttrByName.
1401320958

Edited 1401320976
Good Afternoon, I'm currently trying to get the Script to work & running into problems that i'm sure are user error. I've created a character sheet (Basically a heavy modified rolemaster sheet) and listed the attributes as your script instructs However i'm getting the following errors when I try to use the script. <a href="http://s9.postimg.org/s3jqngkdr/Untitled.png" rel="nofollow">http://s9.postimg.org/s3jqngkdr/Untitled.png</a> (Bigger picture) Are you able to tell what i'm doing wrong w/ that screen shot? I'm logged in as the GM & try to use a player's token to attack that bandit. Thanks, William
*Update* I've ensured the tokens were linked to their character sheet. Now when I do the script, I select the bandit and place in a 0 for modifiers & nothing is parsed or rolled.
*Update* Success! after saving the scripts in the API setting and "Restarting the sandbox" I have successfully ran the script!