Roll Initiative: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
(A macro to roll initiative for a group of selected tokens according to the rules of a popular game system.)
 
m (Taustin moved page roll Initiative to Roll Initiative without leaving a redirect)
 
(6 intermediate revisions by 4 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"];


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


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


Line 38: Line 38:
[h,foreach(Selected, getSelected("json")), CODE:
[h,foreach(Selected, getSelected("json")), CODE:
{
{
[h: switchToken(Selected)]
[switchToken(Selected)]
[h:init = getInitiative()]
[init = getInitiative()]
[h:init = floor(init)]
[init = floor(init)]
[h: setInitiative(init)]
[setInitiative(init)]
}]
}]
 
</syntaxhighlight>
[h:abort(0)]
</source>


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 23:59, 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.