• 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.
  • It's time for the first HD Modeling Contest of 2025. Join the theme discussion for Hive's HD Modeling Contest #7! Click here to post your idea!

Abilities as flags.

Status
Not open for further replies.
Level 12
Joined
May 22, 2015
Messages
1,051
I've recently started using abilities to mark units. The ability does nothing and has no icon, so you can't even tell it's there. I use the abilities to determine what to do with them for certain triggers. This is mostly so that I don't have to check the unit type against several units that all behave similarly.

As an example, there are plenty of effects in my map that "corrupt" a unit (corrupt as in mind control, turn them into a zombie, turn them into a vampire, etc). To protect certain units (buildings, "holy" units, and heroes) from these effects, I was checking all these unit types and classifications to make sure it didn't hit them. I decided to simplify it to just check if they have the ability "Corruption Protection" which does nothing outside of these triggers. If they have it, then nothing happens. Otherwise, it does its normal thing and zombifies / mind controls them.

I've since used it for a whole bunch of other things in my map as well.

Here's my questions about it:
Is there any issue with doing this?
I am also wondering if it is better to use this than to use unit groups in the cases where I never need to loop over the unit group.
 
That is a good solution. It is fine to use.

If those units are controllable, then just beware that players may click on the ability even if it doesn't have an icon (and there is no way to get rid of the tooltip). Nothing is wrong with that, but it can look ugly/weird. You may want to use something like SetPlayerAbilityAvailable() to hide the spell, or use a hidden spellbook. But if it is just for npcs, then you don't have to worry about this.

EDIT: The alternative would be to use a hashtable to map the unit's ID to a flag. e.g.
JASS:
local integer parentKey = StringHash("corruption")
call SaveBoolean(hash, parentKey, 'hfoo', true)
call SaveBoolean(hash, parentKey, 'Hpal', true)
// ...
etc. Then you can just load the boolean of the unit's ID to check if the unit has that flag. You would save those values on init. But I don't see anything really wrong with your method, so it is your choice.
 

TKF

TKF

Level 19
Joined
Nov 29, 2006
Messages
1,267
I've recently started using abilities to mark units. The ability does nothing and has no icon, so you can't even tell it's there.

You are not the only one using this. Some mappers uses this. I often uses dummy abilities to flag or index units in a certain way.

I think Hashtables loads is a bit slower than checking if a unit has an ability. I haven't tested that though.
 
Level 12
Joined
May 22, 2015
Messages
1,051
Awesome. Thanks guys!

EDIT:
There are abilities that have no icon so I am using those. I think they are based off of the attribute bonus hero ability with no stats and with the option to have the icon not show up.
 
Level 24
Joined
Aug 1, 2013
Messages
4,658
You can do it even better.
Go and download a unit indexer system and create boolean array variables (you can also use integers to combine certain classifications).

Use the Custom Data of the unit (which is unique due to the indexer) as index in the array.
You can do pretty much everything you want.
You wont need a hashtable and it is much faster and better to read.
 
Level 12
Joined
May 22, 2015
Messages
1,051
A unit indexer is for storing unique unit IDs, right? That is probably better in place of unit groups than abilities, so I'll probably look at it for that. I think the abilities are very handy for when the unit type is always behaving the same.
 
Level 25
Joined
May 11, 2007
Messages
4,650
That is a good solution. It is fine to use.

If those units are controllable, then just beware that players may click on the ability even if it doesn't have an icon (and there is no way to get rid of the tooltip). Nothing is wrong with that, but it can look ugly/weird. You may want to use something like SetPlayerAbilityAvailable() to hide the spell, or use a hidden spellbook. But if it is just for npcs, then you don't have to worry about this.

There is no need to use a hidden spellbook anymore:
http://www.hiveworkshop.com/forums/lab-715/hiding-any-button-new-method-please-help-me-test-266571/
 
@SAUS: Yes. A unit indexer gives each unit a unique integer index from 0 to 8191 so that you can store data conveniently through arrays. However, using a unit indexer is better when you have unit-specific behavior/data. In your case, you need to store a flag for an entire unit-type, so using an ability or hashtable (these are both consistent across unit-types) is arguably better.

@LordDz: Thanks for the link.
 
Status
Not open for further replies.
Top