Macro scripting with multiple actions


Hello, I am interested in macro scripting as it allows for quick actions to be performed without too hassle by the GM, but I am stuck on writing something that works for all token / characters selected in the map.

I would like to write something that goes like this: I place some of my characters in the map, I select some of them and then I run a macro. The macro have to run in the same way for all tokens.

Let’s explain with an example: I have to place 20 monsters in the map and I want every single one of them to have a random HP value. For now I have to select them one by one and for every one run this macro: “@selected.hp = !hroll @selected.hp_formula >> @selected.hp_max = @selected.hp”. This way every one have a random HP value based on his hp dice formula, but this is a time consuming method. I would like to select them all and run a macro once such that, if I have a Zombie (3d8+22) and a Dragon (17d10+85), the zombie will roll 3d8 and add the 22 as his HP and the dragon will roll 17d10 and add the 85.

How can I do that?

I hope that this make sense, ask me what’s not correctly explained.