• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Determining which selected unit show items/abilities/portrait via triggers

Status
Not open for further replies.
Level 2
Joined
Feb 23, 2017
Messages
9
I know how to check which units are selected by a player, but I want to know which specific unit currently has their inventory, abilities and portrait displayed. Is there a decent way to do this?
 
Level 45
Joined
Feb 27, 2007
Messages
5,578
No, because switching between active units in the selected group doesn't trigger an event and there are no functions related to it. Here's a thought though:

Only way I can think of is to force a hotkey for the player, and whichever unit is ordered to do whatever the hotkey corresponds to is the currently active unit. Ideally you would use a hotkey for a no-target basic command card action that all units share but because many buildings can't attack or move they don't get Stop/Hold like normal units would. In any case you can make a custom channel-based ability with no targets, animations, art, mana cost, etc. as well as a black icon, its own designated hotkey that no other ability shares and a unique orderstring not used by another ability in your map. Give every unit in your map the ability by default and simply disable/enable it on a per-unit basis with the new ability enabling/hiding functions.

When you want to know what's active, enable the ability for every unit currently selected by the player, force the hotkey, and begin listening for units being ordered to do the special order in your custom ability. Once one is detected, disable the ability on every unit you added it to before and re-issue the active unit's previous order (via something like Last Order) to keep it from being interrupted. Unfortunately the big boner killer here is that this whole process takes a non-zero amount of time to happen so your 'currently active unit' query will never be instantaneous. There is a slight delay between enabling the ability (or adding it in the first place) and being able to successfully force its hotkey (too early and nothing happens), and a second slight delay before that order event fires.

If the active unit is currently stunned/silenced/unable to cast for some reason this method will fail.
 
Level 2
Joined
Feb 23, 2017
Messages
9
Okay, thanks. I kind of suspected that there might be no way to easily detect the unit showing abilities, etc.

I think your approach makes some sense for trying to detect what's selected (with some drawbacks you mentioned, thanks for that!), but my end goal is to create ability and item tooltips that are unique to specific units (not just unit types). The items are fairly easy. For abilities, since I plan to script virtually all abilities, I can just create several copies of generic abilities and give every selected unit a unique version with the desired tooltip. I don't think it will be incredibly difficult, but it uses a lot more resources than only updating ability tooltips to reflect a single currently shown unit.
 
Level 2
Joined
Feb 23, 2017
Messages
9
The dynamic tooltips is pretty much what I'm going for. Allows you to easily display stat-based ability info more nicely, as well as making it possible to generate combinations of spell effects without creating a new spell for each, but still having accurate descriptions. The trouble is knowing which unit's dynamic ability tooltips should be displayed. I think making 12x the ability levels (or 12 copies of each ability) is the most straightforward approach, but that requires a LOT of abilities/ability levels. It looks like a lot of that discussion is going on the assumption that each player really only has one caster, which is probably simpler and makes sense for things like RPGs, but isn't as generic as I'd like.

Thanks for the pointers!
 
Status
Not open for further replies.
Top