So, I found a very interesting set of code for adding enemies to the initiative. Huzza! Unfortunately it pulls up EVERY SINGLE NPC TOKEN ON THE MAP. Do we have two people we're escorting? Initiative. Got some objects? Initiative. Forgot to delete one token that's out way off from where everyone is? INITIATIVE!
[spoiler=Macro code]/self Added [R:addAllNPCsToInitiative()] NPCs to initiative. Updating position in initiative...
[h:args=json.set("","npc",1)] [h:NPCsList = getTokens("json",args)]
[H,FOR (x,0,json.length(NPCsList),1,""), CODE:{
[H:switchToken(json.get(NPCsList,x))]
[h:Label = getTokenImage()]
[h:status=input(
"junk|"+getTokenImage()+"|"+ getName() + "|LABEL| ICON=TRUE ICONSIZE=30",
"Initiative|0|Initiative Bonus"
)]
[h:setInitiative(1d20+Initiative)]
}]
[h:sortInitiative()][/spoiler]
Can anyone give me some tips on how to edit this to only work for the SELECTED tokens? I tried to look through the site but, what I saw didn't work, and I'm sure I'm just missing something that's probably, blindingly obvious.
Setting a macro to only use selected tokens?
Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice
- Bone White
- Great Wyrm
- Posts: 1124
- Joined: Tue Aug 23, 2011 11:41 am
- Location: Cornwall, UK
Re: Setting a macro to only use selected tokens?
Code: Select all
/self Added [R:addAllNPCsToInitiative()] NPCs to initiative. Updating position in initiative...
[h:args=json.set("","npc",1)]
[h:NPCsList = getTokens("json",args)]
[H,FOR (x,0,json.length(NPCsList),1,""), CODE:{
[H:switchToken(json.get(NPCsList,x))]
[h:Label = getTokenImage()]
[h:status=input(
"junk|"+getTokenImage()+"|"+ getName() + "|LABEL| ICON=TRUE ICONSIZE=30",
"Initiative|0|Initiative Bonus"
)]
[h:setInitiative(1d20+Initiative)]
}]
[h:sortInitiative()]
I indented your code to make it much easier to read. You want to be altering [wfunc]getTokens[/wfunc] So change the second line from.
[h:args=json.set("","npc",1)]
to
[h:args=json.set("","npc",1,"selected",1)]
Untested, but should work.
Re: Setting a macro to only use selected tokens?
That ALMOST worked! It did roll only the initiative for the selected enemies, but still added all of them. That seems to be an issue with the top line:
This still adds every NPC on the map. Which, for now, works, since we're setting things up one encounter at a time, but there's a dungeon crawl coming up down the line which I intend to have set up ahead of time, and I'd rather not end up with 10-15 encounters' worth of bad guys as blanks in the initiative list!
I tried swapping it to "addToInitiative()" instead, but that's giving me errors.
Code: Select all
/self Added [R:addAllNPCsToInitiative()] NPCs to initiative. Updating position in initiative...
This still adds every NPC on the map. Which, for now, works, since we're setting things up one encounter at a time, but there's a dungeon crawl coming up down the line which I intend to have set up ahead of time, and I'd rather not end up with 10-15 encounters' worth of bad guys as blanks in the initiative list!
I tried swapping it to "addToInitiative()" instead, but that's giving me errors.
Re: Setting a macro to only use selected tokens?
Chazz wrote:That ALMOST worked! It did roll only the initiative for the selected enemies, but still added all of them. That seems to be an issue with the top line:Code: Select all
/self Added [R:addAllNPCsToInitiative()] NPCs to initiative. Updating position in initiative...
This still adds every NPC on the map. Which, for now, works, since we're setting things up one encounter at a time, but there's a dungeon crawl coming up down the line which I intend to have set up ahead of time, and I'd rather not end up with 10-15 encounters' worth of bad guys as blanks in the initiative list!
I tried swapping it to "addToInitiative()" instead, but that's giving me errors.
maybe you should read [wfunc]addToInitiative[/wfunc] first. The 'current token' can be set with [wfunc]switchToken[/wfunc] (which is already in the code) the only thing left now is a for loop to add them one by one... (which you already have in the current code!)
GETTING STARTED WITH MAPTOOLS - TUTORIALS, DOCS, VIDEOS, TOOLS, ETC
DISCORD (the new MT forum!)
My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent.
Frameworks: Dark Heresy, Rogue Trader, Deathwatch, Black Crusade, Only War, SET Card Game, RoboRally
Wiki: Debugging Tutorial, Speed Up Your Macros, Working With Two CODE Levels, Shortcut Keys, Avoiding Stack Overflow, READ THIS
DISCORD (the new MT forum!)
My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent.
Frameworks: Dark Heresy, Rogue Trader, Deathwatch, Black Crusade, Only War, SET Card Game, RoboRally
Wiki: Debugging Tutorial, Speed Up Your Macros, Working With Two CODE Levels, Shortcut Keys, Avoiding Stack Overflow, READ THIS