- Joined
- Aug 18, 2009
- Messages
- 4,097
Exposition
Blizzard offers the jass function
SetPlayerAbilityAvailable
or in GUI
- Player - Enable/Disable Ability
UnitRemoveAbility
or in GUI
- Unit - Remove Ability
Unfortunately, the action covers all the units of a given player and there is no variant for a specific unit.
Fortunately, this tutorial will present some solution.
I have to differentiate between heroes and units. Well, the unit way could be used for heroes too, but it's more cumbersome and less performant. Also, the procedure for non-heroes harbors danger. I cannot say if it's practicable in the end but maybe with the proper configurations.
Anyway, read For Heroes first. The second part references it.
For Heroes
There is a very useful ability for us mapmakers out there called Engineering Upgrade. Its raw code is ANeg, so I will name it that way in this tutorial from now on. The ability holds the power to convert another ability on the unit to a different one. You have to specify both the source and the target ability.
ex:
ANeg with Blizzard (source) to Bash (target)
If you add this ANeg to a unit with the Blizzard ability, it will end up with Bash instead.
Now, I have to tell that when transforming an ability this way, the target ability on the unit inherits some of the source ability's features, such as the remaining cooldown. Furthermore, if you change the source ability while the unit is currently casting it, the unit won't be bothered the least and continue normally. This can be well observed on a channeling spell like Blizzard for example. So two main properties I ascribed to
SetPlayerAbilityAvailable
above are fulfilled.We only need to hide the target ability (and ANeg) now. To not get in conflict with any other stuff, we may create a new dummy ability. I will refer to it as Placeholder. It can basically be of any base, or close to. I usually choose Agyb (Gyrocopter Bombs) for an effectless non-active ability although it could make sense to use the Slow Aura of Tornado or Attribute Bonus here since those abilities do not possess an icon in the first place/can be hidden by configuration. Anyway, Placeholder and ANeg can both be shrouded by
SetPlayerAbilityAvailable
, which should be done at map init. Note that ANeg still works when disabled.Simplification note: I found that the Placeholder can also be the ANeg itself. The unit will have it twice then but it works.
To reveal the ability again, remove ANeg from the unit. The conversion will be reverted with the cooldown still intact. Since ANeg does not remember the source ability it transformed but instead looks up its object data, each ability we want to be able to hide requires another Placeholder plus another ANeg (or only another ANeg if ANeg is the Placeholder).
For Non-Heroes
Why can we not do the same process for non-heroes? Wc3 will crash when trying to add ANeg to a normal unit. So the plan is to disguise the unit as a heroic hero. The only way I have found to accomplish that is by morphing the unit into another (hero) unit type. Doing so is dangerous according to Dr Super Good, and I believe so myself, but maybe it's okay with the proper settings or conditions. The game won't immediately shut down but may run into problems later on when events happen. Another contra is that not each morphing method interrupts the unit's order but it will reset the animation.
Now, if we just morph the unit, add ANeg to hide the ability, then remorph the unit to its original type, that won't work because the unit would still hold ANeg without being a hero and Wc3 does not like it. If we could only remove ANeg before reverting and still keep the ability transformation, our problem would immediately vanish. There comes another trick into play:
Reversed Engineering Upgrade Trick:
As I have stated above, ANeg does not keep in mind which ability it has been used on, rather looks it up from its object editor data. What do you think will happen when we swap source and target ability? Placeholder becomes the source, the ability we want to hide becomes the target. Our unit does not possess Placeholder in the beginning. Nothing will happen when we add ANeg. When we take ANeg away again, however, it will "revert" our original ability by Placeholder. Transformation successful, without keeping ANeg.
The reason I have not suggested this above is because it needs another ANeg now to get from Placeholder to the original ability, one more object.
Additional information on morphing units: A unit will lose all abilities which the target unit type does not possess, while morphing, unless you apply the function
UnitMakeAbilityPermanent
before. This is necessary to keep Placeholder/original ability. I usually have it combined with UnitAddAbility
in a header function. UnitMakeAbilityPermanent
does not have a GUI equivalent.Summarized:
to disable ability:
morph unit to hero
add ANeg1 (Placeholder to original)
remove ANeg1 (Placeholder to original)
morph unit back
to enable ability:
morph unit to hero
add ANeg2 (original to Placeholder)
remove ANeg2 (original to Placeholder)
morph unit back
Finally, I would like to recommend the morphing method and make some comments on the hero unit type.
Of course, we want to be able to do this without any delay. Therefore, the active ones like Metamorphosis are no good, you would also need to trigger orders etc., which would again interrupt casts. Chaos (Srtt) is not sufficient either as it suffers from some minimal delay. The choice goes to the method described here. The trick it makes use of is practically the same as in Reversed Engineering.
Comments on the hero unit type: Blizzard did not account for morphing units into heroes/backwards. Heroes benefit from hero attributes, which influence stats such as hitpoints or armor. When the unit reverts into non-hero form, those bonuses are not dissolved, so the unit ends up with false values. To counter this, just set hero attributes to zero. Also set the base armor value of heroes to 0 (gameplay constant Hero Attribute - Defense Base (before Agility Bonus)). You can equalize this by manually adding the default base armor to each hero in your map. In addition, check Values - Hero - Hide Hero Interface Icon, else the hero portrait will persist.
Test maps are attached.