Universal Attack Macro

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
blakdeth19
Cave Troll
Posts: 30
Joined: Sat Jan 03, 2015 11:05 am

Universal Attack Macro

Post by blakdeth19 »

so im creating a macro for maptool to use in my d&d 3.5 game and im trying to get it so i can use it with any npc token.

I have it getlist of all tokens and it gets the AC of the selected token, then revert back to the original token. After that it has selection of weapons, runs the roll against the AC and outputs hit/miss and if so what damage. Then it deals the damage to the enemy token, sets states if needed or removes from initiative when dead.

But when it reverts back i have to use switchtoken(the tokens actual name). so it will always revert back to the same token. is there a way to universally switch back to the token who called the macro?

Akodo Makama
Giant
Posts: 249
Joined: Mon Apr 20, 2009 9:31 pm

Re: Universal Attack Macro

Post by Akodo Makama »

If you use token IDs, you should be able to do everything without ever switching the active token. There would then be no need to 'revert' to the original.

Something like:

Code: Select all

[listOfSelectedTokens = getSelected()]
[foreach(id, listOfSelectedTokens, "<br>"), code:
{  [targetAC = getProperty("AC", id)]
   [attackRoll = 1d20]
   [hitMiss = if(attackRoll + attackMods >= target AC]
   [if(hitMiss), code:
   {  "You Hit" [getName(id)]
      [targetHP = getProperty("HP", id]
      [targetHP = targetHP - damage]
      [SetProperty("HP", targetHP, id]
   };{"You Missed" [getName(id)]}]
}] 

blakdeth19
Cave Troll
Posts: 30
Joined: Sat Jan 03, 2015 11:05 am

Re: Universal Attack Macro

Post by blakdeth19 »

I tried setting this just after the getlist
When using this i get stack overflow. i even took the macro to 1/3 its size and it still says overflow...

blakdeth19
Cave Troll
Posts: 30
Joined: Sat Jan 03, 2015 11:05 am

Re: Universal Attack Macro

Post by blakdeth19 »

and when i run just
[listOfSelectedTokens = getSelected()]
[foreach(id, listOfSelectedTokens, "<br>"), code:
{ [targetAC = getProperty("AC", id)]
after getlist it returns only the id of the token running the macro, no the one selected from the getlist

blakdeth19
Cave Troll
Posts: 30
Joined: Sat Jan 03, 2015 11:05 am

Re: Universal Attack Macro

Post by blakdeth19 »

I figured it out. i was running an extra macro in my script i didnt need to change the token before i got its ac
just had to remove it and put this. thanks tho!

[h:targetName = listGet(tokenList,Target)]
[r: getProperty("AC", targetName)]

Akodo Makama
Giant
Posts: 249
Joined: Mon Apr 20, 2009 9:31 pm

Re: Universal Attack Macro

Post by Akodo Makama »

The original post contained code not intended to be actually run, but to show what functions to use. It contained a couple typos (missing paranthesis) that would cause errors. The following code is complete and runs properly, but contains no error checking for things like:
no tokens are selected when macro is run
target token has no AC property or no value for AC
target token has no HP property or no value for HP

Code: Select all

[listOfSelectedTokens = getSelected()]
[foreach(id, listOfSelectedTokens), code:{
   <p>
   Attacking [getName(id)]
   [damage = 1d4]
   [attackRoll = 1d20]
   [targetAC = getProperty("AC", id)]
   [hitMiss = if(attackRoll >= targetAC,1,0)]
   [if(hitMiss == 1), code:{
      You Hit
      [targetHP = getProperty("HP", id)]
      [targetHP = targetHP - damage]
      [setProperty("HP", targetHP, id)]
   };{
      You Missed
   }]
}]
 

Post Reply

Return to “Macros”