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

Equipment and character sheet

Hi everyone, I've checked multiple Github files and looked through the forums and can't find the information. I'm building a custom sheet and i'm wondering if i can create a listing so players can choose their weapon(s). By doing so, the weapons stats would be displayed in the character sheet and I could refer to it in macro. Please note that player could potentially have more than one ranged/close combat weapon. I might just use different attributes for this like attr_AP1(armor penetration) and use a macro called #RangedWeapon1. Any idea if this is something possible?
1571762672

Edited 1571762716
Andreas J.
Forum Champion
Sheet Author
Translator
Yes, that is possible with sheetworkers . So if you have a dropdown menu that list the names of weapons, you can create sheetworkers that fill out the corresponding stats when you select a weapon. the code/logic for the sheet worker would look something like this: <script type="text/worker"> on("change:weaponname", function() { getAttrs(["weaponname","weaponatk","weapondmg"], function(values) { if(values.weaponname == "sword"){ var update = {}; update.weaponatk = "3";                 update.weapondmg = "1d8";                 setAttrs(update); } else if(values.weaponname == "dagger"){ var update = {}; update.weaponatk = "2";                 update.weapondmg = "1d4"; setAttrs(update); } }); }); </script>
1571769417

Edited 1571773818
GiGs
Pro
Sheet Author
API Scripter
Andreas' approach would work, but a much more efficient way to do it is like this: const weapons = {     none: {weaponatk: 0, weapondmg: ""},     sword: {weaponatk: 0, weapondmg: "1d4"},     axe: {weaponatk: -1, weapondmg: "1d6"}, }; on("change:weaponname sheet:opened", function () {     getAttrs(["weaponname"], function (values) {         const output = weapons[values.weaponname] || weapons['none'];         setAttrs(output);     }); }); So the first step is to set up the weapons object at the start. Each line should begine with the name of the weapon variable from your select. So in your character sheet html, you'd have something like this where players select their weapons: <select name="attr_weaponname" >     <option value="none" selected>(Choose One)</option>     <option value="sword">Sword</option>     <option value="axe">Axe</option> </select> For your data object, you need to start each row with the weapon name exactly as it is in the value (same case), which would look like this: const weapons = {     none: {},     sword: {},     axe: {}, } With this framework setup, you enter the stats of each weapon between the curly braces. You must  use the attribute names on your character sheet for each weapon stat. So if you have <input name="attr_wpnatkbonus" value="0" /> then you'd enter wpnatkbonus like so, with its actual values const weapons = {     none: {wpnatkbonus: 0, },     sword: {wpnatkbonus: 1, },     axe: {wpnatkbonus: -1, }, }; Enter the attribute names for each weapon stat, then a colon, then the value. If the value is text, but it in quotes, if its a number, don't.  Note: if you attribute names have "-" in them, you'll have to put the name in quotes, like so: const weapons = {     none: {"wpn-atk-bonus": 0, }, }; You dont need to do this with underscores, so they make a better separator for multi-word names. Separate multiple stats with commas (refer back to the script posted right at the top. You'll notice I included a none entry. It's handy to have an entry and stats for "no weapon selected", even if you are just entering "0", "-", or "" as values. With this setup, the sheet worker is really simple. on("change:weaponname sheet:opened", function () {     getAttrs(["weaponname"], function (values) {         const output = weapons[values.weaponname] || weapons['none'];         setAttrs(output);     }); }); this part just grabs the weaponname, and the output line grabs all the relevant value from the data object you set up: output = weapons[values.weaponname] The bit after that sets it to a 'none' entry if the weapon name isnt recognised. It's handy to be able to handle errors and typos.  Hope this helps!
1571769652

