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

Macro to sum the money value of all selected tokens and report to chat?

For a Persona TTRPG campaign that I'm running, enemies have their loot stored in their inventory and money fields. My party gets money from them all when they win, a random item on a mixed success, and every item on a complete success. Is there a macro to read all selected enemy money fields, sum them, and report to chat how much money they get? Optionally, is there also a macro that can pick one of the selected enemies at random and report their Inventory? A macro that reports the inventory of every enemy? It's safe to assume every enemy only ever has one item.
Wanted to bump this, I haven't made any headway on finding a function to do this on my own and I have no API coding experience at all.
1618245155

Edited 1618245211
Andreas J.
Forum Champion
Sheet Author
Translator
You could do a macro that does something like this(assuming the money sat is named "gold" and you have only 5 party members: &{template:default} {{name=Party total gold}} {{Gold= [[@{target|target1|gold}+@{target|target2|gold}+@{target|target3|gold}+@{target|target4|gold}+@{target|target5|gold} ]] }}   It will require you to target a token representing each character, but if the party's name doesn't change you could do it something like this: &{template:default} {{name=Party total gold}} {{Gold= [[@{Alice|gold}+@{Bob the Green|gold}+@{Charlie|gold}+@{David Goliathsson|gold}+@{Gandalf|gold} ]] }}
It will depend on which character sheet your game is using (I'm guessing Unofficial Persona TTRPG) and what the inventory attributes are. You could probably create a macro to read the static inventory attributes from enemies, one at a time.  A macro won't be able to read from several selected characters at the same time, or to select one at random. But any of that could be done with a custom API script.  I'm not aware of any scripts that have any similar purpose to that currently.
My hope is to have the party defeat between three and five Shadows (each of which has a Money field which is where I store their money dropped on death), select all the defeated shadows, push a button, and have it report the total money gained from the Shadows. Would Andreas J's macro do that?
Andreas' macro was to list out how much gold your players characters have, not the enemies.  You could use it for enemies, but the problem with a macro is it is static and will always target the same number of things (in Andreas' macro case it will always target 5 tokens). You could use Andreas' macro if you had a 'blank' token, in case you had fewer than 5 targets. A custom API could do what you are looking for, but you'd need to get someone to write it or write it yourself. (I don't have enough javascript skill to do so.) A script could be written so you would specify how many targets to use (or select them all at the same time), and automatically sum the total of all their gold, but a macro on its own is not able to do that.
I suppose I could make several macros for between one and six shadows. It might be only slightly more work?
1618334469
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
I haven't had a chance to try it out, but it's possible that SelectManager might be of help. If it can cause each selected token in turn to write its gold value to a "treasure" character in an incrementing fashion using ChatSetAttr, or to a specified token bubble using token-mod. then you could read that totaled field.
Isn't it easier to only generate their Money after they die?
1618344290

Edited 1618398158
David M.
Pro
API Scripter
Scriptcards can do this, although it uses a touch of some advanced syntax to make it happen. The following will sum the values of the attributes "GP", "SP", and "CP" for all selected tokens. !script {{ --#title|Count de Monet! --:(0) INITIALIZE LOOT| --=totalGP|0 --=totalSP|0 --=totalCP|0 --:(1) GET ALL SELECTED TOKENS| --~selectedToks|getselected --:(2) EXTRACT AND SUM THE GP ATTRIBUTE FOR EACH SELECTED TOKEN| --=i|0 --:Loop| --=i|[$i] + 1 --&thisTokID|[&selectedToks[$i.Total]] --=thisGP|[*[&thisTokID]:GP] --=thisSP|[*[&thisTokID]:SP] --=thisCP|[*[&thisTokID]:CP] --+[#990000][*[&thisTokID]:character_name] Loot:[/#]|[b][$thisGP.Total] GP __ [$thisSP.Total] SP __ [$thisCP.Total] CP[/b] --=totalGP|[$totalGP] + [$thisGP] --=totalSP|[$totalSP] + [$thisSP] --=totalCP|[$totalCP] + [$thisCP] --?[$i.Total] -lt [$selectedToksCount.Total]|Loop --:(3) REPORT TOTAL GP| --+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| --+[#990000]Total Loot[/#]|[b][$totalGP.Total] GP __ [$totalSP.Total] SP __ [$totalCP.Total] CP[/b] }} Example output:
1618372947
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
"De mo-NAY! De mo-NAY!"
1618398254
David M.
Pro
API Scripter
Oops! Thanks Keith, I corrected my post above ;)