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

Custom API for custom weapons

Hi there, im new to roll20, with only about 200 hours put in and im fairly new to coding in JS. However, in one of my campaigns I crafted a longbow for our ranger to use. The longbow is a +1 longbow, in addition, it adds 1d4 earth damage, and the intrinsic perk is its ability to ricochet the arrows off any surface. the player could make as many ricochets as he could intelligence saves that would increment by 2 with each successful save. The only damage applied to the enemies during this attack phase, is the 1d4 earth damage. My question is... what is a good place to start to create such an API that would first make the normal attack and damage rolls, then roll INT save, ask if it was a success, and if so continue rolling, damaging, and rolling again until a failed save? 

Here is the exact description from my campaign 
Longbow +1 When an arrow is fired from this bow, it becomes sheathed in an earthen casing allowing it to ricochet off any object's surface in the area. The arrow deals an additional 1d4 earth damage. The arrow ricochets as many times as the user can make an INT saving throw starting at a DC14 adding 2 to the DC per ricochet. Only the initial target takes the 1d8 arrow damage. Any successive ricochets only deal 1d4 earth damage.

If someone could help me that would be great, thanks!


June 23 (5 years ago)

Edited June 23 (5 years ago)
David M.
Pro
API Scripter

I don't do js, but here is a very hacky, inelegant, brute force, spamming-your-chat-feed way to do it using inline rolls and macros. I don't know what system/sheet you are using so I just hardcoded attack and save modifiers (as +1, and +2, respectively) for the example.

Basically, just spamming saving throws and potential d4 damage a bunch of times. The [[{1d20+2}>14]] line returns a 0 for failure and 1 for success. You would only count the ricochets until the first failure (DC16 in the example). I just put up to DC 22 in the example, but you could add more until statistically impossible.

&{template:default} {{name=Earthen Longbow Attack}} {{Initial Attack Roll=[[1d20+1]] vs AC}} {{Initial Target Damage=[[1d8+1]] Piercing}} {{Ricochet 1? (DC14)=[[{1d20+2}>14]] successes
[[d4]] damage}} {{Ricochet 2? (DC16)=[[{1d20+2}>16]] successes
[[d4]] damage}} {{Ricochet 3? (DC18)=[[{1d20+2}>18]] successes
[[d4]] damage}} {{Ricochet 4? (DC20)=[[{1d20+2}>20]] successes
[[d4]] damage}} {{Ricochet 5? (DC22)=[[{1d20+2}>22]] successes
[[d4]] damage}} 

Example output

You could make it take up less space if you just multiplied the d4's by the 0 or 1 returned from the saving throw comparison, but you would lose the ability to mouse over the result to see what number you actually rolled. Many people don't like that, though. In this case, you would just stop at the first 0 damage ricochet.

&{template:default} {{name=Earthen Longbow Attack}} {{Initial Attack Roll=[[1d20+1]]}} {{Initial Target Damage=[[1d8+1]]}} {{Ricochet 1 Damage (DC 14)=[[[[{d20+2}>14]]*1d4]] }} {{Ricochet 2 Damage (DC 16)=[[[[{d20+2}>16]]*1d4]]}} {{Ricochet 3 Damage (DC 18)=[[[[{d20+2}>18]]*1d4]]}} {{Ricochet 4 Damage (DC 20)=[[[[{d20+2}>20]]*1d4]]}} {{Ricochet 5 Damage (DC 22)=[[[[{d20+2}>22]]*1d4]]}}

API script seems like a much better solution, but it was just a fun thought experiment :)


David, this is excellent, im going to try this, and ill let you know how it turns out. Thanks for the effort put into this... if it changes the variable names at all, I am using D&D 5e

June 24 (5 years ago)

Edited June 24 (5 years ago)
David M.
Pro
API Scripter

Ok, 5E so in that case it might be better to just tack just the Ricochet parts at the end of a standard attack template macro so it can take things like Always Roll Advantage, Auto Roll Damage and Crits, etc into account. If you're not familiar with that template, add the +1 Longbow to the character sheet and roll an attack directly from the sheet. Then click in the chat window (where you would normally type) and press the UP arrow. This will bring up the code sent by the character sheet that can be copied into a macro. 

For the 5e sheet, you can replace any hardcoded modifiers with things like:

@{Charname|dexterity_mod} 

and

@{Charname|intelligence_save_bonus}

so that it still works when the characters level or change stats. 

Actually, now that I think about it, the ricochet parts could go into the attack description part of the attack template. Maybe the macro below is be a better option. You would just need to replace all instances of the character name (might want to use a text editor find/replace). Oh, and there is a sneak attack included so you can remove that part if it doesn't apply. 

@{Charname|wtype}&{template:atkdmg} {{mod=+6}} {{rname=Earthen Longbow +1}} {{r1=[[@{Charname|d20}cs>20 + @{Charname|dexterity_mod}[DEX] + @{Charname|pb}[PROF] + 1[Magic]]]}} @{Charname|rtype}cs>20 + @{Charname|dexterity_mod}[DEX] + @{Charname|pb}[PROF]]]}} {{attack=1}} {{range=150/600}} {{damage=1}} {{dmg1flag=1}} {{dmg1=[[1d8 + @{Charname|dexterity_mod}[DEX] + 1[Magic]]]}} {{dmg1type=Piercing }} 0 {{dmg2=[[0]]}} {{dmg2type=}} {{crit1=[[1d8[CRIT]]]}} {{crit2=[[0[CRIT]]]}} 0 {{desc=Ricochet 1? (DC14)=[[{1d20+@{Charname|intelligence_save_bonus}}>14]] successes
[[d4]] damage
Ricochet 2? (DC16)=[[{1d20+@{Charname|intelligence_save_bonus}}>16]] successes
[[d4]] damage 
Ricochet 3? (DC18)=[[{1d20+@{Charname|intelligence_save_bonus}}>18]] successes
[[d4]] damage 
Ricochet 4? (DC20)=[[{1d20+@{Charname|intelligence_save_bonus}}>20]] successes
[[d4]] damage 
Ricochet 5? (DC22)=[[{1d20+@{Charname|intelligence_save_bonus}}>22]] successes
[[d4]] damage}} {{globalattack=@{Charname|global_attack_mod}}} {{globaldamage=[[1d6[Sneak Attack]]]}} {{globaldamagecrit=[[1d6[Sneak Attack]]]}} {{globaldamagetype=@{Charname|global_damage_mod_type}}} ammo= @{Charname|charname_output}
Example output on a crit, with sneak attack (the 1+6 damage part), with "Always Roll Advantage" and "Auto Roll Damage & Crits" checked in the character sheet.


Anyway, this should at least be enough to get you started. A custom script would likely result in a more elegant solution, but since my only tool is a hammer... :) 

Good luck!


Dude youre the man! My campaign is tonight so this helps a ton... I am thinking of upgrading my hammer to an arsenal of tools ;)