Edited 1571775562
GiGs
Pro
Sheet Author
API Scripter
Guillaume B. said: I'm building a custom sheet and i'm wondering if i can create a listing so players can choose their weapon(s). By doing so, the weapons stats would be displayed in the character sheet and I could refer to it in macro. Please note that player could potentially have more than one ranged/close combat weapon. I might just use different attributes for this like attr_AP1(armor penetration) and use a macro called #RangedWeapon1. You might want to look into repeating sections in the wiki, for the ability to have multiple weapons at once. To use my code with repeating sections, it would look like this: on("change:repeating_weapons:weaponname sheet:opened", function () {     getAttrs(["repeating_weapons_weaponname"], function (values) {         const output = weapons[values.repeating_weapons_weaponname] || weapons['none'];         setAttrs(output);     }); });
1571774695
Andreas J.
Forum Champion
Sheet Author
Translator
Nice :D Almost left a disclaimer at the bottom, mentioning that you'd likely show up and show how it really done. Good to know that my example would also work, I've never created anything more than simple sheetworkers, and 90% I've later refactored them to your suggestions. In a sense, we could say we stand on the shoulder of giants GiGs. :'D
1571776400
GiGs
Pro
Sheet Author
API Scripter
Thanks :) If you were going to do it the way you suggested Andreas, here are some tips: you want to avoid duplication as much as possible, so the var update and setAttrs should be moved out of the if like so: on("change:weaponname", function() { getAttrs(["weaponname"], function(values) {        var update = {}; if(values.weaponname == "sword"){ update.weaponatk = "3";                 update.weapondmg = "1d8"; } else if(values.weaponname == "dagger"){ update.weaponatk = "2";                 update.weapondmg = "1d4"; }         setAttrs(update); }); }); And notice the change on the getAttrs line. It was this: getAttrs(["weaponname","weaponatk","weapondmg"], function(values) { You only need to get the weaponname. You never read the other two from the sheet, so you dont need them in the getAttrs line.
1571795047

Edited 1571795775
Thank a lot for the replies.  I've set up all information and the character sheet seems to be working regarding the weapon choice. I don't know if your script was supposed to display the weapon attribute but it doesn't seem to do so atm : Relevant code : <h2>Arme de tir</h2> <fieldset class="repeating_weaponname"> <select name="attr_weaponname" > <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> <option value="Aucune" selected>Aucune</option> </select> </fieldset> <script type="text/worker"> const weapons = { Aucune: {INJ: "-", Recharge: "-", Requisition: "-"}, Bolter: {INJ: 3, Recharge: "1D6", Chargeur: 4}, Bolter Lourd : {INJ: 4, Recharge: "1D6", Chargeur: 3}, Canon Grav: {INJ: 2, Recharge: "1D3", Chargeur: 2}, Canon Laser: {INJ: 9, Recharge: "1D3", Chargeur: 2}, Canon Plasma: {INJ: 6, Recharge: "1D3", Chargeur: 3}, Carabine Laser: {INJ: 1, Recharge: "1D10", Chargeur: 5}, Fusil à pompe: {INJ: 1, Recharge: "1D6", Chargeur: 5}, Fusil à pompe automatique: {INJ: 2, Recharge: "1D3", Chargeur: 4}, Fusil Grav: {INJ: 1, Recharge: "1D4", Chargeur: 3}, Fusil Melta: {INJ: 6, Recharge: "1D4", Chargeur: 3}, Fusil Plasma: {INJ: 5, Recharge: "1D6", Chargeur: 4}, Grenade à fragmentation: {INJ: 2, Recharge: "N/A", Chargeur: 1}, Grenade Flash: {INJ: 0, Recharge: "N/A", Chargeur: 3}, Grenade Melta: {INJ: 5, Recharge: "N/A", Chargeur: 1}, Lance-flammes: {INJ: 1, Recharge: "1D3", Chargeur: 3}, Lance-flammes lourd: {INJ: 2, Recharge: "1D4", Chargeur: 2}, Lance-missile: {INJ: 8, Recharge: "N/A", Chargeur: 5}, Multi-Melta: {INJ: 10, Recharge: "1D4", Chargeur: 3}, Pistolet Bolter: {INJ: 2, Recharge: "1D8", Chargeur: 5}, Pistolet Grav: {INJ: 0, Recharge: "1D6", Chargeur: 4}, Pistolet Laser: {INJ: 1, Recharge: "1D10", Chargeur: 5}, Pistolet Melta: {INJ: 4, Recharge: "1D3", Chargeur: 4}, Pistolet Plasma: {INJ: 4, Recharge: "1D6", Chargeur: 4}, Pistolet Stubber: {INJ: 0, Recharge: "1D10", Chargeur: 5}, Sniper Laser: {INJ: 3, Recharge: "1D4", Chargeur: 3}, Stubber: {INJ: 1, Recharge: "1D8", Chargeur: 4}, Stubber Lourd: {INJ: 2, Recharge: "1D8", 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); }); }); </script> EDIT : change the code to reflect the ''repeating weaponname'' change.
1571795747

Edited 1571795811
GiGs
Pro
Sheet Author
API Scripter
Have you added the inputs or spans to hold the information? something like <fieldset class="repeating_weapons">     <select name="attr_weaponname" >     <!-- values trimmed for space --> </select>     <input name="attr_INJ" value="-" readonly />     <input name="attr_Recharge" value="-" readonly />     <input name="attr_ Requisition " value="-" readonly /> </fieldset> Also, you should remove the world selected from all but the last of your select values. For instance,  <option value="Bolter" selected>Bolter</option> <option value="Bolter Lourd " selected>Bolter Lourd </option> should be <option value="Bolter" >Bolter</option> <option value="Bolter Lourd " >Bolter Lourd </option> selected  sets the one that is selected by default, which you want to be the Choisir option.
1571795910
GiGs
Pro
Sheet Author
API Scripter
You'll need to change repeating_weaponname back to repeating_weapons , or the sheet worker wont work.
GiGs said: Have you added the inputs or spans to hold the information? something like <fieldset class="repeating_weapons">     <select name="attr_weaponname" >     <!-- values trimmed for space </select>     <input name="attr_INJ" value="-" readonly />     <input name="attr_Recharge" value="-" readonly />     <input name="attr_ Requisition " value="-" readonly /> </fieldset> Also, you should remove the world selected from all but the last of your select values. For instance,  <option value="Bolter" selected>Bolter</option> <option value="Bolter Lourd " selected>Bolter Lourd </option> should be <option value="Bolter" >Bolter</option> <option value="Bolter Lourd " >Bolter Lourd </option> selected  sets the one that is selected by default, which you want to be the Choisir option. Mmm, tried the switch and I only get dash sign in the output. <h2>Arme de tir</h2> <fieldset class="repeating_weapons"> <select name="attr_weaponname" >  <!-- values trimmed for space </select> <input name="attr_INJ" value="-" readonly /> <input name="attr_Recharge" value="-" readonly /> <input name="attr_Chargeur" value="-" readonly /> </fieldset> <script type="text/worker"> const weapons = {  <!-- values trimmed for space }; 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); }); }); </script>
1571797003

