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

[en français] Comment faire un macro qui affiche un résultat "texte" d'un tirage aléatoire

1638313744

Edited 1638313818
Bonjour, J'aimerai créer l'équivalent d'un tableau de blessures critiques. Le tirage se ferait avec1d20 auquel on pourrait ajouter une variable allant de -2 à +10. Le seul moyen que j'ai trouvé c'est d'utiliser plein de rollable tables (sachant que mon tableau aurait 30 entrées de poids identique). Ma macro ressemblerait à ça :  [[1t[blessure-grave-?{Modificateur|-2|-1|0|1|2}] ]] Et encore là j'ai déjà 5 tables appelées blessure-grave--2, blessure-grave--1, etc... alors que je peux aller de -2 à +10... Bref existe-t-il une manière de faire moins chiante ?  Là je sèche. Merci à tous !
1638334373
timmaugh
Forum Champion
API Scripter
Hey, Yanick... sorry this reply will be in English, but hopefully Google translate will work for you.  I'm not quite sure whether you have a range of -1 to 30 which you've broken up into 12 tables that overlap (from -1 to 18, from 0 to 19, from 1 to 20, etc.), or whether you have 12 lists (-2 to 10) of 30 items. In either case, Muler can help. Muler is a metascript that can let you roll -- with a modifier -- against a static list of returns (a table). Paired with ZeroFrame (and probably SelectManager), you can output nicely formatted text, or drop your returned text into another script or to a location on your character sheet. ZF and SM are also metascripts, and they're all available from the 1-click. Here's what it would look like... You'd create a mule table on a character. The mule table is a character ability with specific formatting. The character can be a sheet that you add only to track the mule table information (once you get the hang of it, you might want to create more mule tables and house them on this same character. So let's say your character is named MuleBoy and your mule table (ability) is named "InjuryTable". Enter your injury information attached to the value that would denote that injury. It sounds like you have a range of the lowest value you could roll on a d20 (1) minus the greatest negative modifier (-2), giving you a -1. Your upper value seems to be 30 (d20 = 20, +10 modifier). So your mule table would look like: -1=A hangnail 0=A splinter 1=A case of spontaneous jazz hands 2=... ...all the way up to 30. Then you can retrieve a value from that table. Here is returning the value associated with 5: get.MuleBoy.InjuryTable.5/get If you want to roll against the list, use an inline roll and extract the result. Here is your roll: [[1d20 + ?{Modifier|-2|-1|0|1|2|3|4|5|6|7|8|9|10}]] And here is the same roll used in a get statement (like above): get.MuleBoy.InjuryTable.[[1d20 + ?{Modifier|-2|-1|0|1|2|3|4|5|6|7|8|9|10}]].value/get One other piece that you need is to tell your line to load up the macro, which you do like this: {& mule MuleBoy.InjuryTable} Here is the final product in a roll template (using the representative roll marker for the roll to get the value, since I need the roll in 2 places): !&{template:default}{{name=Injury Report}} [[1d20 + ?{Modifier|-2|-1|0|1|2|3|4|5|6|7|8|9|10}]] {{Result $[[0]]=get.MuleBoy.InjuryTable.$[[0]]/get}}{& mule MuleBoy.InjuryTable}{&simple} That could obviously be made up to be prettier with more information from the character, etc. Note, too, that these results are recursive (with ZeroFrame installed), so you could expand other calls to other mules that were stored in the value you retrieved, or roll inline rolls. If you post more information from your table, I can help you put the finished product together, if this is a direction you want to go.
1638719043

Edited 1638719302
Thank you Timmaugh, I'll try this way. I'm not sur that everything is understood but I'll try. :)
1639518448

