This is a rather complex macro that will roll initiative for a group of tokens selected using a popular game system's rules. Specifically, the rules are:
The code for this is below:
[h: initList = "booga=-1"];[h, foreach(Selected, getSelected("json")), CODE:{ [h: switchToken(Selected)] [h: SelectedGMName = getTokenImage()] [h: arr = json.fromStrProp(initList)] [h,if(json.contains(arr, SelectedGMName) != 0), CODE: { [h: init = json.get(arr, SelectedGMName)]};
{ [h:result = 1d20] [h:init = result + getProperty("Initiative", Selected)] [h:tie = getProperty("Initiative", Selected) / 100] [h:init = init + tie] [h: initList = concat(initList, ";", SelectedGMName, "=", init)] };] [h: switchToken(Selected)] [h: addToInitiative()] [h: setInitiative(init)]}]
[h: sortInitiative()][h,foreach(Selected, getSelected("json")), CODE:{ [h: switchToken(Selected)] [h:init = getInitiative()] [h:init = floor(init)] [h: setInitiative(init)]}]
[h:abort(0)]The result is that if you have a party of 4 PCs all with different token images, and a group of 4 skeletons with the same token image, and 2 zombies with the same token image, which would be typical, and you select all the tokens and run this macro, your initiative list will be populated with all the tokens. The 4 skeletons will all have the same initiative result. The 2 zombies will both have the same initiative result. If there are any ties, tokens with the higher initiative bonus will be presented first.