Edited 1571797054
GiGs
Pro
Sheet Author
API Scripter
You need to put the weapons stuff back in - i trimmed it for space. Change this <script type="text/worker"> const weapons = {  <!-- values trimmed for space }; back to this <script type="text/worker"> const weapons = { Aucune: {INJ: "-", Recharge: "-", Requisition: "-"}, Bolter: {INJ: 3, Recharge: "1D6", Chargeur: 4}, "Bolter Lourd": {INJ: 4, Recharge: "1D6", Chargeur: 3}, Canon Grav: {INJ: 2, Recharge: "1D3", Chargeur: 2}, Canon Laser: {INJ: 9, Recharge: "1D3", Chargeur: 2}, Canon Plasma: {INJ: 6, Recharge: "1D3", Chargeur: 3}, Carabine Laser: {INJ: 1, Recharge: "1D10", Chargeur: 5}, Fusil à pompe: {INJ: 1, Recharge: "1D6", Chargeur: 5}, Fusil à pompe automatique: {INJ: 2, Recharge: "1D3", Chargeur: 4}, Fusil Grav: {INJ: 1, Recharge: "1D4", Chargeur: 3}, Fusil Melta: {INJ: 6, Recharge: "1D4", Chargeur: 3}, Fusil Plasma: {INJ: 5, Recharge: "1D6", Chargeur: 4}, Grenade à fragmentation: {INJ: 2, Recharge: "N/A", Chargeur: 1}, Grenade Flash: {INJ: 0, Recharge: "N/A", Chargeur: 3}, Grenade Melta: {INJ: 5, Recharge: "N/A", Chargeur: 1}, Lance-flammes: {INJ: 1, Recharge: "1D3", Chargeur: 3}, Lance-flammes lourd: {INJ: 2, Recharge: "1D4", Chargeur: 2}, Lance-missile: {INJ: 8, Recharge: "N/A", Chargeur: 5}, Multi-Melta: {INJ: 10, Recharge: "1D4", Chargeur: 3}, Pistolet Bolter: {INJ: 2, Recharge: "1D8", Chargeur: 5}, Pistolet Grav: {INJ: 0, Recharge: "1D6", Chargeur: 4}, Pistolet Laser: {INJ: 1, Recharge: "1D10", Chargeur: 5}, Pistolet Melta: {INJ: 4, Recharge: "1D3", Chargeur: 4}, Pistolet Plasma: {INJ: 4, Recharge: "1D6", Chargeur: 4}, Pistolet Stubber: {INJ: 0, Recharge: "1D10", Chargeur: 5}, Sniper Laser: {INJ: 3, Recharge: "1D4", Chargeur: 3}, Stubber: {INJ: 1, Recharge: "1D8", Chargeur: 4}, Stubber Lourd: {INJ: 2, Recharge: "1D8", Chargeur: 3}, }; Also look through the list above, and put quotes around every name isn't a single word, like I just did with " Bolter Lourd".
1571797556
GiGs
Pro
Sheet Author
API Scripter
In fact, I'd make a bigger change: let's look at your select. Here's the first few entries (with selected removed) <select name="attr_weaponname" > <option value="Bolter" >Bolter</option> <option value="Bolter Lourd " >Bolter Lourd </option> <option value="Canon Grav" >Canon Grav</option> The bit after the value should be a simple name, ideally a single world all in lower case. The user never sees that. The bit before /option is the bit the user sees. so you should change this to look like this <select name="attr_weaponname" > <option value="bolter" >Bolter</option> <option value="bolter_lourd " >Bolter Lourd </option> <option value="canon_grav" >Canon Grav</option> Notice - no spaces, or dashes, or any other characters except for english letters and an underscore. Some of your later names also have problematic characters. These         <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> should be         <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> Notice - all lower case letters, no special characters except for underscore. This simplifies the sheet worker. Your code would then be const weapons = { aucune: {INJ: "-", Recharge: "-", Requisition: "-"}, bolter: {INJ: 3, Recharge: "1D6", Chargeur: 4}, bolter_lourd: {INJ: 4, Recharge: "1D6", Chargeur: 3}, canon_grav: {INJ: 2, Recharge: "1D3", Chargeur: 2}, and so on. Match up the the names here with the value in your select exactly . same spelling, everything.
I've modified everything and still, no dice. I'm starting to think I've made error in previous sections. <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> </select> <input name="attr_INJ" value="-" readonly /> <input name="attr_Recharge" value="-" readonly /> <input name="attr_Chargeur" value="-" readonly /> </fieldset> <script type="text/worker"> const weapons = { aucune: {INJ: "", Recharge: "", Chargeur: ""}, bolter: {inj: 3, recharge: "1D6", chargeur: 4}, bolter_lourd : {inj: 4, recharge: "1D6", chargeur: 3}, canon_grav: {inj: 2, recharge: "1D3", chargeur: 2}, canon_laser: {inj: 9, recharge: "1D3", chargeur: 2}, canon_plasma: {inj: 6, recharge: "1D3", chargeur: 3}, carabine_laser: {inj: 1, recharge: "1D10", chargeur: 5}, fusil_pompe: {inj: 1, recharge: "1D6", chargeur: 5}, fusil_pompe_automatique: {inj: 2, recharge: "1D3", chargeur: 4}, fusil_grav: {inj: 1, recharge: "1D4", chargeur: 3}, fusil_melta: {inj: 6, recharge: "1D4", chargeur: 3}, fusil_plasma: {inj: 5, recharge: "1D6", chargeur: 4}, grenade_fragmentation: {inj: 2, recharge: "N/A", chargeur: 1}, grenade_flash: {inj: 0, recharge: "N/A", chargeur: 3}, grenade_melta: {inj: 5, recharge: "N/A", chargeur: 1}, Lance_flammes: {inj: 1, recharge: "1D3", chargeur: 3}, lance_flammes_lourd: {inj: 2, recharge: "1D4", chargeur: 2}, lance_missile: {inj: 8, recharge: "N/A", chargeur: 5}, multi_melta: {inj: 10, recharge: "1D4", chargeur: 3}, pistolet_bolter: {inj: 2, recharge: "1D8", chargeur: 5}, pistolet_grav: {inj: 0, recharge: "1D6", chargeur: 4}, pistolet_laser: {inj: 1, recharge: "1D10", chargeur: 5}, pistolet_melta: {inj: 4, recharge: "1D3", chargeur: 4}, pistolet_plasma: {inj: 4, recharge: "1D6", chargeur: 4}, pistolet_stubber: {inj: 0, recharge: "1D10", chargeur: 5}, sniper_laser: {inj: 3, recharge: "1D4", chargeur: 3}, stubber: {inj: 1, recharge: "1D8", chargeur: 4}, stubber_lourd: {inj: 2, recharge: "1D8", 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); }); }); </script>
1571799479

