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

Ammo script

Hi there, I'm trying to set up the Ammo script in my custom game. I have no problem to produce a macro that will affect the ammo of one weapon. My problem is that in my custom setup, the ammo is randomly consumed. For exemple, a plasma gun has a ''ammo consumption'' of 1D6. If the player roll a ''1 or less'' in this round, it means he depleted his cartridge. In my custom character sheet, I've created a section describing the number of cartridge for each weapon the player has. I can than create a character sheet button supporting a Roll query asking for the ammo consumption :  ?{Ammo consumption? 1d3|1d4|1d6|1d8|1d10 but after this, I'm stuck. How do I create the rest? I want something like (if roll <=1, then !ammo (ammo script lower number of cartridge from the associated weapon by one) (if roll >1, then some text says *everything is fine*) Thanks a lot for your help!
1571878923
GiGs
Pro
Sheet Author
API Scripter
This might need a custom script. You cant do conditional effects in macros, if statements aren't possible. Though if the ammo cartridges are a simple number (1, 2, 3, etc) you can buid your query to return either 0 or 1, and use !ammo to reduce the number by that amount. You ammo consumption query is lacking a couple of characters: ?{Ammo consumption?|1 d3|1d4|1d6|1d8|1d10} If you want it to be a roll, you should wrap it in inline brackets too [[?{Ammo consumption?|1 d3|1d4|1d6|1d8|1d10}]] To make this a number of 0 or 1 when 1 is rolled, you can do [[?{Ammo consumption?|1 d3|1d4|1d6|1d8|1d10}<1 ]] I dont use the ammo script, so not sure what syntax for that command you need, but the above expression shouldgive you a 1 when rolling 1 or less, and a 0 otherwise.
Great idea. Works well! Now to implement the ammo script with repeating listing. I'll try to figure out something which will bypass the need to use weapon_$0_ammo need. 
1571927968
The Aaron
Roll20 Production Team
API Scripter
You can use the Row ID, but that's probably going to require a Sheet Worker to retrieve it abs store it. 
1571932036

Edited 1571949309
The Aaron said: You can use the Row ID, but that's probably going to require a Sheet Worker to retrieve it abs store it.  I'm a kind of a beginner into this. I've read the  section  describing this how will this work is I add new weapon? The RowID will seek the new weapon each time? Thanks, Guillaume Edit : I've searched up a bit and this manipulation is beyond what I'm currently understanding with html.
1571952305
GiGs
Pro
Sheet Author
API Scripter
The simplest approach is to put a button in the repeating section, to run the ammo check and script call. Then you dont need to worry about row id (remember, attribute references within the same row of a repeating section dont need to use the repeating_weapons_rowID part).
1571957069
The Aaron
Roll20 Production Team
API Scripter
If it's running a script call, you'll need to pass the RowID information to the API as it executes outside the context of the character, much less the row. 
GiGs said: The simplest approach is to put a button in the repeating section, to run the ammo check and script call. Then you dont need to worry about row id (remember, attribute references within the same row of a repeating section dont need to use the repeating_weapons_rowID part). Something like this? <h2>Arme de tir</h2> <fieldset class="repeating_weapons"> <select name="attr_weaponname" > (all the weapon option goes there, saved some space) </select> <button type='roll' name='roll_wound_level' value='&{template:default} {{name=@{character_name} tir avec @{weaponname} }} {{Niveau de la blessure =[[ @{INJ} + ?{Marge de succès?|0} - @{target|combined_personal_defense} ]] }}'></button><span class='dee'></span> </select> <br> <h5>INJ :</h5><input name="attr_INJ" value="-" readonly /><br> <h5> Recharge :</h5> <input name="attr_Recharge" value="-" readonly /> <br> <h5> Chargeur :</h5> <input name="attr_Chargeur" value="-" readonly /> </select> <input type="number" name="attr_resilience_bonus" value="0"> <button type='roll' name='roll_recharge' value='@{Chargeur}-[[-1*?{Recharge?|1d3|1d4|1d6|1d8|1d10}<1]]'></button><span class='dee'></span> </select> this result display the number of cartridge minus the roll but doesn't affect the value though. Guillaume
1572044099
GiGs
Pro
Sheet Author
API Scripter
As Aaron points out, you'll need a sheet worker to grab the row id if you want to use it with the ammo script. What is the syntax for ammo? What would your ammo command look like? Share that and we can tweak your code to make it work. 
1572054797

Edited 1572054923
The command to use the !ammo script would look like this: <button type='roll' name='roll_recharge' value='!ammo @{selected|token_id} repeating_weapons_$0_Chargeur [[-1*?{Recharge?|1d3|1d4|1d6|1d8|1d10}<1]]'></button><span class='dee'></span> Edit: Made an error in the syntax.
1572059977
GiGs
Pro
Sheet Author
API Scripter
I would suggest adding a hidden input next to the Charger input, like <input type="hidden" name="attr_chargerfull" value="" > Then make your button value !ammo @{character_id} @{chargerfull} [[-1*?{Recharge?|1d3|1d4|1d6|1d8|1d10}<1]] This is under the assumption that ammo accepts character_ids. I had a quick look at the ammo script and it looks like it does. Then add the following repeating section on("change:repeating_weapons:chargeur", function(eventInfo) {             setAttrs({         repeating_weapon_chargerfull: eventInfo.sourceAttribute     }); }); For any existing rows, you'll need to change the weapon type to one with a different Chargeur value to ensure the hidden attribute gets populated. For any rows you create after this change it will work automatically.
1572102859

Edited 1572104089
I've tried to change the html like you said : <h2>Arme de tir</h2> <fieldset class="repeating_weapons"> <select name="attr_weaponname" > <option value="aucune" selected>(Choisir)</option> <option value="bolter" selected>Bolter</option> <option value="bolter_lourd " selected>Bolter Lourd </option> <option value="canon_grav" selected>Canon Grav</option> <option value="canon_laser" selected>Canon Laser</option> <option value="canon_plasma" selected>Canon Plasma</option> <option value="carabine_laser" selected>Carabine Laser</option> <option value="fusil_pompe" selected>Fusil à pompe</option> <option value="fusil_pompe_automatique" selected>Fusil à pompe automatique</option> <option value="fusil_grav" selected>Fusil Grav</option> <option value="fusil_melta" selected>Fusil Melta</option> <option value="fusil_plasma" selected>Fusil Plasma</option> <option value="grenade_fragmentation" selected>Grenade à fragmentation</option> <option value="grenade_flash" selected>Grenade Flash</option> <option value="grenade_melta" selected>Grenade Melta</option> <option value="Lance_flammes" selected>Lance-flammes</option> <option value="lance_flammes_lourd" selected>Lance-flammes lourd</option> <option value="lance_missile" selected>Lance-missile</option> <option value="multi_melta" selected>Multi-Melta</option> <option value="pistolet_bolter" selected>Pistolet Bolter</option> <option value="pistolet_grav" selected>Pistolet Grav</option> <option value="pistolet_laser" selected>Pistolet Laser</option> <option value="pistolet_melta" selected>Pistolet Melta</option> <option value="pistolet_plasma" selected>Pistolet Plasma</option> <option value="pistolet_stubber" selected>Pistolet Stubber</option> <option value="sniper_laser" selected>Sniper Laser</option> <option value="stubber" selected>Stubber</option> <option value="stubber_lourd" selected>Stubber Lourd</option> <button type='roll' name='roll_wound_level' value='&{template:default} {{name=@{character_name} tir avec @{weaponname} }} {{Niveau de la blessure =[[ @{INJ} + ?{Marge de succès?|0} - @{target|combined_personal_defense} ]] }}'></button><span class='dee'></span> </select> <h5>INJ:</h5> <input name="attr_INJ" value="-" readonly /> <h5>Recharge:</h5> <input name="attr_Recharge" value="-" readonly /> <h5>Chargeur:</h5> <input type="hidden" name="attr_chargeurfull" value="" /> <button type='roll' name='roll_recharge' value='!ammo @{character_id} @{chargeurfull} [[-1*?{Recharge?|1d3|1d4|1d6|1d8|1d10}<1]]'></button><span class='dee'></span> </fieldset> <script type="text/worker"> const weapons = { aucune: {repeating_weapons_INJ: "", repeating_weapons_Recharge: "", repeating_weapons_Chargeur: ""}, bolter: {repeating_weapons_INJ: 3, repeating_weapons_Recharge: "1D6", repeating_weapons_Chargeur: 4}, bolter_lourd : {repeating_weapons_INJ: 4, repeating_weapons_Recharge: "1D6", repeating_weapons_Chargeur: 3}, canon_grav: {repeating_weapons_INJ: 2, repeating_weapons_Recharge: "1D3", repeating_weapons_Chargeur: 2}, canon_laser: {repeating_weapons_INJ: 9, repeating_weapons_Recharge: "1D3", repeating_weapons_Chargeur: 2}, canon_plasma: {repeating_weapons_INJ: 6, repeating_weapons_Recharge: "1D3", repeating_weapons_Chargeur: 3}, carabine_laser: {repeating_weapons_INJ: 1, repeating_weapons_Recharge: "1D10", repeating_weapons_Chargeur: 5}, fusil_pompe: {repeating_weapons_INJ: 1, repeating_weapons_Recharge: "1D6", repeating_weapons_Chargeur: 5}, fusil_pompe_automatique: {repeating_weapons_INJ: 2, repeating_weapons_Recharge: "1D3", repeating_weapons_Chargeur: 4}, fusil_grav: {repeating_weapons_INJ: 1, repeating_weapons_Recharge: "1D4", repeating_weapons_Chargeur: 3}, fusil_melta: {repeating_weapons_INJ: 6, repeating_weapons_Recharge: "1D4", repeating_weapons_Chargeur: 3}, fusil_plasma: {repeating_weapons_INJ: 5, repeating_weapons_Recharge: "1D6", repeating_weapons_Chargeur: 4}, grenade_fragmentation: {repeating_weapons_INJ: 2, repeating_weapons_Recharge: "N/A", repeating_weapons_Chargeur: 1}, grenade_flash: {repeating_weapons_INJ: 0, repeating_weapons_Recharge: "N/A", repeating_weapons_Chargeur: 3}, grenade_melta: {repeating_weapons_INJ: 5, repeating_weapons_Recharge: "N/A", repeating_weapons_Chargeur: 1}, Lance_flammes: {repeating_weapons_INJ: 1, repeating_weapons_Recharge: "1D3", repeating_weapons_Chargeur: 3}, lance_flammes_lourd: {repeating_weapons_INJ: 2, repeating_weapons_Recharge: "1D4", repeating_weapons_Chargeur: 2}, lance_missile: {repeating_weapons_INJ: 8, repeating_weapons_Recharge: "N/A", repeating_weapons_Chargeur: 5}, multi_melta: {repeating_weapons_INJ: 10, repeating_weapons_Recharge: "1D4", repeating_weapons_Chargeur: 3}, pistolet_bolter: {repeating_weapons_INJ: 2, repeating_weapons_Recharge: "1D8", repeating_weapons_Chargeur: 5}, pistolet_grav: {repeating_weapons_INJ: 0, repeating_weapons_Recharge: "1D6", repeating_weapons_Chargeur: 4}, pistolet_laser: {repeating_weapons_INJ: 1, repeating_weapons_Recharge: "1D10", repeating_weapons_Chargeur: 5}, pistolet_melta: {repeating_weapons_INJ: 4, repeating_weapons_Recharge: "1D3", repeating_weapons_Chargeur: 4}, pistolet_plasma: {repeating_weapons_INJ: 4, repeating_weapons_Recharge: "1D6", repeating_weapons_Chargeur: 4}, pistolet_stubber: {repeating_weapons_INJ: 0, repeating_weapons_Recharge: "1D10", repeating_weapons_Chargeur: 5}, sniper_laser: {repeating_weapons_INJ: 3, repeating_weapons_Recharge: "1D4", repeating_weapons_Chargeur: 3}, stubber: {repeating_weapons_INJ: 1, repeating_weapons_Recharge: "1D8", repeating_weapons_Chargeur: 4}, stubber_lourd: {repeating_weapons_INJ: 2, repeating_weapons_Recharge: "1D8", repeating_weapons_Chargeur: 3}, }; on("change:repeating_weapons:weaponname sheet:opened", function () { getAttrs(["repeating_weapons_weaponname"], function (values) { const output = weapons[values.repeating_weapons_weaponname] || weapons['Aucune']; setAttrs(output); }); }); on("change:repeating_weapons:chargeur", function(eventInfo) { setAttrs({ repeating_weapons_chargeurfull: eventInfo.sourceAttribute }); }); I've also tried to change the information in  canon_grav: {repeating_weapons_INJ: 2, repeating_weapons_Recharge: "1D3", repeating_weapons_Chargeur: 2}, to canon_grav: {repeating_weapons_INJ: 2, repeating_weapons_Recharge: "1D3", repeating_weapons_chargeurfull: 2}, but it didn't work. I know that the input is read though cause the chat windows give me this :  (From Ammo): Attribute [2] was not found. Please verify that you have the right name.
1572124063
GiGs
Pro
Sheet Author
API Scripter
Change this <h5>Chargeur:</h5> <input type="hidden" name="attr_chargeurfull" value="" /> back to what it was before. The hidden input I suggested is an extra one, that goes beside that.
Everything work.  Thanks a lot Gigs and The Aaron!
1572372958
The Aaron
Roll20 Production Team
API Scripter
Mostly GiGs, but you're welcome!
I've been doing some research but I can't find anything. Is there a way to put the ammo script in a power cards? I'm trying to have a one-click button that manage the ''roll to hit'' then ''dodge'' if hit, then ''damage'' if hit was successful and finally ''ammo'' to see if the player used a magazine or not.  Right now, everything works except the ammo part. I've tried this (and many other iteration) without success:   <button type="roll" name="roll_jet_total" value=" !power {{ --hroll||[[ [$MS] [NH] 4df + @{rolelvlwpn} + ?{Modificateur pour toucher la cible?|0|-3|-2|-1|+1|+2|+3} - ?{Niveau de difficulté pour atteindre la cible?|0}]] --?? $MS.total < 0 ?? Marge d'échec :|[^MS], Tir raté. --?? $MS.total >= 0 ?? Marge de succès :|[^MS], Tir réussi --?? $MS.total >= 0 ?? Test d’esquive :|[[ [$Esq] [NH] 4df + @{hurtlvl} + @{agility} + ?{Modificateur pour le test d'esquive?|0|-3|-2|-1|+1|+2|+3}]] --?? $Esq.total > $MS.total ?? Résultat| La cible anticipe tes tirs. --?? $Esq.total <= $MS.total ?? Résultat| La cible est touchée. --?? $Esq.total <= $MS.total ?? Niveau de blessure:|[[ [$DMG] 0d0 + @{INJ} - @{target|combined_personal_defense} ]] --?? $Esq.total <= $MS.total ?? alterbar1|_target|@{target||token_id} _bar|3 _amount|-[^DMG]/2+[^MS]/2 _show|GM --ammo|!ammo @{character_id} @{chargeurfull} [[-1*{@{Recharge}+?{Tir automatique ?|Non,0|Oui,-2}}<1}]] }} "></button> When rolled alone and note in a powercard, it work perfectly :  <button type="roll" name="roll_consochargeur" value="!ammo @{character_id} @{chargeurfull} [[-1*{@{Recharge}+?{Tir automatique ?|Non,0|Oui,-2}}<1}]]"></button> Thanks a lot, Guillaume
1573206786
GiGs
Pro
Sheet Author
API Scripter
Power cards is its own beast, it's a good idea to find its active thread and ask for help there.