Saving you a Click. I have posted the working version at the top of this post here. I have kept the rest of the post in tact so you may read if you like. I'll save everyone a scroll. I have my updated macro right here. It's working as it is. It relies on a character attribute called "NumberOfVillagers" to be on the character named "Mob of Villagers". If you want to implement this in your own games, just change those to be whatever you'd like. You'll also need a rollable table with a number of sides equal to the number of members of your mob/swarm/etc. The Mob of Villagers in my game has 96 health and every 4 health represents 1 villager (for a total of 24 villagers). !token-mod {{ --set bar3_value|[[@{selected|bar3}-[[{?{How much damage?},@{selected|bar3}}kl1]]]] width|[[[[{[[([[[[[[@{selected|bar3}-[[{?{How much damage?},@{selected|bar3}}kl1]]]]/@{selected|bar3|max}]]-0.0001]])d1]],[[{[[(1d[[[[@{selected|bar3}-[[{?{How much damage?},@{selected|bar3}}kl1]]]]]])-4]],0}>1]],1}>1]]*70]] height|[[[[{[[([[[[[[@{selected|bar3}-[[{?{How much damage?},@{selected|bar3}}kl1]]]]/@{selected|bar3|max}]]-0.0001]])d1]],[[{[[(1d[[[[@{selected|bar3}-[[{?{How much damage?},@{selected|bar3}}kl1]]]]]])-4]],0}>1]],1}>1]]*70]] currentside|[[{[[@{selected|NumberOfVillagers|Max}-[[floor((@{selected|bar3|max}-[[@{selected|bar3}-[[{?{How much damage?},@{selected|bar3}}kl1]]]])/4)]]]],[[0d0]]}kh1]] --order toback }} !setattr --name Mob of Villagers --NumberOfVillagers|[[{[[@{selected|NumberOfVillagers|Max} - [[floor((@{selected|bar3|max}-[[@{selected|bar3}-[[{?{How much damage?},@{selected|bar3}}kl1]]]])/4)]]]],[[0d0]]}kh1]] /desc The Mob of Villagers took [[{?{How much damage?},@{selected|bar3}}kl1]] damage. [[{[[[[floor((@{selected|bar3|max}-[[@{selected|bar3}-[[{?{How much damage?},@{selected|bar3}}kl1]]]])/4)]]-[[@{selected|NumberOfVillagers|max}-@{selected|NumberOfVillagers}]]]],0}kh1]] of them were killed. The mob now has [[{[[@{selected|NumberOfVillagers|Max}-floor((@{selected|bar3|max}-@{selected|bar3})/4)]],[[0d0]]}kh1]] villagers left. Tl;dr: I made a macro that applies damage to a swarm enemy, killing some number of the individuals in the swarm per x HP. The macro to apply the damage and calculate the new swarm size isn't working because (I think) Token-Mod isn't finished updating the HP value by the time ChatSetAttr is attempting to update the swarm size. I'm not sure how to fix this. Additionally, I wrote some cool stuff to change the size of the token of the swarm and I also want to update which sheet the token represents based on the size of the swarm... but I have some questions. I am working to help my DM make a macro for swarms. (In this case, it's a mob of angry villagers, but that's besides the point.) The premise is simple enough. There are 25 angry villagers in a mob. Each villager has 4 hit points. Each time the mob of angry villagers is attacked, I want to figure out how many villagers are left in the mob. I have a rollable table with a number of sides equal to the maximum number of angry villagers and each element of the table has a token with a number displaying the number of surviving angry villagers. I want to use token mod to set the token side equal to the correct number of villagers. To help deal with numbers that aren't multiples of 4, I have created an attribute on the Mob of Villagers sheet that shows the number of villagers. @{Mob of Villagers|NumberOfVillagers} refers to the current number of survivors. @{Mob of Villagers|NumberOfVillagers|Max} refers to the max number of villagers in the mob. To accomplish this, I wrote a macro using ChatSetAttr and Token-Mod together. Because I'm a dev and I can't stand uncommented code, I'll be "commenting" the code below to clarify its function using "//" followed by a number that references the comments below the macro section (this looks easier to read this way). !token-mod {{
--set
// [1]
bar3_value|[[@{selected|bar3} -[[{?{How much damage?}, @{selected|bar3}}kl1]]
--report
// [2]
all|"/desc The {name} took [[{?{How much damage?}, @{selected|bar3}}kl1]] damage and [[{ [[ [[floor((@{selected|bar3|max} - @{selected|bar3}) / 4)]] - [[@{selected|NumberOfVillagers|max} - @{selected|NumberOfVillagers}]] ]], 0}kh1]] of them were killed. The mob now has [[{[[@{selected|NumberOfVillagers} - floor((@{selected|bar3|max} - @{selected|bar3}) / 4)]], [[0d0]]}kh1]] villagers left."
}}
// [3]
!setattr --name Mob of Villagers --silent --NumberOfVillagers|[[{[[@{selected|NumberOfVillagers|Max} - floor((@{selected|bar3|max} - @{selected|bar3}) / 4)]], [[0d0]]}kh1]]
// [4]
!token-mod --set currentside|@{selected|NumberOfVillagers}
}} [1] I am applying damage here. I want to set the current health equal to the mob's current health, minus the damage they're about to take. The maximum damage the mob can take is its current hit points. [2] I want to post to chat the amount of damage these villagers took, how many were killed, and how many remain. The maximum damage the mob can take is equal to their remaining hitpoints. [3] Here, I want to update the number of villagers into the NumberOfVillagers attribute on their character sheet. I will reference this number to see how many villagers have been killed so far. This is supposed to help me keep track of the number of remaining villagers. It also avoids situations where player 1 deals 9 damage, killing 2 villagers with a remainder of 3 damage. Player 2 deals 8 damage, killing 2 villagers, still holding a remainder of 3 damage. Then player 3 deals 3 damage, killing the 1 with the remainder (even though each villager has 4 hitpoints). To do this, I am taking the max number of villagers and I am subtracting the total number of villagers that the players have killed so far. To get this, I take the total number of villagers and subtract their current health, divided by 4, rounded down. [4] Now that I have updated the NumberOfVillagers in the Attributes section, I want to use that number to determine which token "side" I want from my rollable table. The number here should be the same number as the number of living villagers. Alright, so here's my problem. When I run the macro I posted above here's what happens. First, it prompts me to ask how much damage the Mob of Villagers has taken. I'll apply 9 damage to my mob here. Next, it correctly applies the damage to the token and reports the information... incorrectly. It shows that 0 of the villagers were killed and that the mob has 24 villagers left. (The Mob of Villagers "3" is just a numbered tokens thing.) Additionally, the Attribute NumberOfVillagers has not been updated and it remains at 24/24. At this point, any of the macros I call now will correctly work. I can go ahead and type my ChatSetAttr command and it will correctly function now. After I call that, individually, I can call the Token-Mod set current side macro and it will work. So why can't I call these together? From what I understand, Roll20 parses and executes macros line by line until they are completed. But it looks like the bar3 value is taking too long to update, so by the time Roll20 has submitted the line of code for execution, the ChatSetAttr line is being submitted. At the time that it's sent, damage hasn't been applied yet so it can't update the NumberOfVillagers attribute. Because I can't assign that value, by the time I'm reaching the next macro, the value is still just "24". That's at least my interpretation of it. But Since You're Here... Can I get a second opinion on this macro? And while you're here. Is there a better way to handle this? Ideally, I wanted to even change the "Represents Character" field to change from the Mob of Villagers, to a Group of Villagers at 12 members and at 1 member I'd want it to change to a single villager. I can do the macrowork manually, but that defeats the fun of automating stuff. Like, I can make a button that the DM presses at the health thresholds, but... yuck. Most of the reason for macro work is to automate cool stuff. !token-mod {{ --set currentside|@{Mob of Villagers|NumberOfVillagers} width|[[ [[ { [[ ( [[ [[ @{selected|bar3} / @{selected|bar3|max} ]] - 0.0001 ]] )d1 ]], [[ { [[ 1d [[ @{selected|bar3} ]] - 4]], 0 } > 1 ]], 1 } > 1 ]] * 70]] height|[[ [[ { [[ ( [[ [[ @{selected|bar3} / @{selected|bar3|max} ]] - 0.0001 ]] )d1 ]], [[ { [[ 1d [[ @{selected|bar3} ]] - 4]], 0 } > 1 ]], 1 } > 1 ]] * 70]] --order toback }} This took some work, but the above macro should try to see if the swarm/mob meets 3 conditions. 1) If you divide its current hp by its max hp and you subtract a TINY bit, and you roll THAT many dice, it should roll a 1 if you are above half health. It will roll a 0 if you are below. 2) If you subtract 4 from your current health (the amount of health for each member of the mob), you should be left with a number of mobs greater than 0. If this is true, you roll a 1, if it is false you roll a 0. 3) Free Space Since I needed my mob to be huge, I can multiply my token's height and width by that equation * 70 to reach 210, which is giant sized. And when they're at half their strength, they are large. When they are down to 4 health or less, it's just the 1 dude. It's no longer a mob. Also, it sends it all to back, since no one wants to cover their players' beautiful, shining faces as they are mauled and engulfed in the endless flesh fiesta of your swarm. I've tried creating a character with token actions called "1", "2", and "3" so that I could use the return value from that macro above to call his token actions to call a macro snippet like !token-mod --set represents|@{Mob of Villagers|character_id} But predictably, they don't allow you to call a token action with something like %{CharacterName|AwesomeMacro[[X]]}. Nor do they allow the [[math]] in macros or character references (or whatever the @{stuff} is called}. You also can't use an element from a rollable table like @{CharacterName|AwesomeMacro[[1t[Wow]]]}. And yet, I still want to believe that there's a way to change the "Represents Character"... It's quickly becoming my white whale.