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 API Script: How to use it in Roll20

I'm neophyte about API, script, Javascipt, so i apologize if i will say some nonsense. I've created this script, and i want to use it in my roll20 tabletop during session, with !TesoroA chat message... anyone can help me. function rollDice(min, max) {   return min + Math.floor(Math.random() * (max-min + 1)) } const d2 = () => rollDice(1, 2) const d4 = () => rollDice(1, 4) const d6 = () => rollDice(1, 6) const d8 = () => rollDice(1, 8) const d12 = () => rollDice(1, 12) const d20 = () => rollDice(1, 20) const d10 = () => rollDice(1, 10) const d100 = () => rollDice(1,100) function Spade(){ var OggSpade = 1 for (OggSpade; OggSpade > 0; OggSpade--){ var TipoSpada = d20() if (TipoSpada >0 && TipoSpada <9){ console.log('Spada + 1')} else if (TipoSpada >8 && TipoSpada <11){ console.log('Spada + 1, + 2 contro i licantropi')} else if (TipoSpada =11){ console.log('Spada + 1, + 2 contro incantatori')} else if (TipoSpada >11 && TipoSpada <14){ console.log('Spada + 1, + 3 contro i non morti')} else if (TipoSpada >13 && TipoSpada <16){ console.log('Spada + 1, + 3 contro i draghi')} else if (TipoSpada =16){ console.log('Spada + 1, incantesimo “luce magica” 1/giorno ')} else if (TipoSpada >16 && TipoSpada <20){ console.log('Spada + 1, incantesimo “cura ferite leggere” 1/giorno')} else if (TipoSpada =20){ console.log('Spada + 2')} }} function AltreArmi(){ var OggAltreArmi = 1 for (OggAltreArmi; OggAltreArmi > 0; OggAltreArmi --){ var TipoAltraArma = d20() if (TipoAltraArma >0 && TipoAltraArma <5){ console.log('Frecce + 1 (10 frecce')} else if (TipoAltraArma >4 && TipoAltraArma <7){ console.log('Ascia + 1')} else if (TipoAltraArma >6 && TipoAltraArma <10){ console.log('Pugnale + 1')} else if (TipoAltraArma =10){ console.log('Pugnale + 1')} else if (TipoAltraArma >10 && TipoAltraArma <14){ console.log('Mazza + 1')} else if (TipoAltraArma >13 && TipoAltraArma <17){ console.log('Dardi per balestra + 1 (10 dardi)')} else if (TipoAltraArma =17){ console.log('Fionda + 1')} else if (TipoAltraArma >17){ console.log('Martello da guerra + 1')} }} function ScudiArmature(){ var OggScudiArmature = 1 for (OggScudiArmature; OggScudiArmature > 0; OggScudiArmature --){ var TipoScudiArmature = d20() if (TipoScudiArmature >0 && TipoScudiArmature <5){ console.log('Armatura di cuoio + 1')} else if (TipoScudiArmature >4 && TipoScudiArmature <10){ console.log('Corazza di maglia + 1')} else if (TipoScudiArmature >9 && TipoScudiArmature <12){ console.log('Corazza di piastre + 1')} else if (TipoScudiArmature >11 && TipoScudiArmature <18){ console.log('Scudo + 1')} else if (TipoScudiArmature >17 && TipoScudiArmature <20){ console.log('Scudo + 1')} else if (TipoScudiArmature =20){ console.log('Corazza di maglia + 1 e Scudo + 1')}   }} var TesoroAMR = d100() if (TesoroAMR<26){ console.log( d6()*1000 + ' Monete Rame'); } var TesoroAMA = d100() if (TesoroAMA<31){ console.log( d6()*1000 + ' Monete Argento'); } var TesoroAME = d100() if (TesoroAME<21){ console.log( d4()*1000 + ' Monete Electrum'); } var TesoroAMO = d100() if (TesoroAMO<36){ console.log( d6()*2000 + ' Monete Oro'); } var TesoroAMP = d100() if (TesoroAMP<26){ console.log( d2()*1000 + ' Monete Platino'); } var TesoroAGemme = d100() if (TesoroAGemme<51){ var GemmeA = d6()*6 console.log(GemmeA + ' Gemme') for (GemmeA; GemmeA > 0; GemmeA--){   var ValoreGemmeA = d100() if (ValoreGemmeA >0 && ValoreGemmeA <21){ console.log('Gemma del valore di ' + 10 + ' Monete Oro')} else if (ValoreGemmeA >20 && ValoreGemmeA <46){ console.log('Gemma del valore di ' + 50 + ' Monete Oro')} else if (ValoreGemmeA >45 && ValoreGemmeA <76){ console.log('Gemma del valore di ' + 100 + ' Monete Oro')} else if (ValoreGemmeA >75 && ValoreGemmeA <96){ console.log('Gemma del valore di ' + 500 + ' Monete Oro')} else if (ValoreGemmeA >96){ console.log('Gemma del valore di ' + 1000 + ' Monete Oro')}}   } var TesoroAGioielli = d100() if (TesoroAGioielli<51){ var GioielliA = d6()*6 console.log(GioielliA + ' Gioielli') for (GioielliA; GioielliA > 0; GioielliA--){ console.log('Gioiello del valore di ' + '' + d6()*300 + '' + ' Monete Oro')} } var TesoroAOggetti = d100() if (TesoroAOggetti <31){ console.log('3 oggetti magici') var OggettiA = 3 for (OggettiA; OggettiA > 0; OggettiA--){   var TipoOggettiA = d100() if (TipoOggettiA >0 && TipoOggettiA <21){ console.log(Spade.call())} else if (TipoOggettiA >20 && TipoOggettiA <31){ console.log(AltreArmi.call())} else if (TipoOggettiA >30 && TipoOggettiA <41){ console.log(ScudiArmature.call())} else if (TipoOggettiA >40 && TipoOggettiA <66){ console.log('Pozioni')} else if (TipoOggettiA >65 && TipoOggettiA <86){ console.log('Pergamene')} else if (TipoOggettiA >85 && TipoOggettiA <91){ console.log('Anelli')} else if (TipoOggettiA >90 && TipoOggettiA <96){ console.log('Bacchette, verghe e bastoni')} else if (TipoOggettiA >96){ console.log('Oggetti magici vari')}}   }}  
1609893165
The Aaron
Roll20 Production Team
API Scripter
I have no idea what this script is supposed to do, but I did some initial clean up on it and fixed a few issues: 1) Comparison in Javascript is == or ===.   = is assignment, so putting if(TipoAltraArma =17) will assign 17 to that variable, which will also be true to the if.  You want to use === for comparison everywhere until you understand what the difference between === and == is, and then you'll never want to use ==. 2)  console doesn't exist in the API sandbox, just use log() 3) You had an extra } at the end, which I removed 4) I wrapped it all in an on('ready',...) event handler 5) I replaced the rollDice() function with randomInteger(), which is supplied by the API.  Here's that code: on('ready',()=>{ const d2 = () => randomInteger(2); const d4 = () => randomInteger(4); const d6 = () => randomInteger(6); const d8 = () => randomInteger(8); const d12 = () => randomInteger(12); const d20 = () => randomInteger(20); const d10 = () => randomInteger(10); const d100 = () => randomInteger(100); function Spade(){ var OggSpade = 1; for (OggSpade; OggSpade > 0; OggSpade--){ var TipoSpada = d20(); if (TipoSpada >0 && TipoSpada <9){ log('Spada + 1'); } else if (TipoSpada >8 && TipoSpada <11) { log('Spada + 1, + 2 contro i licantropi'); } else if (TipoSpada === 11) { log('Spada + 1, + 2 contro incantatori'); } else if (TipoSpada >11 && TipoSpada <14) { log('Spada + 1, + 3 contro i non morti'); } else if (TipoSpada >13 && TipoSpada <16) { log('Spada + 1, + 3 contro i draghi'); } else if (TipoSpada === 16) { log('Spada + 1, incantesimo “luce magica” 1/giorno '); } else if (TipoSpada >16 && TipoSpada <20) { log('Spada + 1, incantesimo “cura ferite leggere” 1/giorno'); } else if (TipoSpada === 20) { log('Spada + 2'); } } } function AltreArmi() { var OggAltreArmi = 1; for (OggAltreArmi; OggAltreArmi > 0; OggAltreArmi --) { var TipoAltraArma = d20(); if (TipoAltraArma >0 && TipoAltraArma <5) { log('Frecce + 1 (10 frecce'); } else if (TipoAltraArma >4 && TipoAltraArma <7) { log('Ascia + 1'); } else if (TipoAltraArma >6 && TipoAltraArma <10) { log('Pugnale + 1'); } else if (TipoAltraArma ===10) { log('Pugnale + 1'); } else if (TipoAltraArma >10 && TipoAltraArma <14) { log('Mazza + 1'); } else if (TipoAltraArma >13 && TipoAltraArma <17) { log('Dardi per balestra + 1 (10 dardi)'); } else if (TipoAltraArma ===17) { log('Fionda + 1'); } else if (TipoAltraArma >17) { log('Martello da guerra + 1'); } } } function ScudiArmature() { var OggScudiArmature = 1; for (OggScudiArmature; OggScudiArmature > 0; OggScudiArmature --) { var TipoScudiArmature = d20(); if (TipoScudiArmature >0 && TipoScudiArmature <5) { log('Armatura di cuoio + 1'); } else if (TipoScudiArmature >4 && TipoScudiArmature <10) { log('Corazza di maglia + 1'); } else if (TipoScudiArmature >9 && TipoScudiArmature <12) { log('Corazza di piastre + 1'); } else if (TipoScudiArmature >11 && TipoScudiArmature <18) { log('Scudo + 1'); } else if (TipoScudiArmature >17 && TipoScudiArmature <20) { log('Scudo + 1'); } else if (TipoScudiArmature === 20) { log('Corazza di maglia + 1 e Scudo + 1'); } } } var TesoroAMR = d100(); if (TesoroAMR<26) { log( d6()*1000 + ' Monete Rame'); } var TesoroAMA = d100(); if (TesoroAMA<31) { log( d6()*1000 + ' Monete Argento'); } var TesoroAME = d100(); if (TesoroAME<21) { log( d4()*1000 + ' Monete Electrum'); } var TesoroAMO = d100(); if (TesoroAMO<36) { log( d6()*2000 + ' Monete Oro'); } var TesoroAMP = d100(); if (TesoroAMP<26) { log( d2()*1000 + ' Monete Platino'); } var TesoroAGemme = d100(); if (TesoroAGemme<51) { var GemmeA = d6()*6; log(GemmeA + ' Gemme'); for (GemmeA; GemmeA > 0; GemmeA--) { var ValoreGemmeA = d100(); if (ValoreGemmeA >0 && ValoreGemmeA <21) { log('Gemma del valore di ' + 10 + ' Monete Oro'); } else if (ValoreGemmeA >20 && ValoreGemmeA <46) { log('Gemma del valore di ' + 50 + ' Monete Oro'); } else if (ValoreGemmeA >45 && ValoreGemmeA <76) { log('Gemma del valore di ' + 100 + ' Monete Oro'); } else if (ValoreGemmeA >75 && ValoreGemmeA <96) { log('Gemma del valore di ' + 500 + ' Monete Oro'); } else if (ValoreGemmeA >96) { log('Gemma del valore di ' + 1000 + ' Monete Oro'); } } } var TesoroAGioielli = d100(); if (TesoroAGioielli<51) { var GioielliA = d6()*6; log(GioielliA + ' Gioielli'); for (GioielliA; GioielliA > 0; GioielliA--) { log('Gioiello del valore di ' + '' + d6()*300 + '' + ' Monete Oro'); } } var TesoroAOggetti = d100(); if (TesoroAOggetti <31) { log('3 oggetti magici'); var OggettiA = 3; for (OggettiA; OggettiA > 0; OggettiA--) { var TipoOggettiA = d100(); if (TipoOggettiA >0 && TipoOggettiA <21) { log(Spade.call()); } else if (TipoOggettiA >20 && TipoOggettiA <31) { log(AltreArmi.call()); } else if (TipoOggettiA >30 && TipoOggettiA <41) { log(ScudiArmature.call()); } else if (TipoOggettiA >40 && TipoOggettiA <66) { log('Pozioni'); } else if (TipoOggettiA >65 && TipoOggettiA <86) { log('Pergamene'); } else if (TipoOggettiA >85 && TipoOggettiA <91) { log('Anelli'); } else if (TipoOggettiA >90 && TipoOggettiA <96) { log('Bacchette, verghe e bastoni'); } else if (TipoOggettiA >96) { log('Oggetti magici vari'); } } } }); Describe what this is supposed to do, and we can probably help you with it.
First of all thanks for your patience and for your professionalism, I very much appreciated. My idea is to use in chat !TreasureA to generate a BECMI type A Treasure
1609897728
The Aaron
Roll20 Production Team
API Scripter
Ah! That's quite an ambitious undertaking.&nbsp; A lot of people use RecursiveTable to build out a hierarchy of tables to do a roll on.&nbsp; That's also a pretty hefty undertaking, but much of it is already handled for you by the script. If you still want to build out your own script, probably you should spend some time learning Javascript in a more official capacity.&nbsp; Here's a decent site for it:&nbsp; <a href="http://jsforcats.com/" rel="nofollow">http://jsforcats.com/</a> And here are some links that talk about writing API scripts: <a href="https://app.roll20.net/forum/post/6605115/namespaces-novice-seeks-help-exploring-the-revealing-module-pattern" rel="nofollow">https://app.roll20.net/forum/post/6605115/namespaces-novice-seeks-help-exploring-the-revealing-module-pattern</a> <a href="https://app.roll20.net/forum/post/6584105/creating-an-object-that-holds-specific-character-dot-id-and-character-name/?pagenum=1" rel="nofollow">https://app.roll20.net/forum/post/6584105/creating-an-object-that-holds-specific-character-dot-id-and-character-name/?pagenum=1</a> <a href="https://app.roll20.net/forum/post/6237754/slug%7D" rel="nofollow">https://app.roll20.net/forum/post/6237754/slug%7D</a> I'll dig out my BECMI books and look at the tables, I might be able to help a bit with it this weekend.
I think i solve the problem. This script seems be good: on('ready', () =&gt; { &nbsp; &nbsp; const die = (sides) =&gt; randomInteger(sides); &nbsp; &nbsp; function Spade(){ var OggSpade = 1 for (OggSpade; OggSpade &gt; 0; OggSpade--){ var TipoSpada = die(20) if (TipoSpada &gt;0 &amp;&amp; TipoSpada &lt;9){ sendChat('Tesoro A', `/w gm Spada + 1`)} else if (TipoSpada &gt;8 &amp;&amp; TipoSpada &lt;11){ sendChat('Tesoro A', `/w gm Spada + 1, + 2 contro i licantropi`)} else if (TipoSpada =11){ sendChat('Tesoro A', `/w gm Spada + 1, + 2 contro incantatori`)} else if (TipoSpada &gt;11 &amp;&amp; TipoSpada &lt;14){ sendChat('Tesoro A', `/w gm Spada + 1, + 3 contro i non morti`)} else if (TipoSpada &gt;13 &amp;&amp; TipoSpada &lt;16){ sendChat('Tesoro A', `/w gm Spada + 1, + 3 contro i draghi`)} else if (TipoSpada =16){ sendChat('Tesoro A', `/w gm Spada + 1, incantesimo “luce magica” 1/giorno`)} else if (TipoSpada &gt;16 &amp;&amp; TipoSpada &lt;20){ sendChat('Tesoro A', `/w gm Spada + 1, incantesimo “cura ferite leggere” 1/giorno `)} else if (TipoSpada =20){ sendChat('Tesoro A', `/w gm Spada + 2`)} }} &nbsp;function AltreArmi(){ var OggAltreArmi = 1 for (OggAltreArmi; OggAltreArmi &gt; 0; OggAltreArmi--){ var TipoAltraArma = die(20) if (TipoAltraArma &gt;0 &amp;&amp; TipoAltraArma &lt;5){ sendChat('Tesoro A', `/w gm Frecce + 1 (10 frecce`)} else if (TipoAltraArma &gt;4 &amp;&amp; TipoAltraArma &lt;7){ sendChat('Tesoro A', `/w gm Ascia + 1`)} else if (TipoAltraArma &gt;6 &amp;&amp; TipoAltraArma &lt;10){ sendChat('Tesoro A', `/w gm Pugnale + 1`)} else if (TipoAltraArma =10){ sendChat('Tesoro A', `/w gm Pugnale + 1`)} else if (TipoAltraArma &gt;10 &amp;&amp; TipoAltraArma &lt;14){ sendChat('Tesoro A', `/w gm Mazza + 1`)} else if (TipoAltraArma &gt;13 &amp;&amp; TipoAltraArma &lt;17){ sendChat('Tesoro A', `/w gm Dardi per balestra + 1 (10 dardi)`)} else if (TipoAltraArma =17){ sendChat('Tesoro A', `/w gm Fionda + 1`)} else if (TipoAltraArma &gt;17){ sendChat('Tesoro A', `/w gm Martello da guerra + 1`)} }} function ScudiArmature(){ var OggScudiArmature = 1 for (OggScudiArmature; OggScudiArmature &gt; 0; OggScudiArmature--){ var TipoScudiArmature= die(20) if (TipoScudiArmature &gt;0 &amp;&amp; TipoScudiArmature &lt;5){ sendChat('Tesoro A', `/w gm Armatura di cuoio + 1`)} else if (TipoScudiArmature &gt;4 &amp;&amp; TipoScudiArmature &lt;10){ sendChat('Tesoro A', `/w gm Corazza di maglia + 1`)} else if (TipoScudiArmature &gt;9 &amp;&amp; TipoScudiArmature &lt;12){ sendChat('Tesoro A', `/w gm Corazza di piastre + 1`)} else if (TipoScudiArmature &gt;11 &amp;&amp; TipoScudiArmature &lt;18){ sendChat('Tesoro A', `/w gm Scudo + 1`)} else if (TipoScudiArmature &gt;17 &amp;&amp; TipoScudiArmature &lt;20){ sendChat('Tesoro A', `/w gm Scudo + 1`)} else if (TipoScudiArmature =20){ sendChat('Tesoro A', `/w gm Corazza di maglia + 1 e Scudo + 1`)} }} function Pozioni(){ var OggPozioni = 1 for (OggPozioni; OggPozioni &gt; 0; OggPozioni--){ var TipoPozioni= die(20) if (TipoPozioni &gt;0 &amp;&amp; TipoPozioni &lt;5){ sendChat('Tesoro A', `/w gm Pozione di rimpicciolimento`)} else if (TipoPozioni &gt;4 &amp;&amp; TipoPozioni &lt;7){ sendChat('Tesoro A', `/w gm Pozione di E.S.P.`)} else if (TipoPozioni &gt;6 &amp;&amp; TipoPozioni &lt;10){ sendChat('Tesoro A', `/w gm Pozione di forma gassosa`)} else if (TipoPozioni &gt;9 &amp;&amp; TipoPozioni &lt;13){ sendChat('Tesoro A', `/w gm Pozione di crescita`)} else if (TipoPozioni &gt;12 &amp;&amp; TipoPozioni &lt;17){ sendChat('Tesoro A', `/w gm Pozione di guarigione`)} else if (TipoPozioni =17){ sendChat('Tesoro A', `/w gm Pozione d'invisibilità`)} else if (TipoPozioni &gt;17 &amp;&amp; TipoPozioni &lt;20){ sendChat('Tesoro A', `/w gm Pozione di levitazione`)} else if (TipoPozioni =20){ sendChat('Tesoro A', `/w gm Pozione del veleno`)} }} function Pergamene(){ var OggPergamene = 1 for (OggPergamene; OggPergamene &gt; 0; OggPergamene--){ var TipoPergamene= die(20) if (TipoPergamene &gt;0 &amp;&amp; TipoPergamene &lt;5){ sendChat('Tesoro A', `/w gm Pergamena con 1 incantesimo`)} else if (TipoPergamene &gt;4 &amp;&amp; TipoPergamene &lt;8){ sendChat('Tesoro A', `/w gm Pergamena con 2 incantesimi`)} else if (TipoPergamene =8){ sendChat('Tesoro A', `/w gm Pergamena con 3 incantesimi`)} else if (TipoPergamene &gt;8 &amp;&amp; TipoPergamene &lt;11){ sendChat('Tesoro A', `/w gm Maledizione (lanciata automaticamente su chi legge)`)} else if (TipoPergamene &gt;10 &amp;&amp; TipoPergamene &lt;14){ sendChat('Tesoro A', `/w gm Pergamena di protezione contro i licantropi`)} else if (TipoPergamene &gt;13 &amp;&amp; TipoPergamene &lt;17){ sendChat('Tesoro A', `/w gm Pergamena di protezione contro i non morti`)} else if (TipoPergamene &gt;16 &amp;&amp; TipoPergamene &lt;19){ sendChat('Tesoro A', `/w gm Mappa di un tesoro del valore di ${dice(6)*1000} monete d'oro`)} else if (TipoPergamene &gt;18){ sendChat('Tesoro A', `/w gm Mappa di un tesoro magico`)} }} function Anelli(){ var OggAnelli = 1 for (OggAnelli; OggAnelli &gt; 0; OggAnelli--){ var TipoAnelli= die(20) if (TipoAnelli &gt;0 &amp;&amp; TipoAnelli &lt;4){ sendChat('Tesoro A', `/w gm Anello del controllo sugli animali`)} else if (TipoAnelli &gt;3 &amp;&amp; TipoAnelli &lt;9){ sendChat('Tesoro A', `/w gm Anello di resistenza al fuoco`)} else if (TipoAnelli &gt;8 &amp;&amp; TipoAnelli &lt;11){ sendChat('Tesoro A', `/w gm Anello di invisibilità`)} else if (TipoAnelli &gt;10 &amp;&amp; TipoAnelli &lt;16){ sendChat('Tesoro A', `/w gm Anello di protezione + 1`)} else if (TipoAnelli &gt;15 &amp;&amp; TipoAnelli &lt;19){ sendChat('Tesoro A', `/w gm Anello per camminare sulle acque`)} else if (TipoAnelli &gt;19){ sendChat('Tesoro A', `/w gm Anello indebolimento`)} }} function BacchetteVergheBastoni(){ var OggBacchetteVergheBastoni = 1 for (OggBacchetteVergheBastoni; OggBacchetteVergheBastoni &gt; 0; OggBacchetteVergheBastoni--){ var TipoBacchetteVergheBastoni= die(20) if (TipoBacchetteVergheBastoni &gt;0 &amp;&amp; TipoBacchetteVergheBastoni &lt;7){ sendChat('Tesoro A', `/w gm Bacchetta di individuazione dei nemici`)} else if (TipoBacchetteVergheBastoni &gt;6 &amp;&amp; TipoBacchetteVergheBastoni &lt;12){ sendChat('Tesoro A', `/w gm Bacchetta di individuazione della magia`)} else if (TipoBacchetteVergheBastoni &gt;11 &amp;&amp; TipoBacchetteVergheBastoni &lt;15){ sendChat('Tesoro A', `/w gm Bacchetta paralizzante`)} else if (TipoBacchetteVergheBastoni &gt;14 &amp;&amp; TipoBacchetteVergheBastoni &lt;18){ sendChat('Tesoro A', `/w gm Bastone guaritore`)} else if (TipoBacchetteVergheBastoni =18){ sendChat('Tesoro A', `/w gm Bastone/serpente`)} else if (TipoBacchetteVergheBastoni &gt;18){ sendChat('Tesoro A', `/w gm Verga della dissoluzione della magia`)} }} function OggettiMagiciVari(){ var OggOggettiMagiciVari = 1 for (OggOggettiMagiciVari; OggOggettiMagiciVari &gt; 0; OggOggettiMagiciVari--){ var TipoOggettiMagiciVari= die(20) if (TipoOggettiMagiciVari &gt;0 &amp;&amp; TipoOggettiMagiciVari &lt;3){ sendChat('Tesoro A', `/w gm Borsa dissolvente`)} else if (TipoOggettiMagiciVari &gt;2 &amp;&amp; TipoOggettiMagiciVari &lt;6){ sendChat('Tesoro A', `/w gm Borsa conservante`)} else if (TipoOggettiMagiciVari =6){ sendChat('Tesoro A', `/w gm Sfera di cristallo`)} else if (TipoOggettiMagiciVari &gt;6 &amp;&amp; TipoOggettiMagiciVari &lt;9){ sendChat('Tesoro A', `/w gm Mantello degli elfi`)} else if (TipoOggettiMagiciVari &gt;8 &amp;&amp; TipoOggettiMagiciVari &lt;11){ sendChat('Tesoro A', `/w gm Stivali degli elfi`)} else if (TipoOggettiMagiciVari =11){ sendChat('Tesoro A', `/w gm Guanti del potere orchesco`)} else if (TipoOggettiMagiciVari &gt;11 &amp;&amp; TipoOggettiMagiciVari &lt;14){ sendChat('Tesoro A', `/w gm Elmo di mutazione dell'allineameto`)} else if (TipoOggettiMagiciVari &gt;13 &amp;&amp; TipoOggettiMagiciVari &lt;17){ sendChat('Tesoro A', `/w gm Elmo telepatico`)} else if (TipoOggettiMagiciVari &gt;16 &amp;&amp; TipoOggettiMagiciVari &lt;19){ sendChat('Tesoro A', `/w gm Medaglione E.S.P.`)} else if (TipoOggettiMagiciVari &gt;18){ sendChat('Tesoro A', `/w gm Corda magica`)} }} &nbsp; &nbsp; on('chat:message', (msg) =&gt; { &nbsp; &nbsp; &nbsp; &nbsp; if ('api' === msg.type &amp;&amp; msg.content.match(/^!TesoroA/)) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const TesoroAMR = die(100); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const TesoroAMA = die(100); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const TesoroAME = die(100); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const TesoroAMO = die(100); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const TesoroAMP = die(100); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const TesoroAGemme = die(100); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const TesoroAGioielli = die(100); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const TesoroAOggetti = die(100); &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (TesoroAMR &lt;= 25) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat('Tesoro A', `/w gm Monete di Rame:${die(6)*1000}`); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (TesoroAMA &lt;= 30) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat('Tesoro A', `/w gm Monete d'Argento:${die(6)*1000}`); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (TesoroAME &lt;= 20) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat('Tesoro A', `/w gm Monete d'Electrum:${die(4)*1000}`); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (TesoroAMO &lt;= 35) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat('Tesoro A', `/w gm Monete d'Oro:${die(6)*2000}`); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (TesoroAMP &lt;= 25) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat('Tesoro A', `/w gm Monete di Platino:${die(2)*1000}`); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (TesoroAGemme &lt;= 50) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var GemmeA = die(6)*6 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat('Tesoro A', `/w gm Gemme:${GemmeA}`); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for (GemmeA; GemmeA &gt; 0; GemmeA--){ &nbsp; var ValoreGemmeA = die(100) if (ValoreGemmeA &gt;0 &amp;&amp; ValoreGemmeA &lt;21){ &nbsp;sendChat('Tesoro A', `/w gm Gemma del valore di 10 Monete Oro`)} else if (ValoreGemmeA &gt;20 &amp;&amp; ValoreGemmeA &lt;46){ &nbsp;sendChat('Tesoro A', `/w gm Gemma del valore di 50 Monete Oro`)} else if (ValoreGemmeA &gt;45 &amp;&amp; ValoreGemmeA &lt;76){ &nbsp;sendChat('Tesoro A', `/w gm Gemma del valore di 100 Monete Oro`)} else if (ValoreGemmeA &gt;75 &amp;&amp; ValoreGemmeA &lt;96){ &nbsp;sendChat('Tesoro A', `/w gm Gemma del valore di 500 Monete Oro`)} else if (ValoreGemmeA &gt;96){ &nbsp;sendChat('Tesoro A', `/w gm Gemma del valore di 1000 Monete Oro`)}} &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (TesoroAGioielli &lt;= 50) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var GioielliA = die(6)*6 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat('Tesoro A', `/w gm Gioielli:${GioielliA}`); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (GioielliA; GioielliA &gt; 0; GioielliA--){ &nbsp; &nbsp;sendChat('Tesoro A', `/w gm Gioiello del valore di ${die(6)*300} Monete Oro`)} &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (TesoroAOggetti &lt;= 30) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var OggettiA = 3 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat('Tesoro A', `/w gm 3 Oggetti Magici`); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for (OggettiA; OggettiA &gt; 0; OggettiA--){ var TipoOggettiA = die (100) if (TipoOggettiA &gt;0 &amp;&amp; TipoOggettiA &lt;21){ Spade.call()} else if (TipoOggettiA &gt;20 &amp;&amp; TipoOggettiA &lt;31){ AltreArmi.call()} else if (TipoOggettiA &gt;30 &amp;&amp; TipoOggettiA &lt;41){ ScudiArmature.call()} else if (TipoOggettiA &gt;40 &amp;&amp; TipoOggettiA &lt;66){ Pozioni.call()} else if (TipoOggettiA &gt;65 &amp;&amp; TipoOggettiA &lt;86){ Pergamene.call()} else if (TipoOggettiA &gt;85 &amp;&amp; TipoOggettiA &lt;91){ Anelli.call()} else if (TipoOggettiA &gt;90 &amp;&amp; TipoOggettiA &lt;96){ BacchetteVergheBastoni.call()} else if (TipoOggettiA &gt;96){ OggettiMagiciVari.call()}} &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } }})})
1609952828
The Aaron
Roll20 Production Team
API Scripter
Well, as long as it's working for you, that sounds great! I might suggest switching your die() implementation to this: const times = (n,f)=&gt;Array(n).fill(n).map(f); const die = (s,n=1) =&gt; times(n,()=&gt;randomInteger(s)).reduce((m,a)=&gt;m+a); Then you can roll 6d6 as: var GemmeA = die(6,6); As what you have now: var GemmeA = die(6)*6 Is equivalent to: 1d6 x 6
Thank Aaron, switch executed ;) I've another question: there's a way to put 6*6 results of this: if (TesoroAGemme &lt;= 50) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var GemmeA = die(6)*6 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat('Tesoro A', `/w gm Gemme:${GemmeA}`); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for (GemmeA; GemmeA &gt; 0; GemmeA--){ &nbsp; var ValoreGemmeA = die(100) if (ValoreGemmeA &gt;0 &amp;&amp; ValoreGemmeA &lt;21){ &nbsp;sendChat('Tesoro A', `/w gm Gemma del valore di 10 Monete Oro`)} else if (ValoreGemmeA &gt;20 &amp;&amp; ValoreGemmeA &lt;46){ &nbsp;sendChat('Tesoro A', `/w gm Gemma del valore di 50 Monete Oro`)} else if (ValoreGemmeA &gt;45 &amp;&amp; ValoreGemmeA &lt;76){ &nbsp;sendChat('Tesoro A', `/w gm Gemma del valore di 100 Monete Oro`)} else if (ValoreGemmeA &gt;75 &amp;&amp; ValoreGemmeA &lt;96){ &nbsp;sendChat('Tesoro A', `/w gm Gemma del valore di 500 Monete Oro`)} else if (ValoreGemmeA &gt;96){ &nbsp;sendChat('Tesoro A', `/w gm Gemma del valore di 1000 Monete Oro`)}} &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; In only one line? so that the result seems like: "(From Tesoro A): Gemme: x(6*6) &nbsp;(From Tesoro A): Gemme prices: x monete, x monete, x monete, x monete"
1609957931
The Aaron
Roll20 Production Team
API Scripter
Something like: if (TesoroAGemme &lt;= 50) { var GemmeA = die(6,6); let output = `/w gm Gemme:${GemmeA}: ` let GemmaResults = []; for (GemmeA; GemmeA &gt; 0; GemmeA--){ var ValoreGemmeA = die(100) if (ValoreGemmeA &gt;0 &amp;&amp; ValoreGemmeA &lt;21){ GemmaResults.push(`Gemma del valore di 10 Monete Oro`); } else if (ValoreGemmeA &gt;20 &amp;&amp; ValoreGemmeA &lt;46){ GemmaResults.push(`Gemma del valore di 50 Monete Oro`); } else if (ValoreGemmeA &gt;45 &amp;&amp; ValoreGemmeA &lt;76){ GemmaResults.push(`Gemma del valore di 100 Monete Oro`); } else if (ValoreGemmeA &gt;75 &amp;&amp; ValoreGemmeA &lt;96){ GemmaResults.push(`Gemma del valore di 500 Monete Oro`); } else if (ValoreGemmeA &gt;96){ GemmaResults.push(`Gemma del valore di 1000 Monete Oro`); } } sendChat('Tesoro A', `${ouput} ${GemmaResults.join(', ')}`); }