Edited 1639519457
I didn't succed that way... :/ So I tried another way (changing my critical hit table with a d100 instead of a d20) but I have some problems using POWERCARDS : - the text doesn't appear complete in the chat box. Here is my macro : !power {{ --bgcolor|#000000 --txcolor|##ffffff -- erowbg|#000000 -- orowbg|#000000 --erowtx|#ffffff --orowtx|#ffffff --name|Blessure Grave --Jet| [[ [$JET] 1d100 + ?{Modificateur} ]] -- ?? $JET <= 5 ?? ! BG1  :|^^~C**[! Petite entaille (ND 10) : +1 DM !]** ~C  -- ?? $JET >= 6 AND $JET <= 10 ?? ! BG2  :|^^~C**[! Ralentissement (ND 10) : la cible gagne l'état "ralenti" !]** ~C  -- ?? $JET >= 11 AND $JET <= 15 ?? ! BG3  :|^^~C**[! Choc (ND 10) : la cible lâche ce qu'elle tient !]** ~C  -- ?? $JET >= 16 AND $JET <= 20 ?? ! BG4  :|^^~C**[! Distraction  (ND 10) : la cible gagne l'état "ralenti" !]** ~C  -- ?? $JET >= 21 AND $JET <= 25 ?? ! BG5  :|^^~C**[! Déséquilibre (ND 10) : la cible doit faire un test de FOR diff. 12 ou se retrouver au sol. !]** ~C  -- ?? $JET >= 26 AND $JET <= 30 ?? ! BG6  :|^^~C**[! Blessure accablante (ND 10) : La cible pert un point de force (ou gagne l'état "étourdi" si plus de points de force) !]** ~C  -- ?? $JET >= 31 AND $JET <= 35 ?? ! BG7  :|^^~C**[! Etourdissement (ND 10) : la cible gagne l'état "étourdi" jusque la fin de son prochain tour. !]** ~C  -- ?? $JET >= 36 AND $JET <= 40 ?? ! BG8  :|^^~C**[! Piqûre (ND 10) : la cible perd 1d4+1 DM supplémentaire !]** ~C  -- ?? $JET >= 41 AND $JET <= 45 ?? ! BG9  :|^^~C**[! Renversement (ND 15) : la cible gagne l'état "renversé" !]** ~C  -- ?? $JET >= 46 AND $JET <= 50 ?? ! BG10  :|^^~C**[! Mal au crâne (ND 15) : la cible perd 2 en INT jusqu'à ce qu'elle soit soignée. !]** ~C  -- ?? $JET >= 51 AND $JET <= 55 ?? ! BG11  :|^^~C**[! Blessure effroyable (ND 15) : la cible perd 1d8+1 DM supplémentaire !]** ~C  -- ?? $JET >= 56 AND $JET <= 60 ?? ! BG12  :|^^~C**[! Blessure lancinante (ND 15) : la cible perd 2 en CON jusqu'à ce qu'elle soit soignée !]** ~C  -- ?? $JET >= 61 AND $JET <= 65 ?? ! BG13  :|^^~C**[! Hébétement (ND 15) : la cible gagne l'état "étourdi" et perd 2 en SAG jusqu’à ce qu'elle soit soignée !]** ~C  -- ?? $JET >= 66 AND $JET <= 70 ?? ! BG14  :|^^~C**[! Confusion (ND 15) : la cible gagne l'état "étourdi" et perd 2 en INT et en SAG jusqu'à ce qu'elle soit soignée !]** ~C  -- ?? $JET >= 71 AND $JET <= 75 ?? ! BG15  :|^^~C**[! Paralysé (ND 15) : la cible gagne l'état "paralysé" !]** ~C  -- ?? $JET >= 76 AND $JET <= 80 ?? ! BG16  :|^^~C**[! Aux abois (ND 15) : la cible ouvre sa garde offrant à son agresseur une attaque gratuite immédiate (attaque simple) !]** ~C  -- ?? $JET >= 81 AND $JET <= 85 ?? ! BG17  :|^^~C**[! Hors d'haleine (ND 15) : la cible gagne l'état "ralenti" et perd 2 en FOR !]** ~C  -- ?? $JET >= 86 AND $JET <= 90 ?? ! BG18  :|^^~C**[! A mal (ND 15) : la cible gagne les états "aveuglé" et "ralenti" !]** ~C  -- ?? $JET >= 91 AND $JET <= 95 ?? ! BG19  :|^^~C**[! Exténuation (ND 20) : la cible subit 1d10+1 DM temporaire et perd 2 en FOR !]** ~C  -- ?? $JET >= 96 AND $JET <= 100 ?? ! BG20  :|^^~C**[! Infirmité (ND 20) : L'un des membres de la cible (choisi par le MJ) est infirme jusqu'à ce qu'on le soigne ou qu'on le remplace. La cible ne peut plus utiliser ce membre. !]** ~C  -- ?? $JET >= 101 AND $JET <= 105 ?? ! BG21  :|^^~C**[! Mutilation (ND 20) : La cible perd définitivement l'un de ses membres (choisi par le Mj). Elle doit réussir un test de CON diff. 15 immédiatement ou tomber dans l'inconscience pendant 1d6 h. !]** ~C  -- ?? $JET >= 106 AND $JET <= 110 ?? ! BG22  :|^^~C**[! Blessure épouvantable (ND 20) : la cible perd 1d10+1 DM supplémentaire et perd 2 FOR et 2 CON jusqu'à ce qu'elle soit soignée. !]** ~C  -- ?? $JET >= 111 AND $JET <= 115  ?? ! BG23  :|^^~C**[! Invalidité (ND 20) : la cible gagne les états "affaibli" et "ralenti" jusqu'à ce qu'elle soit soignée.  !]** ~C  -- ?? $JET >= 116 AND $JET <= 120 ?? ! BG24  :|^^~C**[! Aveuglé (ND 20) : la cible gagne l'état "aveuglé". !]** ~C  -- ?? $JET >= 121 AND $JET <= 125 ?? ! BG25  :|^^~C**[! Perte de connaissance (ND 20) : la cible gagne l'état "inconscient" et perd 2 en INT et en SAG jusqu'à ce qu'elle soit soignée !]** ~C  -- ?? $JET >= 126 AND $JET <= 130 ?? ! BG26  :|^^~C**[! Blessure de cauchemar (ND 25) : la cible perd 1d12+1 DM supplémentaire. Elle perd également 2 dans une carac au choix définitivement !]** ~C  -- ?? $JET >= 131 AND $JET <= 140 ?? ! BG27  :|^^~C**[! Hémorragie (ND 25) : A chaque tour, la cible perd 1d6 DM jusqu'à ce qu'elle soit soignée.  !]** ~C  -- ?? $JET >= 141 AND $JET <= 150 ?? ! BG28  :|^^~C**[! La fin est proche (ND 25) : la cible meurt au prochain tour sans soins adaptés. !]** ~C  -- ?? $JET >= 151 ?? ! BG29  :|^^~C**[! Mort : décès irréversible !]** ~C  }}
1639519570

Edited 1639594397
For example, when I lauch the macro I have : And the end of the text is missing...
1639581944

Edited 1639658829
timmaugh
Forum Champion
API Scripter
Hmm... Back to the Muler solution, I did make a mistake in the code I suggested. This works for me (translated into English): ===================================================================================== Character: MuleBoy Ability: InjuryTable Content: ===================================================================================== <=5= Small notch (ND 10): +1 DM  6-10=Slowdown (ND 10): the target gains the "slowed" state  11-15=Shock (ND 10): the target drops what it is holding  16-20=Distraction (ND 10): the target gains the "slowed" state  21-25=Imbalance (ND 10): the target must take a FOR diff test. 12 or end up on the ground.  26-30=Overwhelming wound (ND 10): The target loses a point of strength (or gains the state "stunned" if more points of strength)  31-35=Stun (ND 10): the target gains the "stunned" state until the end of his next turn.  36-40=Sting (ND 10): the target loses 1d4 + 1 additional DM  41-45=Knockdown (ND 15): the target gains the "knocked down" state  46-50=Headache (ND 15): the target loses 2 INT until it is healed.  51-55=Dreadful Injury (ND 15): the target loses 1d8 + 1 additional DM  56-60=Throbbing wound (ND 15): the target loses 2 CON until it is healed  61-65=Dazed (ND 15): the target gains the "stunned" state and loses 2 SAG until it is healed  66-70=Confusion (ND 15): the target gains the "stunned" state and loses 2 INT and SAG until it is healed  71-75=Paralyzed (ND 15): the target gains the "paralyzed" state  76-80=At bay (ND 15): the target opens its guard offering its attacker an immediate free attack (simple attack)  81-85=Out of breath (ND 15): the target gains the "slowed" state and loses 2 STR  86-90=Badly (ND 15): the target gains the "blinded" and "slowed" states  91-95=Exhaustion (ND 20): the target suffers 1d10 + 1 temporary DM and loses 2 STR  96-100=Disability (ND 20): One of the target's limbs (chosen by the GM) is crippled until either cured or replaced. The target can no longer use this member.  101-105=Mutilation (ND 20): The target permanently loses one of its members (chosen by the GM). It must pass a CON diff test. 15 immediately or fall unconscious for 1d6 h.  106-110=Terrible Injury (ND 20): the target loses 1d10 + 1 additional DM and loses 2 STR and 2 CON until it is healed.  111-115=Disability (ND 20): The target gains "weakened" and "slowed" states until it is healed.  116-120=Blinded (ND 20): the target gains the "blinded" state.  121-125=Loss of consciousness (ND 20): the target gains the "unconscious" state and loses 2 in INT and SAG until it is healed  126-130=Nightmare Injury (ND 25): The target loses 1d12 + 1 additional DM. She also loses 2 in a character of your choice definitely  131-140=Bleeding (ND 25): Each turn, the target loses 1d6 DM until it is healed.  141-150=The end is near (ND 25): the target dies on the next turn without adequate healing.  >=151=Death: irreversible death  Then this command: !&{template:default}{{name=Injury Report}} [[1d100 + ?{Modifier}]] {{Result =Rolled $[[0]]%NEWLINE%get.MuleBoy.InjuryTable.$[[0]].value/get}}{& mule MuleBoy.InjuryTable}{&simple} Produces this sort of output:
I tried... But I failed... :( I installed the three API (Muler, Zeroframe and SelectManager) I created my MuleBoy : I created the launch macro : It's ok when I launch, I'me asked about a modifier : Then, nothing in the chat box... :( What have I done wrong  ?... Thank you for your help Timmaugh. :) 
1639595275

Edited 1639596219
IT'S OK !!!!! I launched again the API and it works !!!!! Thank you ! I have also another question : How can I do to make the  text in the chat box more smart ? Can I  have something like my missed example above ? Edit : there is a problem with a negative modifier, it seems that ther is a loop when the result is negative also :
1639597434

Edited 1639597499
timmaugh
Forum Champion
API Scripter
Excellent that you got it working, Yanick! Let me dig into the loop on the negative outcome and see what I can figure out, there. As for your previous example with the PowerCards macro... if by "smart" you want the formatting that PowerCards gave you, you can get that. Now that you see the way to get the data from Muler, you just have to put that component into your PowerCards macro. Basically, Muler will pull the text from your mule into the PowerCard command line so that by the time PC sees it the proper injury text is there. That means you can do away with a conditional check in PC completely. The PC macro will look very simple because all of your cases will be stored in the mule. It will be dynamic, though, because every time you roll you will get a potentially-different return from the Mule... and PowerCards won't know the difference. EDIT : Meaning you'd need your get statement to return the injury info where you need it, and you'd need the {&mule} statement to pull in the right data table.
1639603079
timmaugh
Forum Champion
API Scripter
OK, got the other problem sorted... 2 things. First, make sure the first line of your Mule doesn't have a space before the 5. In fact, there needs to be no space in a variable name until the "=" that defines what it will evaluate to. In the version I posted earlier, I think I had a space. I'll go correct that post, above. Second, I also found an error in a regex statement in Muler that was preventing the detection of negative return values. I have submitted a fix to the 1-click repository, but that will probably take until next week's merge for it to commit. If you want to get it sooner than that, you can get it from my personal repo  and copy it in manually. Once you have that in, your negative-value variables should evaluate correctly.
It's ok for the space before the 5and I can wait until next week for the one click, for the moment I'm only testing in a "test game" before I put this solution in my real game :)  Thank you !
I tried to include PC to the launch macro but, another fail for me (I'm really not a good coder !!!) I'd like something like that : !power {{ --bgcolor|#000000 --txcolor|##ffffff -- erowbg|#000000 -- orowbg|#000000 --erowtx|#ffffff --orowtx|#ffffff --name|Blessure Grave !&{template:default}{{name=Blessure Grave}} [[1d100 + ?{Modifier}]] {{Result =Jet $[[0]]%NEWLINE%get.MuleBoy.InjuryTable.$[[0]].value/get}}{& mule MuleBoy.InjuryTable}{&simple} }} But my synthax is obviously uncorrect...
1639664915
timmaugh
Forum Champion
API Scripter
First, the space around the variable "5" in the InjuryTable absolutely matters -- otherwise Muler won't see it as a variable it can retrieve, and numbers at or below 5 won't return a value. There can be no space prior to the assignment operator (the "=" sign that sets the left equal to the right). That means all of this must run together: <=5= I have updated the table example, above. Second, I'm not as fluent in the PowerCards syntax, so this might still need some work. I can't get the inline-roll formatting (so players can hover over the roll and see the component parts) unless I let PowerCards construct the roll, but the Muler constructs (getting the variable) need to access a roll created by the Roll20 parser. So in order to get the text in the below example, I have to let Roll20 handle the roll, which apparently ruins the ability of PowerCards to render a rolltip. Someone else might be able to help with that part, or you might try investigating ScriptCards, which is a script heir to the PowerCards legacy (which also delivers on the original promise of what PowerCards could have been). In any case, here is how you could use the Muler constructs in a PowerCards macro: !power {{ --bgcolor|#000000 --txcolor|##ffffff --erowbg|#000000 --orowbg|#000000 --erowtx|#ffffff --orowtx|#ffffff --name|Blessure Grave --Jet: [[1d100 + ?{Modificateur} ]] ^^get.MuleBoy.InjuryTable.$[[0]].value/get }}{& mule MuleBoy.InjuryTable}
And is it possible to put specific colors or texts format using only your API without Powercard ?
1639667801
timmaugh
Forum Champion
API Scripter
Not in the way you would want to customize and format various parts. The metascript toolbox (ZeroFrame, SelectManager, Plugger, Muler, APILogic, MathOps,etc.) gives one more level of information retrieval that you can use for other messages. Typically you have Roll20 retrieval (things like @{selected...} or @{target...} or @{character name...}), and then you have processes hard-coded into a script. That is the order they go in. Metascripts get in the middle of that*. Where most scripts want to own the message (you are sending a message to PowerCards; or you are sending a message to TokenMod; or you are sending a message to ChatSetAttr, etc.), metascripts give you the opportunity to detect particular requests within the text of the message. Since they run before the destination script (e.g., running before PowerCards), they alter the command line that PC will ultimately see. That's why your PowerCard can get quite simple - by the time it sees the command line for any particular message, Muler will have changed it to provide the extra text content. The metascript toolbox can provide these line-changes to almost any script*, or they can be used to retrieve information that is ultimately just output to chat directly, using built in Roll20 constructs (if you have ZeroFrame installed). That's what I was doing using the default template in my example. That template is available in any game no matter what system you are running, but you could change it to be a particular template from a particular character sheet. Those other templates will have other formatting. If you want to use those, you'd start with an exclamation point (to trigger the API), then continue with the message content as you would want it to appear in chat (using a roll template, for example), before ultimately including a {&simple} tag. (You'll see this tag in my example). That ultimately tells ZeroFrame to output the message content -- in whatever state it's been left -- at the end of the metascript processing (instead of letting it pass on to other scripts). That lets us use metascript constructs (like retrieving variables from a mule) in messages we only intend to hit the chat (instead of another script). So you CAN use the metascript constructs in different outputs that already have formatting (roll templates), or you can use them in other scripts that give you a more granular control over the look of the message. That's where I was suggesting ScriptCards, as I have not noticed the problem I was running into (where PowerCards wouldn't provide a tooltip for a roll you let Roll20 parse). You can look at the thread on working ScriptCard examples or the wiki examples to see some of the formatting you can achieve with those. * - one caveat about when metascripts work is that they don't HAVE to be installed prior to other scripts, for the most part . They use a trick to get themselves to the head of the queue of scripts waiting to handle any message. This works for 99% of scripts. PowerCards can be one that doesn't play nicely with metascripts. Completely by chance, it happens to use the same trick to get itself to the head of the queue; so if it happens to be installed first (and therefore processed first when your sandbox boots up), it will get in line BEFORE the metascripts. This can be corrected by removing and re-adding PowerCards after you have the metascripts in place, or by editing a line of the code of the script. I am reaching out to Kurt to see if he can submit a change to PowerCards to make it work with the metascript toolbox regardless of the installation order. For now, you may need to perform the remove-and-reinstall trick to get the order correct.
ok, no problem, I take your first solution without customization, that will be ok and I'm sure that it works ! :) Thank you !