Setting a macro to only use selected tokens?

Discuss macro implementations, ask for macro help (to share your creations, see User Creations, probably either Campaign Frameworks or Drop-in Resources).

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

Post Reply
Chazz
Kobold
Posts: 9
Joined: Tue Apr 05, 2011 11:11 pm

Setting a macro to only use selected tokens?

Post by Chazz »

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!
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()]
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.

User avatar
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?

Post by Bone White »

[code=php]/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()] [/code]


I indented your code to make it much easier to read. You want to be altering Wiki: getTokens() 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.

Chazz
Kobold
Posts: 9
Joined: Tue Apr 05, 2011 11:11 pm

Re: Setting a macro to only use selected tokens?

Post by Chazz »

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.

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Setting a macro to only use selected tokens?

Post by wolph42 »

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 Wiki: addToInitiative() first. The 'current token' can be set with Wiki: switchToken() (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!)

Post Reply

Return to “Macros”