Simple Auto Targeting Mode [New Lib and Video]

Threads specific to teaching (or step-by-step resources) for writing macros and scripts for use in MapTool.

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

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

Simple Auto Targeting Mode [New Lib and Video]

Post by aliasmask »

Okay, I added a bunch more features and control for targets.
  • Easy target mode activation
  • Distinguish between Allies and Enemy Melee, Range and Magic targets
  • Target unseen tokens (with GMs help)
  • Lock targets so they can't be changed
  • Target mode configuration auto save
  • Specify Single or Multiple targets
I've included an example campaign along with the new state images. Names of images match the name of token state.

See the Demo Video: http://www.filefront.com/16404589/targetingDemo2.avi 36mb 3:46

Download the campaign, lib and images: DOWNLOAD 8mb
Attachments
Example.jpg
Example.jpg (34.25 KiB) Viewed 7514 times
Last edited by aliasmask on Sun May 09, 2010 9:14 pm, edited 9 times in total.

User avatar
CoveredInFish
Demigod
Posts: 3104
Joined: Mon Jun 29, 2009 10:37 am
Location: Germany
Contact:

Re: Simple Auto Targeting Mode

Post by CoveredInFish »

This is genius! *applause*

Its awesome whats possible to achieve with the given maptool assets!

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

Re: Simple Auto Targeting Mode [new video]

Post by aliasmask »

Okay, I've upgraded the first version and uploaded a new demo video.

User avatar
Rumble
Deity
Posts: 6235
Joined: Tue Jul 01, 2008 7:48 pm

Re: Simple Auto Targeting Mode [new video]

Post by Rumble »

Very clever. I am going to experiment with incorporating this into my framework for D&D (assuming I have your permission). Not sure how to handle modifiers to the attack, but it would be fun to experiment with nonetheless!

Edit: One quick recommendation. This is probably not going to be a problem in most cases, but I added a check to makes sure that the targeting doesn't work on Lib:Tokens (and there are probably other tokens you don't want it to work on - tokens with the "Dead" state, or invisible, or whatever). I added these lines to "targetingMode":

Code: Select all

[h:targetedName = getName(targetId)]
[h, if(startsWith(targetedName, "Lib:")): isLibToken = 1; isLibToken = 0]
and then changed the condition in the final IF() option in that same macro to:

Code: Select all

