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)]
};{}]
}]
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",";")]
This is more for the people writing code for others to use to make life simpler for those non-programmers out there.