Edited 1571800220
GiGs
Pro
Sheet Author
API Scripter
Aha, no, this time the error was mine. My initial code was set up for normal attributes. I forgot to take into account this is a repeating section.  You have two options. First: Change this 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); }); }); to on("change:repeating_weapons:weaponname", function () { getAttrs(["repeating_weapons_weaponname"], function (values) { const fix_key = key => `repeating_weapons_${key}`; const weapon = weapons[values.repeating_weapons_weaponname] || weapons['Aucune']; const output = Object.keys(weapon) . reduce((result, key) => { result[fix_key(key)] = weapon[key]; return result; }, {}) setAttrs(output); }); }); Or change all the keys in the weapons object: const weapons = { aucune: {INJ: "", Recharge: "", Chargeur: ""}, bolter: {inj: 3, recharge: "1D6", chargeur: 4}, bolter_lourd : {inj: 4, recharge: "1D6", chargeur: 3}, canon_grav: {inj: 2, recharge: "1D3", chargeur: 2}, canon_laser: {inj: 9, recharge: "1D3", chargeur: 2}, canon_plasma: {inj: 6, recharge: "1D3", chargeur: 3}, carabine_laser: {inj: 1, recharge: "1D10", chargeur: 5}, fusil_pompe: {inj: 1, recharge: "1D6", chargeur: 5}, fusil_pompe_automatique: {inj: 2, recharge: "1D3", chargeur: 4}, fusil_grav: {inj: 1, recharge: "1D4", chargeur: 3}, fusil_melta: {inj: 6, recharge: "1D4", chargeur: 3}, fusil_plasma: {inj: 5, recharge: "1D6", chargeur: 4}, grenade_fragmentation: {inj: 2, recharge: "N/A", chargeur: 1}, grenade_flash: {inj: 0, recharge: "N/A", chargeur: 3}, grenade_melta: {inj: 5, recharge: "N/A", chargeur: 1}, Lance_flammes: {inj: 1, recharge: "1D3", chargeur: 3}, lance_flammes_lourd: {inj: 2, recharge: "1D4", chargeur: 2}, lance_missile: {inj: 8, recharge: "N/A", chargeur: 5}, multi_melta: {inj: 10, recharge: "1D4", chargeur: 3}, pistolet_bolter: {inj: 2, recharge: "1D8", chargeur: 5}, pistolet_grav: {inj: 0, recharge: "1D6", chargeur: 4}, pistolet_laser: {inj: 1, recharge: "1D10", chargeur: 5}, pistolet_melta: {inj: 4, recharge: "1D3", chargeur: 4}, pistolet_plasma: {inj: 4, recharge: "1D6", chargeur: 4}, pistolet_stubber: {inj: 0, recharge: "1D10", chargeur: 5}, sniper_laser: {inj: 3, recharge: "1D4", chargeur: 3}, stubber: {inj: 1, recharge: "1D8", chargeur: 4}, stubber_lourd: {inj: 2, recharge: "1D8", chargeur: 3}, }; each entry here would be like this: aucune: {repeating_weapons_INJ: "", repeating_weapons_Recharge: "", repeating_weapons_Chargeur: ""}, Just add repeating_weapons_ to the start of each weapons attributes in this data list (and only here - dont change the Inputs!). DONT DO BOTH! Pick which one you prefer. Sorry for giving you a bit of a runaround here :)
Everything works now. That's pretty awesome! Thanks a million! Now, I'm  wondering how I can refer to a specific INJ attribute. Let's say the character have 1 pistol and 1 rocket launcher, how can I force the macro to use one weapon INJ or the other? And could I alter the ''chargeur'' number with an ammo script? Thanks for letting me know. :)
1571805864
GiGs
Pro
Sheet Author
API Scripter
There are a few of ways, not all of them very straightforward. For all of them it's a good idea to add a button in the repeating section for making attacks. Once that's done, the simplest way is to drag the button for a specific weapon to the macro toolbar and it will always refer to that specific weapon. If you're willing to use scripts, a custom script could easily grab the details of a specific named weapon. Or my Universal Chat Menu script (or Scott's similar Menu maker script) will build a menu of all the weapons in the repeating section, and paste it into chat. It's a very handy way to access macros in a character sheet. Or, using basic macros, you can access a weapon by using the index format: @{repeating_weapons_$0_INJ} will give you the first weapon in your list, replacing $0 will $1 will give the second, $2 will give the third, and so on. A final method: You could include a checkbox in your repeating section, for active weapon. Whenever that's clicked it saves the row ID somewhere on the sheet, then the player has a single macro to make attacks, and it automatically uses the row for the currently selected weapon. So there's a few options, all take a little set up.
Ok. I've tried to create a button for the repeating section. But I can't figure out how to call the specific ''INJ'' stat. I've tried : </select> <button type='roll' name='roll_wound_level' value='&{template:default} {{name=@{character_name} tir avec @{weaponname} }} {{Niveau de la blessure =[[ @{weapons_INJ} + ?{Marge de succès?|0} - @{target|combined_personal_defense} ]] }}'></button><span class='dee'></span> </select>
1571856935