[H, if(hasInit && !isSource && !isLibToken), code: {...

Otherwise, it works beautifully.

User avatar
Rumble
Deity
Posts: 6235
Joined: Tue Jul 01, 2008 7:48 pm

Re: Simple Auto Targeting Mode [new video]

Post by Rumble »

Let me rephrase: it works fantastic-awesome. I made a couple quick modifications for use in my framework (basically, I had it generate and store a target list that was then referenced so I could associate a specific target with a specific attack), and it was SLICK.

This is great stuff.

dorpond
RPTools Team
Posts: 5534
Joined: Thu Jun 01, 2006 2:05 pm
Location: Buffalo, NY

Re: Simple Auto Targeting Mode [new video]

Post by dorpond »

This sounds very interesting indeed! Do you have a basic campaign file that we can download to see it in action?
(I have bandwidth issues here at work)
How to use my bundled artwork (MT1.3B60+): http://forums.rptools.net/viewtopic.php?f=8&t=11759

User avatar
Rumble
Deity
Posts: 6235
Joined: Tue Jul 01, 2008 7:48 pm

Re: Simple Auto Targeting Mode [new video]

Post by Rumble »

dorpond wrote:This sounds very interesting indeed! Do you have a basic campaign file that we can download to see it in action?
(I have bandwidth issues here at work)

Yep. Download the attached campaign (it's 3MB; no idea why it's that big but I guess because there are a lot of states, etc.). Hopefully that's not too large.

To see it in action:

1. Add the tokens (not the big red ones, but the character tokens) to initiative.
2. Start initiative. Go to either the Relic or Theoden entry.
3. Select Relic or Theoden (whichever you picked in initiative)
4. Mouse off and then back over them to activate Targeting Mode.
5. Mouse over whoever you want to attack.
6. Pick an attack macro on the token doing the targeting (for instance, if you pick Relic, then Scorching Burst is a good one)
7. Run it.
8. Profit!

It seems like a lot of steps, but it's really just broken down exactingly. It's really quick to do, once you see the process.
Attachments
target-example.cmpgn
(3.48 MiB) Downloaded 205 times

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

Re: Simple Auto Targeting Mode [new video]

Post by aliasmask »

Yeah, target validation was the next step in the process. In fact, this part can get really intricate. Show different marks for Allies, Ranged vs Melee, spell effect targeting, force only 1 valid target. I was going to have different modes in mine where I have order of attack where I can separate a multi attack either by putting one or more attacks before hand on a target or giving the order of attack when a foe goes down.

I designed it, so far, to just cover the basics in targeting and to be used by anyone who can integrate it. I'm glad you like it and I'll checkout your framework to see it in action. As a quick change to your valid targets, I would use Wiki: getTokens() because it automatically filters lib: and image: tokens.

Here is a code snippet of it in action where I limit token selection for my combat manager:

Code: Select all

...
<!-- Filter for valid tokens -->
[h: allTokens = json.union(getTokens("json"),getOwned(l.player,"json"))]
[h: ids.active = json.intersection(ids.active,allTokens)]
[h: ids.inactive = json.intersection(ids.inactive,allTokens)]
[h: ids.selected = json.intersection(ids.selected,allTokens)]
... 
I believe getTokens("json") defaults to getting all the valid visible tokens, so if you're a gm, your selection will be greater unless you are in "player view" than an attached client.

edit: I'm guessing since the campaign won't load it is of a later version of MT than I have [1.3.b63]. I have yet to upgrade. I saw the "my old campaign won't load" posts and some token saving incompatibilities, so I decided to wait. I think it is safe to do now, but I hadn't planned on upgrading until I'm done with the current map I'm using.

edit: I'm working on another update and I'll have an example campaign file using the 3.5/Pathfinder framework by Imarkus. I've reduced the targetingMode macro down it's basic function and any kind of decision making will be made in the called macros.

Code: Select all

[H, if(!json.isEmpty(macro.args)): targetId = json.get(macro.args,0); targetId = ""]
[H: sourceId = getSelected()]
[H, if(listCount(sourceId) == 1 && getCurrentInitiative() != -1): hasInit = if(getInitiativeToken() == sourceId,1,0); hasInit = 0]
[H, if(hasInit), code: {
   [H, if(sourceId == targetId):
      execLink(macroLinkText("updateSource@Lib:CombatMedic","none",json.append("",sourceId)),1);
      execLink(macroLinkText("updateTarget@Lib:CombatMedic","none",json.append("",targetId,sourceId)),1)
   ]
};{}] 
This will allow for a more robust control of source and target manipulation without having to worry about messing up the core functionality. (namely recursion errors). I'll have more later.

I've also given some thought to how to target tokens who are covered by another token and I have expanded the targeting states to include Target Melee, Target Range, Target Ally and Target Magic. An example of Target Ally (which is not a good thing) is attacking someone in a grapple. For my attack macro, it would be nice to know if I have to apply a penalty to the attack because an Ally was in the way. By targeting the opponent and the Ally, that flag will exist to check against for any penalties and miss chance.

Some example pseudocode would be:

Code: Select all

if(Ally is targeted)
   true - if(melee attack)
      true - if(roll 20% concealment)
         true - attack ally
         false - attack enemy
      false - if(precise shot)
         true - no attack penalty
         false - minus 4 to hit
   false - attack enemy

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

Re: Simple Auto Targeting Mode [New Lib and Video]

Post by aliasmask »

New Version and Video is now on the first post.

User avatar
Full Bleed
Demigod
Posts: 4736
Joined: Sun Feb 25, 2007 11:53 am
Location: FL

Re: Simple Auto Targeting Mode [New Lib and Video]

Post by Full Bleed »

This seems pretty cool and I plan to use it selectively for awhile to see how it plays out, but I don't see any directions about how to actually incorporate this into an existing framework. I think I've got most of it figured out (add the "targetMacro" property, add the states, add the lib token), but can you give an example of how an attack macro uses the target information? Rumble's campaign example uses a newer version of MT than I'm using and the example campaign in the OP has no attack macros that do anything.
Maptool is the Millennium Falcon of VTT's -- "She may not look like much, but she's got it where it counts."

User avatar
Full Bleed
Demigod
Posts: 4736
Joined: Sun Feb 25, 2007 11:53 am
Location: FL

Re: Simple Auto Targeting Mode [New Lib and Video]

Post by Full Bleed »

Feature Request: The more I play around with this the less I think I really like the "Auto-On" targeting with the option box popping up every time. I've found that I can remove the targetMacro property and put it into a simple Macro and then run the target routine on a selected token, but I was wondering how hard it would be to build a function that could be easily called with a macro.

For example, rather than see the targeting option box come up each time, I think it would be nice to be able to make specific target macros like:

Code: Select all

[h: getTarget(Melee, Single, NPC, NoLock)]

It would also be nice to be able to set a maximum range for the target. That way you could build custom target macros for spells and other ranged attacks and you would only be able to target what was in range.
Maptool is the Millennium Falcon of VTT's -- "She may not look like much, but she's got it where it counts."

User avatar
Rumble
Deity
Posts: 6235
Joined: Tue Jul 01, 2008 7:48 pm

Re: Simple Auto Targeting Mode [New Lib and Video]

Post by Rumble »

Full Bleed wrote:Feature Request: The more I play around with this the less I think I really like the "Auto-On" targeting with the option box popping up every time. I've found that I can remove the targetMacro property and put it into a simple Macro and then run the target routine on a selected token, but I was wondering how hard it would be to build a function that could be easily called with a macro.

For example, rather than see the targeting option box come up each time, I think it would be nice to be able to make specific target macros like:

Code: Select all

[h: getTarget(Melee, Single, NPC, NoLock)]

It would also be nice to be able to set a maximum range for the target. That way you could build custom target macros for spells and other ranged attacks and you would only be able to target what was in range.


I found the same thing (I'm using the original version, not the latest version) - the auto-on can be a bit troublesome (and the code is a little...dense? Took me a while to figure out what aliasmask was doing in there!). However, I found that you can make some modifications to do a few things. Note that these are somewhat framework specific (D&D 4th Edition, to be precise), but what I did was:

1. Disable the auto-on feature.
2. Put in a "toggle targeting" button as a fail-safe/fallback just in case a state doesn't get cleared right, or whatever.
3. Have targeting go "active" when you click the macro button for an attack power.
4. Bring up a dialog (not an input()) so you can collect targets and add modifiers, etc. with the dialog open (the dialog updates to show what you've targeted as you add or remove targets).
5. Execute the power against the specific list of targets, and resolve rolls.
6. Shut off targeting and clear the target list.

I de-linked it from initiative since in D&D 4th you can act outside of your own initiative.

However, I have to say that despite minor quibbles or areas where it needed changes for my specific needs, this is really a very clever and well-done resource, so thanks, aliasmask!


@FB: I missed your comment about how an attack macro uses the target information. One thing you need to set up is a place to store the collected targets - I just made a property called "CurrentTargetList", which holds a JSON Array of targets selected (and updates if you de-select them). Then, when the power is executed, I grab that property, and do a foreach() through the list so I can grab the proper defense, and output the target's name, my roll, and whether it beat the defense or not. I'll post some code if you like.

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

Re: Simple Auto Targeting Mode [New Lib and Video]

Post by aliasmask »

I'm in the process of integrating this with a 3.5/pathfinder framework. My plan was to get the targets by simply saying:

Code: Select all

<!-- Get targeted token list -->
[H: targets = getTokens("json",json.set("{}","setStates",json.append("","Targeted"))] 
Optionally, I could test to see if the attack is magic based (has no weapon damage modifiers), melee (ignore ranged feats) or ranged(get token ranges for mods) or has an Ally targeted (apply concealment for melee, range penalty check for range). I would probably just test the targeting mode.

Code: Select all

[H: id = getTokens("json",json.set("{}","setStates",json.append("","Targeting"))]
[H: isRange = getState("Targeting Range",id)]
[H: isMelee = getState("Targeting Melee",id)]
[H: isMagic = getState("Targeting Magic",id)]
[H: isAllyTargeted = json.isEmpty(getTokens("json",json.set("{}","setStates",json.append("","Target Ally")))]
 
Using states makes this code independent of existing frameworks. The config (popup) can be turned off by selecting the last option and locking it for that token, but I can imagine it can get more annoying for the GM with all those NPCs. I can default it to off and keep the other defaults where any single enemy target will be selected. If you need to change it, then you can hit the macro I provided to reset.

Code: Select all

[H: resetTargeting()] 
I can easily add some parameters to that to set specific settings. But to do it now would require a call to resetTargeting to clear existing targets and this:

Code: Select all

<!-- tMode: 0 Any, 1 Melee, 2 Range, 3 Magic -->
<!-- isMultiTarget: 0 No, 1 Yes -->
<!-- mMode, maxTargets not used yet -->
<!-- noPopup: 0 No, 1 Yes -->
<!-- targetAlly: 0 No, 1 Yes -->
<!-- sourceId: id of token holding these settings -->
[H: setProperty("h.targetModes",json.set("{}","tMode",tMode,"isMultiTarget",isMultiTarget,"mMode",mMode,
   "maxTargets",maxTargets,"noPopup",noPopup,"targetAlly",targetAlly),sourceId)] 
edit: Also, this system is designed to only have 1 person targeting at a time, so hasInit was the most obvious and easy to check constriction, but I will make it so you can target while not your turn, but no other tokens can be in targeting mode to do so. I'll make a button for that. So, I'll add "Toggle Targeting" which will turn off targeting all together for selected tokens and "Set Targeting Mode" which will set that tokens mode. If the token has init, it will also clear any targets on the board.

An example of use would be:

Code: Select all

<!-- Turn Targeting on, darn the torpedoes -->
[H: toggleTargeting(1)]
<!-- Turn Targeting off -->
[H: toggleTargeting(0)]
<!-- Toggle the existing targeting -->
[H: toggleTargeting()]

<!-- Set targeting mode to melee, multiple targets, no allys -->
[H: setTargetingMode(json.set("{}","tMode",1,"isMultiTarget":1,"targetAlly":0))]
[H: setTargetingMode(1,1,0)]
<!-- Or use the word for targeting mode: any,melee,range,magic -->
[H: setTargetingMode(json.set("{}","tMode","melee","isMultiTarget":1,"targetAlly":0))]
[H: setTargetingMode("melee",1,0)]
 
I'll post the updated lib later.

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

Re: Simple Auto Targeting Mode [New Lib and Video]

Post by aliasmask »

1. Disable the auto-on feature.
2. Put in a "toggle targeting" button as a fail-safe/fallback just in case a state doesn't get cleared right, or whatever.
3. Have targeting go "active" when you click the macro button for an attack power.
4. Bring up a dialog (not an input()) so you can collect targets and add modifiers, etc. with the dialog open (the dialog updates to show what you've targeted as you add or remove targets).
5. Execute the power against the specific list of targets, and resolve rolls.
6. Shut off targeting and clear the target list.
  1. Will do.
  2. Toggle the targeted token, or the targeting token? I already have a "Reset Targeting" to clear all targets and sources and the settings for a source are set back to default.
  3. Will do, sort of. Since I'm trying to keep it separate from a framework, the framework attack macro will be able to call toggleTargeting(1) to activate.
  4. I suppose I can make a form input for processing targets. Actually, that's what my the other part of my combat medic does, and it's in a frame that remains open. I haven't integrated the two yet though. But it will display your sources, defaulting to the one who has initiative. Shows a list of tokens being targeted. Has buttons for attacking, healing and recovery. The targets have checkboxes to add and remove.
  5. That's what combat medic will do. Both of these are framework specific though and really aren't a part of the targeting code.
  6. Will do. I'll have a global shut off/on button. I'll probably just integrate it with the resetTargeting() macro where passing it a 1 will turn on, and 0 will turn off targeting globally.
  7. For Full Bleed: Will do on the getTarget but it's more like my setTargetingMode() above. I'll actually create a getTargets() macro as well and it will return targets based on a list, ie getTargets("any,melee,range,magic,ally") would be the full gambit and will return a json object of json arrays. For example:
    • getTargets("melee") = {"mode":"melee","hasAlly":1,"melee":["id1","id2"],"ally":["id2"]}.
    • getTargets("any") = {"mode":"any","hasAlly":1,"melee":["id1","id2"],"ally":["id2,id4"],"range":["id3","id4"],"any":["id1","id2","id3","id4"],"self":"id0"}
    • getTargets("magic") = {"mode":"magic","hasAlly":1,"magic":["id1","id2","id3","id4"],"self":"id0"}
I haven't though about how I should deal with targeting yourself yet. I do have to make a change to "any" mode and set targets not in melee range to range targets. This may actually make melee and range mode obsolete, except by limiting what can be targeted.

User avatar
Rumble
Deity
Posts: 6235
Joined: Tue Jul 01, 2008 7:48 pm

Re: Simple Auto Targeting Mode [New Lib and Video]

Post by Rumble »

No, no - those are the things I did to make it work with the specifics of my framework. Not recommendations for your basic structure.

What you created is sort of like a "plugin"; it has to be adapted to specific needs, is all, and that's what I did to make it work just like I wanted.

Post Reply

Return to “Drop-In Macros and Scripts”