putMacro() - variant of createMacro()

These are tools and utilities that make it easier to run games. This includes Lib: macro tokens dropped into MapTool to manage the game, a conversion file for CharacterTool to allow use in MapTool, or just about anything else you can think of -- except graphics with macros and anything specific to a particular campaign framework. Those are already covered by the Tilesets subforum and the Links and External Resources forum.

Moderators: dorpond, trevor, Azhrei, giliath, Gamerdude, jay, Mr.Ice

Post Reply
User avatar
aliasmask
RPTools Team
Posts: 9024
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

putMacro() - variant of createMacro()

Post by aliasmask »

If you want to create a macro on a target token, but want to keep the process separate from any other functionality you're running. Here is a bit of code I wrote. It requires two parts, my macro "putMacro" and the macro that calls putMacro with the relevant data. putMacro will sort out the targets selected, check for duplicates and you can even put in your own custom condition that is checked on the selected tokens.

To use. select the library token with putMacro and the creeation macro, hold down the shift key and select the other tokens to put the created macro on. Click the creation macro that calls putMacro and voila, new macros created on all the other tokens with no duplication.
putMacro

Code: Select all

<!-- This should be run on a lib token --->
[h: assert(isTrusted() && !json.isEmpty(macro.args),"<b>putMacro(macroName,macroText,macroProps,delim,condition)</b>",0)]

<!-- Verify all the arguments -->
[h: tNumArgs = json.length(macro.args)]
[h: assert(tNumArgs >= 3,"<b>putMacro(macroName,macroText,macroProps,delim,condition)</b>",0)]
[h: tMacroName = json.get(macro.args,0)]
[h: tMacroText = json.get(macro.args,1)]
[h: tMacroProps = json.get(macro.args,2)]
[h, if(tNumArgs >= 4), code:{
   [h: tType = json.get(macro.args,3)]
   [h: tType = if(tType != "",tType,";")]
};{
   [h: tType = ";"]
}]
[h, if(tNumArgs >= 5), code:{
   [h: tCondition = json.get(macro.args,4)]
};{
   [h: tCondition = 1]
}]

<!-- Get all the selected Tokens. Remove the one running the macro -->
[h: tSelected = getSelected()]
[h: mIds = listDelete(tSelected,listFind(tSelected,currentToken()))]

<!-- Remove ids that already have the macro -->
[h: tIds = mIds]
[h, foreach(tId,mIds), code: {
   [h: tFound = listFind(getMacros(",",tId),tMacroName)]
   [h, if(tFound != -1), code: {
      [h: tIds = listDelete(tIds,listFind(tIds,tId))]
   };{}]
}]   

<!-- Put the macro on the remaining tokens -->
[h, foreach(tId,tIds), code: {
   [h: switchToken(tId)]
   [h: cCondition = eval("tCondition")]
   [h, if(cCondition), code: {
      [h: createMacro(tMacroName,tMacroText,tMacroProps,tType)]
   };{}]
}] 
Example Caller:
Spec Abil Macro

Code: Select all

 [h: putMacro("Spec Abils", "/self [macro('Spec Abil Main@Lib:spells'):'']","autoExecute=true;color=red;fontColor=yellow;group=Spells;sortBy=51",";")] 
In the above case, I made putMacro a User Defined Function in onCampaignLoad

This is more for the people writing code for others to use to make life simpler for those non-programmers out there.


User avatar
Azhrei
Site Admin
Posts: 12086
Joined: Mon Jun 12, 2006 1:20 pm
Location: Tampa, FL

Re: putMacro() - variant of createMacro()

Post by Azhrei »

(Moved to the Drop-In Resources forum under User Creations, but I left a shadow thread in the MapTool > Macros forum.)

Post Reply

Return to “Drop-In Macro Resources”