Edited 1571858649
GiGs
Pro
Sheet Author
API Scripter
If the button is inside the repeating section, you just use the attribute name with out the repeating section part, like so: value='&{template:default} {{name=@{character_name} tir avec @{weaponname} }} {{Niveau de la blessure =[[ @{INJ} + ?{Marge de succès?|0} - @{target|combined_personal_defense} ]] }} Edit: meant to say "without", not "with". corrected above
GiGs said: If the button is inside the repeating section, you just use the attribute name with the repeating section part, like so: value='&{template:default} {{name=@{character_name} tir avec @{weaponname} }} {{Niveau de la blessure =[[ @{INJ} + ?{Marge de succès?|0} - @{target|combined_personal_defense} ]] }} Perfect!  Now, I'll be trying to add the Ammo script to decrease the ''Chargeurs'' value each time someone roll a fumble on a specific ''Chargeur'' button I'll create. Thanks for all the informations. We truly stand on your shoulder to bring us higher. :)
To continue on the subject, I've now created a section for close combat weapons. I can't figure how to populate the Damage Factor (DF) box.  I've tried this code : <h2>Arme de tir</h2> <fieldset class="repeating_weapons"> <select name="attr_weaponname"> <option value="aucune"selected>(Choisir)</option> <option value="bolter">Bolter</option> <option value="bolter_lourd">Bolter Lourd </option> <option value="canon_grav">Canon Grav</option> <option value="canon_laser">Canon Laser</option> <option value="canon_plasma">Canon Plasma</option> <option value="carabine_laser">Carabine Laser</option> <option value="fusil_pompe">Fusil à pompe</option> <option value="fusil_pompe_automatique">Fusil à pompe automatique</option> <option value="fusil_grav">Fusil Grav</option> <option value="fusil_melta">Fusil Melta</option> <option value="fusil_plasma">Fusil Plasma</option> <option value="grenade_fragmentation">Grenade à fragmentation</option> <option value="grenade_flash">Grenade Flash</option> <option value="grenade_melta">Grenade Melta</option> <option value="Lance_flammes">Lance-flammes</option> <option value="lance_flammes_lourd">Lance-flammes lourd</option> <option value="lance_missile">Lance-missile</option> <option value="multi_melta">Multi-Melta</option> <option value="pistolet_bolter">Pistolet Bolter</option> <option value="pistolet_grav">Pistolet Grav</option> <option value="pistolet_laser">Pistolet Laser</option> <option value="pistolet_melta">Pistolet Melta</option> <option value="pistolet_plasma">Pistolet Plasma</option> <option value="pistolet_stubber">Pistolet Stubber</option> <option value="sniper_laser">Sniper Laser</option> <option value="stubber">Stubber</option> <option value="stubber_lourd">Stubber Lourd</option> </select> <button type="roll" name="roll_wound_level" value="&{template:default} {{name=@{character_name} tire avec @{weaponname} sur @{target|character_name} }} {{Niveau de la blessure =[[ @{INJ} + ?{Marge de succès?|0} - @{target|combined_personal_defense} ]] }}"></button><span class="dee"> <h5>INJ:</h5> <input name="attr_INJ" value="-" readonly /> <h5>Recharge:</h5> <input name="attr_Recharge" value="-" readonly /> <h5> Chargeur :</h5> <input name="attr_Chargeur" value="-" readonly /> <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> </fieldset> <h2>Arme de corps à corps</h2> <fieldset class="repeating_weapons_cac"> <select name="attr_weaponname_cac"> <option value="arme_energetique_deux_mains" >Arme énergétique à deux mains</option> <option value="arme_improvisee" selected>Arme improvisée</option> <option value="eviscerateur" >Éviscérateur</option> <option value="gantelet_energetique" >Gantelet énergétique</option> <option value="hache" >Hache</option> <option value="hache_deux_main" >Hache à deux mains</option> <option value="hache_energetique" >Hache énergétique</option> <option value="hache_tronconneuse" >Hache tronnçonneuse</option> <option value="lame" >Lame</option> <option value="lame_deux_mains" >Lame à deux mains</option> <option value="lame_energetique" >Lame énergétique</option> <option value="lame_tronconneuse" >Lame tronçonneuse</option> <option value="lance" >Lance</option> <option value="lance_energetique" >Lance énergtique</option> <option value="mace" >Mace</option> <option value="mace_energetique" >Mace Énergétique</option> <option value="marteau_tonnerre" >Marteau tonnerre à deux mains</option> </select> <button type="roll" name="roll_wound_level_cac" value="&{template:default} {{name=@{character_name} attaque avec @{weaponname_cac} sur @{target|character_name} }} {{Niveau de la blessure =[[ @{target|body} + @{target|mass_scale} + @{DF} + ?{Marge de succès?|0} - @{target|combined_personal_defense} ]] }}"></button><span class="dee"> <h5>INJ:</h5> <input name="attr_DF" value="-" readonly /> </fieldset> </div> <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}, }; const weapons_cac = { arme_energetique_deux_mains: {repeating_weapons_cac_DF: 7}, arme_improvisee: {repeating_weapons_cac_DF: -1}, eviscerateur: {repeating_weapons_cac_DF: 8}, gantelet_energetique: {repeating_weapons_cac_DF: 9}, hache: {repeating_weapons_cac_DF: 1}, hache_deux_main: {repeating_weapons_cac_DF: 3}, hache_energetique: {repeating_weapons_cac_DF: 5}, hache_tronconneuse: {repeating_weapons_cac_DF: 4}, lame: {repeating_weapons_cac_DF: 1}, lame_deux_mains: {repeating_weapons_cac_DF: 3}, lame_energetique: {repeating_weapons_cac_DF: 5}, lame_tronconneuse: {repeating_weapons_cac_DF: 4}, lance: {repeating_weapons_cac_DF: 1}, lance_energetique: {repeating_weapons_cac_DF: 5}, mace: {repeating_weapons_cac_DF: 1}, mace_energetique: {repeating_weapons_cac_DF: 5}, marteau_tonnerre: {repeating_weapons_cac_DF: 9}, }; 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_cac:weaponname sheet:opened", function () { getAttrs(["repeating_weapons_cac_weaponname"], function (values) { const output = weapons_cac[values.repeating_weapons_cac_weaponname] || weapons_cac['arme_improvisee']; setAttrs(output); }); }); on("change:repeating_weapons:Chargeur", function(eventInfo) { setAttrs({ repeating_weapons_chargeurfull: eventInfo.sourceAttribute }); }); </script> Now both the shooting & close combat weapon doesn't work. Can someone please help me with this? Hopefully, I wasn't to far away from a solution.
1572217311
GiGs
Pro
Sheet Author
API Scripter
You should only post the parts relevant to the question, only the weapons_cac section and sheet workers should have been posted here. You have two issues. The first is subtle, and I dont know if its documented. You cant use a second _ in a repeating_weapons section name (at least, that's my recollection). So change all instances of  repeating_weapon_cac  to  repeating_weaponcac In your select you define the name like so attr_weaponname_cac In your sheet worker you just use weaponname, and leave of _cac. This: on("change:repeating_weapons_cac:weaponname sheet:opened", function () { getAttrs(["repeating_weapons_cac_weaponname"], function (values) { should be (taking into account the first part above) on("change:repeating_weaponscac:weaponname_cac sheet:opened", function () { getAttrs(["repeating_weaponscac_weaponname_cac"], function (values) { Remember to change your fieldset name in the html too.
GiGs said: You should only post the parts relevant to the question, only the weapons_cac section and sheet workers should have been posted here. I'll be sure to do it next time! Sorry about that. And thanks a lot. Everything works fine now. :)
1572303799
GiGs
Pro
Sheet Author
API Scripter
Great! :)
Strangely, I now got an issue regarding my character sheet. The INJ, Recharge, Chargeur don't populate anymore. I've tried many different things but I can't seems to get everything working as before. What part of the code someone would need to see to try and unbug everything? Thanks a lot.
1572587648
GiGs
Pro
Sheet Author
API Scripter
The sheet code is getting too big to post in the forum. you could post it on gist.github.com or pastebin, but you also need to describe what changes you've made to help narrow down where the issue might be.  First thing to check would be if you have changed any attribute names. You need to check that all the names mentioned in sheet workers match the ones outside the script block. Second would be have you added anything to the sheet worker script block - a character in the wrong place inside a script block can cause all sheet workers to fail.
So, the complete  code on PasteBin. Things I've changed:   -Create Tabs for character sheet  -Create checkbox for hurt level that influence some roll with a -1 or -2  -Create checkbox for a ''/w gm'' that influence each roll Thanks a lot.
1572618886

