Trying to Find Guide or Tutorial

Thoughts, Help, Feature Requests, Bug Reports, Developing code for...

Moderators: dorpond, trevor, Azhrei

Forum rules
PLEASE don't post images of your entire desktop, attach entire campaign files when only a single file is needed, or generally act in some other anti-social behavior. :)
Post Reply
Raebit
Kobold
Posts: 4
Joined: Tue Mar 24, 2015 6:47 pm

Trying to Find Guide or Tutorial

Post by Raebit »

Hello again,

Pretty new to macros, but I understand how to write them and the basic functions.

I am looking for a tutorial or example that will help me construct a target selection macro that will bring up a table of tokens within a player's/token's sight radius for an attack macro. I would like to avoid having the players type out and declare a target each time they attack. Is this possible?

Second question: Can you send multiple macro.args variables to a library token and then send multiple macro.returns? How would you define those extra variables?

Thanks for your time.

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

Re: Trying to Find Guide or Tutorial

Post by wolph42 »

thats yes allover and selection based targeting is also explained on this forum...but you have to search that one.
passing on multipe vars is done by gathering them first in a json array Wiki: json.append() and retrieving them afterwards Wiki: json.get()

you can also have a look at the first link in my sig.

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

Re: Trying to Find Guide or Tutorial

Post by Full Bleed »

Raebit wrote:I am looking for a tutorial or example that will help me construct a target selection macro that will bring up a table of tokens within a player's/token's sight radius for an attack macro. I would like to avoid having the players type out and declare a target each time they attack. Is this possible?
There are a lot of topics on targetting...

Here is one that might get you started about thinking what you can do: http://forums.rptools.net/viewtopic.php ... targetting

It's an old thread, but some good info in there. You can download some existing frameworks and see how other people are doing it these days, too.
Maptool is the Millennium Falcon of VTT's -- "She may not look like much, but she's got it where it counts."


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

Re: Trying to Find Guide or Tutorial

Post by aliasmask »

I wrote this targeting macro awhile ago:

http://forums.rptools.net/viewtopic.php ... 9&#p203749

Here's my latest incarnation of finding targets:
||| getSeenTargets(options,source) |||

Code: Select all

<!-- getSeenTokens(options,source): json array or object 

options (strprop or json object)
   pc - 0 any token, 1 - PC only
   npc - 0 any token, 1 - NPC only
   range - upto this distance in grid units (ie feet, and not grid squares); 0 - any range
   self - 0 do not include self, 1 include self
source = source token, defaults to currentToken
   
This function will get a list of tokenIds based on the current tokens vision 
-->

[H, if(argCount()): options = lower(arg(0)); options = "{}"]
[H, if(argCount() >= 2): sourceToken = arg(1); sourceToken = currentToken()]

<!-- verify token is on current map -->
[H: sourceToken = findToken(sourceToken)]

[H: assert(! json.isEmpty(sourceToken),"<b>getSeenTokens(options,source):</b> Token not found on current map.",0)]

<!-- define options locally -->
[H: defaults = json.set("{}","pc",0,"npc",0,"range",0,"self",0)]
[H, if(json.type(options) == "UNKNOWN" && ! json.isEmpty(options)): options = json.fromStrProp(options)]
[H, if(json.isEmpty(options)): options = defaults; options = json.merge(defaults,options)]
[H: varsFromStrProp(json.toStrProp(options))]

<!-- get token ids -->
[H: conditions = "{}"]
[H, if(npc && ! pc): conditions = json.set(conditions,"npc",npc)]
[H, if(! npc && pc): conditions = json.set(conditions,"pc",pc)]
[H, if(range): conditions = json.set(conditions,"range",json.set("{}","token",sourceToken,"upto",range,"distancePerCell",1))]
[H, if(! json.isEmpty(conditions)): tokenIds = getTokens("json",conditions); tokenIds = getTokens("json")]

<!-- exclude self if set -->
[H, if(self), code: {
   [H, if(! json.isEmpty(tokenIds)): tokenIds = json.union(tokenIds,json.append("",sourceToken)); tokenIds = json.append("",sourceToken)]
};{
   [H, if(! json.isEmpty(tokenIds)): tokenIds = json.difference(tokenIds,json.append("",sourceToken)); tokenIds = "[]"]
}]

<!-- check each id for name and visible -->
[H: targets = "[]"]
[H: hasSight = hasSight()]
[H, if(! hasSight()): setHasSight(1)] <!-- this works for NPC tokens too -->
[H, foreach(tokenId,tokenIds), code: {
   [H: canSee = ! json.isEmpty(canSeeToken(tokenId))]
   [H, if(canSee): targets = json.append(targets,tokenId)]
}]
[H, if(hasSight != hasSight()): setHasSight(hasSight)]

[H: macro.return = targets] 
keywords: amsave targeting

Raebit
Kobold
Posts: 4
Joined: Tue Mar 24, 2015 6:47 pm

Re: Trying to Find Guide or Tutorial

Post by Raebit »

Wow, thank you Wolf, Full Bleed, and again, Alias! That should keep me busy for a while. Much option! (forgive my doge...)

Post Reply

Return to “MapTool”