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

Roll on Appropriate DCC Critical Table

What am I missing here to identify the selected character/token? !script {{ --#title|MonsterCrits --#sourceToken|@{selected|token_id} --&CritType=|@{selected|character_id}|CritDie_max --&CritDie=|@{{selected|character_id}|CritDie} --?"[$CritType]" -inc "I"|[ --+Result|get.table.CRTI.[[$CritDie]].value/get {&simple} --]|[ --?"[$CritType]" -inc "II"|[ --+Result|get.table.CRTII.[[$CritDie]].value/get {&simple} --]|[ --?"[$CritType]" -inc "III"|[ --+Result|get.table.CRTIII.[[$CritDie]].value/get {&simple} --]|[ --?"[$CritType]" -inc "IV"|[ --+Result|get.table.CRTIV.[[$CritDie]].value/get {&simple} --]|[ --?"[$CritType]" -inc "V"|[ --+Result|get.table.CRTV.[[$CritDie]].value/get {&simple} --]|[ --?"[$CritType]" -inc "DR"|[ --+Result|get.table.CRTDR.[[$CritDie]].value/get {&simple} --]|[ --?"[$CritType]" -inc "DN"|[ --+Result|get.table.CRTDN.[[$CritDie]].value/get {&simple} --]|[ --?"[$CritType]" -inc "G"|[ --+Result|get.table.CRTG.[[$CritDie]].value/get {&simple} --]|[ --?"[$CritType]" -inc "U"|[ --+Result|get.table.CRTU.[[$CritDie]].value/get {&simple} --]|[ --?"[$CritType]" -inc "M"|[ --+Result|get.table.CRTM.[[$CritDie]].value/get {&simple} --]| }}
1712633845

Edited 1712673598
So I think you are mixing up String variables --& and Roll variables here. You are are declaring two string variables with --& but then you are adding an equal on the end = and then in your conditionals you reference a roll variable [$CritType]. I see you are setting the --#sourceToken| parameter so you can also use the [*S: to reference your attributes. so those lines could look like: --&CritType|[*S:CritDie^] --&CritDie|[*S:CritDie] Note the caret symbol ^ to get the max property of an attribute. _max isn't the correct syntax outside of token properties like bar1_max. Which the references in your condtional would all become: [&CritType] instead of the roll variable [$CritType] which you never declared. Declaring a roll variable named CritType would look like: --=CritType| Also I don't think you can string if/else code blocks together like that. You aren't closing the code blocks and currently as of writing you cannot nest code blocks. Your conditionals also saying if the string includes, so --?"[&CritType]" -inc "I" is going to match if CritType is I, II, III, or IV. I don't know what your CritDie max property holds but your conditonals are going to match. Like if you had III, it would match on I, II, and III and try to display results for all of them. If the CritDie max property just holds the letters as you are checking for exactly then your ScriptCard could look like this: !scriptcard {{ --#title|MonsterCrits --#sourceToken|@{selected|token_id} --&CritType=|[*S:CritDie^] --&CritDie=|[*S:CritDie] --&tableName|CRT[&CritType] --+Result|get.table.[&tableName].[[&CritDie]].value/get {&simple} }} I cannot speak to the Meta-Script stuff you are doing in your display but the if the CritDie max property is equal to the suffix used at the end of your CRT tables, you could simplify it down to that. I am unsure about using MetaScripts inline like that. Typically ScriptCards would require --@ to call to another mod but perhaps that works for you. I've just never used that syntax so I cannot say. I've only used  ScriptCards native way of rolling on tables  or using a built-in function to access table data which would look like this: !scriptcard {{ --#title|MonsterCrits --#sourceToken|@{selected|token_id} --&CritType=|[*S:CritDie^] --&CritDie=|[*S:CritDie] --&tableName|CRT[&CritType] --~|array;fromtable;CritResultArray;[&tableName];name --+Result|[@CritResultArray([= [&CritDie] - 1 ])] }} Without knowing the specifics of your setup, especially the values in your CritDie attribute both current and max, that would look a monster's CritDie and CritDie_max and use the max as a suffix to pull from the appropriate rollable table an array of values. It would then use the value in CritDie attribute to lookup that entry. So for example if a monster had a CritDie max of II, it would pull all entries into an array from the table CRTII. If the monster then had a CritDie of 12, it would then lookup the 12th entry in the array. Note that [= [&CritDie] - 1] is doing some inline math since ScriptCard arrays are 0 based so the first entry is 0. Granted this is making a lot of assumptions about your setup so it is probably way off from what you are looking for exactly but maybe it can provide a starting point for you. If not, feel free to respond with examples of your setup and folks can help you get a working ScriptCard. EDIT: Figure I should also include an example of a ScriptCard rolling on a table just in case that is useful: !scriptcard {{ --#title|MonsterCrits --#sourceToken|@{selected|token_id} --&CritType=|[*S:CritDie^] --&CritDie=|[*S:CritDie] --&tableName|CRT[&CritType] --=TableRoll|[#T[&tableName]] --+Result|[$TableRoll.tableEntryText] }} EDIT2: Just striking out the bad example above based on timmaugh's answer. Leaving the ScriptCards examples that don't use the MetaScript options in them.
1712668897

Edited 1712681586
timmaugh
Pro
API Scripter
I had not seen the metascript stuff in the original question, so let me quickly add a little clarity, there... 1) The metascripts will run -- and be done running -- before ScriptCards gets the message. That means that you can use ScriptCard-constructions in a metascript construction and expect it to resolve. When the metascripts are working ont he message, the state of the muler construction will look like this: get.table.[&tableName].[[&CritDie]].value/get Muler will specifically look for a table named "[&tableName]", and not find it. By the time ScriptCards expands that variable so that it would properly reference the table, Muler's chance to operate here will have passed. 2) The {&simple} tag in the command line will prevent the message from ever reaching ScriptCards. {&simple} tells the metascripts to dump the message out to chat at the end of the metascript processing, before any other standard script (like ScriptCards) has a chance at the message. If you leave {&simple} in the message, then at the end of the metascript processing you would see the command line output to chat (rather than a card that was the result of ScriptCard work). MetaScript Method You can use the ScriptCards method for table-item-retrieval (that Joshua shared, above), or you can get the item via metascripts. If you are going to do it via metascripts, you have to do all of the component parts via metascript construction (like Fetch + Muler). Like #1 says, above, the metascript parts have to be done before ScriptCards gets involved. I think that would make a metascript-powered ScriptCard look more like: !scriptcard {{     --#title|MonsterCrits     --+Result|get\.table.CRT@(selected.CritDie.max).[\][\]@(selected.CritDie)\]\].value/get }} The order of important elements in the above (between inline roll resolution, Fetch construction resolution, and Muler construction resolution) would go: Inline Roll (Roll20) Muler Fetch Both the inline roll and the Muler construction are dependent on the Fetch construction, so both of them have to be deferred. Then we consider that the Muler construction is dependent on the inline roll resolution, but that should work out because roll resolution happens before the metascripts in each loop. (Provided I have understood what you were trying to do in the original ScriptCard, then the above should work...)
When I run this !scriptcard {{     --#title|MonsterCrits     --+Result|get\.table.CRT@(selected.CritDie.max).[\][\]@(selected.CritDie)\]\].value/get {&simple} }} It prints: scriptcard {{ --#title|MonsterCrits --+ Result|Powerful strike hammers foe to their knees. Make another attack. }} How do I get it to just print the result in a scriptcard?
1712677624

Edited 1712681649
timmaugh
Pro
API Scripter
That's what I was saying about the {&simple} tag. Only use that tag if you want to PREEMPT further processing by other scripts. Since you want ScriptCards to process the result of the metascript operations, you have to remove that tag to let the message proceed to standard scripts. You would use a {&simple} tag to do something like this: !I'm just checking the value of get\.table.CRT@(selected.CritDie.max).[\][\]@(selected.CritDie)\]\].value/get {&simple} Then it would output that simple sentence with the result of the muler/fetch work. Or if you were wanting to output the result in a roll template, you would need the {&simple}: !&{template:default}{{name=Proof of concept}}{{Result=get\.table.CRT@(selected.CritDie.max).[\][\]@(selected.CritDie)\]\].value/get }} {&simple} That would output the result of the muler/fetch operations in the default template -- because that bypasses all other scripts. You want ScriptCards to handle the output (after it does it's own processing), so you want to REMOVE the {&simple} tag. EDIT : And, mea culpa for leaving that in the example, above. I was cutting and pasting willy-nilly and missed that I had included the {&simple} tag. That's my fault. I have removed it from the example in the previous post.
While it's not as concise as that 1 liner with the MetaScript, here is a ScriptCards version of rolling a die and fetching that item from a table: !scriptcard {{ --#title|MonsterCrits --#sourceToken|@{selected|token_id} --&CritType|[*S:CritDie^] --=CritDie|[*S:CritDie] --&tableName|CRT[&CritType] --~|array;fromtable;CritResultArray;[&tableName];name --+Rolled|[$CritDie] --+Result|[@CritResultArray([= [$CritDie.Raw] - 1 ])] }} This does assume that CritDie value is something like 1d4, 1d8, 1d12, etc. I don't know the MetaScripts well enough to speak on why they are printing the scriptcard instead of sending it.
Thank you all.
New wrinkle: How do I adjust this to prompt for CritType and CritDie? !&{template:default}{{name=Proof of concept}}{{Result=get\.table.CRT@(selected.CritDie.max).[\][\]@(selected.CritDie)\]\].value/get }} {&simple}
1712689305
timmaugh
Pro
API Scripter
Well, as for where you would put a query... since queries run before the message reaches the metascripts, and metascripts run before the message reaches standard scripts (or gets output to chat), you can interrupt metascript constructions so long as what you leave behind (after the query processes) would leave you a valid metascript construction. For instance, if you had 3 attributes: attrA, attrB, and attrC... ...and you wanted to use a query to pull one of them, you can put that query within a Fetch construction: @(selected.attrNameGoesHere) If the query was: ?{Pick attribute|attrA|attrB|attrC} ...then that would leave attribute names behind after you made your selection, so you could have that within the Fetch construction like so: @(selected. ?{Pick attribute|attrA|attrB|attrC}) And as for what you would put in the query... it seemed to me that the "CritDie" and the "CritType" were just coming from the same attribute, except one was pointed at the max value. I might have misunderstood, but if that's accurate, then you can rereference the same query (that returns the name of the attribute), in another Fetch construction that would retrieve the "max" part of the same attribute: @(selected.?{Pick attribute}.max) Beyond that, you'd have to share more about what the numbers mean and where they're stored on your sheet. I'm not a DnD player if that's the system you're using, so I don't always pick up on contextual clues of specific gameplay rules.
What I'm looking for is, since I'm using TokenNameNumber to create multiple enemies, I set them to not be linked to the character sheet for the monster. As such, those tokens don't have access to the CritType and CritDie fields, so I want to prompt for those and then perform the same table lookup.
Joab said: What I'm looking for is, since I'm using TokenNameNumber to create multiple enemies, I set them to not be linked to the character sheet for the monster. As such, those tokens don't have access to the CritType and CritDie fields, so I want to prompt for those and then perform the same table lookup. Why aren't you linking those creatures to character sheets?  
You CAN link them to a sheet BUT afterwards set the Bar Values in Token Settings to "NONE", effectively unlinking those bars from the sheet while the rest stays connected... Then the Macro posted above might work, too. Joab said: What I'm looking for is, since I'm using TokenNameNumber to create multiple enemies, I set them to not be linked to the character sheet for the monster. As such, those tokens don't have access to the CritType and CritDie fields, so I want to prompt for those and then perform the same table lookup.
I’m not linking the monsters to the character sheet so they don’t share a single pool of hit points
1713016814
timmaugh
Pro
API Scripter
Right... but if you leave the token connected to the sheet (that is, the "represents character" field is still filled) but delink the token bar, then the token will have access to all of the sheet attributes/abilities, but will not share hit points. In this hypothetical, you would not manage damage on the tokens the same way you might for a normal character, where you modify the value of the attribute on the sheet, leaving the "max" value of the attribute as the starting value. Instead, you would decrement the value of the UNLINKED bar. In fact, a lot of premade compendium tokens are built this way... they have a value in Bar1 current and max, but no linkage in the bar to HP. The token still references the sheet, so you can roll attacks (or, in your case, get CritDie or CritType), but the mook tokens don't step on each other:
That works. Thanks.