Target a Visible NPC: Difference between revisions
Jump to navigation
Jump to search
m (Target Visible NPCs moved to Target a Visible NPC: Ambiguous title) |
m (Taustin moved page target a Visible NPC to Target a Visible NPC without leaving a redirect) |
||
(4 intermediate revisions by 3 users not shown) | |||
Line 10: | Line 10: | ||
<hr> | <hr> | ||
< | <syntaxhighlight lang="mtmacro" line> | ||
/self | /self | ||
[h: lsVisibleNpc = json.intersection( getNPCNames("json"), getVisibleTokenNames("json") )] | [h: lsVisibleNpc = json.intersection( getNPCNames("json"), getVisibleTokenNames("json") )] | ||
Line 21: | Line 21: | ||
// Retrieve the first element, so we only get the name (and not ["name"]) | // Retrieve the first element, so we only get the name (and not ["name"]) | ||
[h: currentTgt = json.get | [h: currentTgt = json.get(lsVisibleNpc, index) ] | ||
// Display message to be sure of what has just been done | // Display message to be sure of what has just been done | ||
Current target : {currentTgt} | Current target : {currentTgt} | ||
</ | </syntaxhighlight> |
Latest revision as of 23:59, 3 May 2023
Note: This function can only be used in a Trusted Macro
This macro allows a player to pick-up a NPC among those he can currently see. Note that this is about the player's view and not the currently selected token's view. You may then store the target's name in the token's properties to ease further actions.
Basically, the macro gets the list of all NPCs available (with getNPCNames()) and the list of all visible tokens (with getVisibleTokenNames()). Then, the intersection will provide visible NPCs.
Macro
1.3b53+
/self
[h: lsVisibleNpc = json.intersection( getNPCNames("json"), getVisibleTokenNames("json") )]
// Abort if no target found (intersection returned an empty list)
[h: assert(json.length(lsVisibleNpc), "No visible NPC", 0)]
// UI: popup a list for selection
[h: input("index|"+json.toList(lsVisibleNpc)+"|My target is|LIST") ]
// Retrieve the first element, so we only get the name (and not ["name"])
[h: currentTgt = json.get(lsVisibleNpc, index) ]
// Display message to be sure of what has just been done
Current target : {currentTgt}