Weird, I can't get getExposedTokenNames() to work. Always returns blank eventhough I have vision on, fow and exposed tokens.
Here's a variation on a function I wrote awhile ago which I use for all my targeting which works for PC and NPC tokens. It will only show the tokens seen by source token. I put a bunch of extra comments in there for you, but typically you can remove those without the *. Tested the code to make sure it works.
Code: Select all
<!-- Macro should have apply to selected checked -->
[H: source = currentToken()]
<!-- get all the tokens on the token layer -->
[H: tokenIds = getTokens("json",json.set("{}","layer","token"))]
<!-- we stop if there are no targets or if there is no current token. remove self from list -->
[H, if(! json.isEmpty(tokenIds) && ! json.isEmpty(source)): tokenIds = json.difference(tokenIds,json.append("",source)); abort(0)]
<!-- reduce list to all tokens to only seen tokens -->
[H: targets = "[]"]
<!-- do this so it works for npc tokens who normally don't have sight on -->
[H: hasSight = hasSight()]
[H, if(! hasSight()): setHasSight(1)]
<!-- add to target list is the source can see the token -->
[H, foreach(tokenId,tokenIds), code: {
[H: canSee = ! json.isEmpty(canSeeToken(tokenId))]
[H, if(canSee): targets = json.append(targets,tokenId)]
}]
<!-- turn npc sight back off it was off before -->
[H, if(hasSight != hasSight()): setHasSight(hasSight)]
<!-- generate the list for the input and sort by name -->
[H: inputList = ""]
[H, foreach(tokenId,targets), code: {
[H: switchToken(tokenId)]
[H: image = getTokenImage()]
[H: inputList = json.append(inputList,strformat("%{token.name} %{image}-30"))]
}]
[H: inputList = json.toList(json.sort(inputList,"a"))]
<!-- INPUT -->
[H: abort(input(
strformat("target|%{inputList}|Select Target|LIST|ICON=TRUE"),
"feature2|None, EvilOutsiderDragonUndead, OtherEvil |Smite Evil|LIST|SELECT=0 VALUE=STRING",
"haste|0|Hasted?|CHECK",
"isPowerAttack|0|PowerAttack?|CHECK",
"isCharging|0|Charging?|CHECK"
))]
keywords: amsave targeting