Target a Visible NPC: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
m (Conversion script moved page Target a Visible NPC to target a Visible NPC: Converting page titles to lowercase)
No edit summary
Line 10: Line 10:


<hr>
<hr>
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
/self  
/self  
[h: lsVisibleNpc = json.intersection( getNPCNames("json"), getVisibleTokenNames("json") )]
[h: lsVisibleNpc = json.intersection( getNPCNames("json"), getVisibleTokenNames("json") )]
Line 25: Line 25:
// 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}
</source>
</syntaxhighlight>

Revision as of 17:11, 14 March 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}