Edited 1572618996
GiGs
Pro
Sheet Author
API Scripter
You have a LOT of typos in the script block. For example:  gantelet_energetique: {repeating_weaponscac_DF: 9repeating_weapons_forcmult:  notice the 9 there And the syntax here eviscerateur: {repeating_weaponscac_DF: repeating_weapons_forcmult: 2, repeating_weapons_appbonus:"@{Body}"}, Notice theres a missing value for the DF. Another syntax error of this sort: hache_energetique: {repeating_weaponscac_DF: 5, repeating_weapons_forcmult: 2, repeating_weapons_appbonus:"@{Body}"}}, There's an extra } at the end there. You'll have to go through and correct them. There's also an extra }); right at the end just before the </script> line. You'll have to delete that. You cant be sloppy with javascript (the stuff inside the script block). You have to get the syntax right. It looks like all of the errors are in the  const weaponscac = { } section, except for those trailing brackets I just mentioned/
Wow, you're really a code ninja! Thanks for all your time GiGs. I know I'm no code expert but if you need anything, don't hesitate.
1572686781
GiGs
Pro
Sheet Author
API Scripter
I cant take all the credit, I just copied it into a javascript validator, and it highlighted a bunch of errors. :)
1574314058

Edited 1574314349
Hi there people, I'm posting in that subject again cause I'm having issues with repeating sections. When players modify their weapons, I can no longer refer to it with repeating_attribute_$0. It's now _$1. And so on and so forth for all other weapons. Is there a way to ''reset'' a weapon number so a new weapon would become the first one again ( _$0 )? Or the error is on my side?
1574318178
GiGs
Pro
Sheet Author
API Scripter
It's not an error, its just the way repeating sections work. If players reorder their weapons, you need to change the index numbers. If you use the chat menu scripts from the other thread, though, you'll get a list of buttons showing their weapon names, and dont need to worry about the index number. 
1574349121

Edited 1574349153
Oh ok, I understand. And good idea for the clickable buttons. I've created an invisible button for that purpose and it works mighty fine. Thanks a lot. :)
Doing some development on my character sheet.  Is there a way to create weapons or a repeating sections that only NPC could select? I mean, I don't want my player to be able to select a ''Scything talon'' for a weapon.
1575090545
GiGs
Pro
Sheet Author
API Scripter
The best way to do this is to have a setting on the sheet that lets you declare whether its a PC or NPC. Then you create two select boxes, each with their own options - one showing the options available to PCs, and the other for NPCs.  Then you use a CSS rule to hide one select and show the other, dependent on whether the character is a PC or NPC.
Great, thanks for the reply. I've been able to make it work. For anyone interested, I've used the code in this tread :&nbsp; <a href="https://app.roll20.net/forum/post/5678732/npc-slash-pc-button/?pageforid=5678732#post-5678732" rel="nofollow">https://app.roll20.net/forum/post/5678732/npc-slash-pc-button/?pageforid=5678732#post-5678732</a>