Roll Initiative: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
No edit summary
m (Taustin moved page roll Initiative to Roll Initiative without leaving a redirect)
 
(2 intermediate revisions by 2 users not shown)
Line 9: Line 9:
The code for this is below:
The code for this is below:


<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[h: initList = "booga=-1"];
[h: initList = "booga=-1"];


Line 43: Line 43:
[setInitiative(init)]
[setInitiative(init)]
}]
}]
</source>
</syntaxhighlight>


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.
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.

Latest revision as of 17:51, 3 May 2023

Roll Initiative

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:

  • each token rolls 1d20 and adds a bonus (stored in the Initiative Property).
  • ties go to the token with the higher bonus.
  • groups of monsters all use the same roll -- or as implemented, tokens with the same image share the same roll.

The code for this is below:

[h: initList = "booga=-1"];

[h, foreach(Selected, getSelected("json")), CODE:
{
	[switchToken(Selected)]
	[SelectedGMName = getTokenImage()]
	[arr = json.fromStrProp(initList)]
	[if(json.contains(arr, SelectedGMName) != 0), CODE:
	{
		[init = json.get(arr, SelectedGMName)]
	};
	{
		[result = 1d20]
		[init = result + getProperty("Initiative", Selected)]
		[tie = getProperty("Initiative", Selected) / 100]
		[init = init + tie]
		[initList = concat(initList, ";", SelectedGMName, "=", init)]
	}]

	[switchToken(Selected)]
	[addToInitiative()]
	[setInitiative(init)]
}]

[h: sortInitiative()]

[h,foreach(Selected, getSelected("json")), CODE:
{
	[switchToken(Selected)]
	[init = getInitiative()]
	[init = floor(init)]
	[setInitiative(init)]
}]

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.