• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

How to set passive Abilities to Variable?

Status
Not open for further replies.
Level 2
Joined
Oct 25, 2019
Messages
11
How do you set an ability to a variable? Specifically, I want a hero to gain a passive spellbook ability upon using an item, and then later be able to "trade out" that ability with another. So, my thoughts were to set the the original passive to variable (Hero_Ability_ Store) and then have the game remove that variable from the Hero when they switch it out with a new item and linked passive.

Right now, I dont know how to tell the game to set the passive ability to a variable because the only capture I see is "Ability being cast" which doesnt work for passives as far as I know.

TLDR: How to set a passive ability to a variable?
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,553
Adding and Removing abilities doesn't require a specific ability instance, you can either Add X ability or Remove X ability.
  • Unit - Add YourSpellbookAbility to (Triggering unit)
  • Unit - Remove YourSpellbookAbility from (Triggering unit)
If the Ability stacks, which a lot of Item abilities do, it will Add the ability to the Unit again and the effects will stack with one another. If the ability doesn't stack (most don't stack), then the unit can only have one copy of the ability, and trying to add a new copy will fail.

For example, a unit can only have one copy of the Blizzard ability, unless you've created a separate copy of it which has a different rawcode. Regardless, both copies will share the same order id which will create conflict issues when trying to issue the order to cast them on the same unit. Item abilities that stack, which is not openly stated, do not suffer from this issue and will apply to the unit an "infinite" number of times. In other words, a unit can have 5 copies of the "+100 life" ability, which will all work together to add 500 life to the unit.

But to answer your question, the Variable you're looking for is Ability Code. I believe the Ability variable is used to specify a specific instance of an ability that exists on a unit.

You can think of it like there's Ability Types and then there's Abilities, Units have Abilities which derive their stats from their Ability Type. Similar to how there are Unit Types and Units. Each Unit is it's own unique instance with stats that change as they move, attack, etc... but they derive their base stats from their Unit Type.
 
Last edited:
Level 2
Joined
Oct 25, 2019
Messages
11
Thanks for the response, I don't think I was clear enough in what I'm trying to do.

I'm essentially trying to make different weapons that heros can equip, but instead of taking up an inventory slot, they instead give bonus damage and abilities added directly to the unit via triggers.

When they find a new weapon, I want them to switch it out and lose the previous abilities gained. I'll have several potential abilties so unless I code it to remove every single passive given by weapons, I cant just code it to remove the ability.

The spellbook is already being used for general abilities as well, so I cant remove the whole spellbook either.

I found ability code, but I don't see a way to match the ability I want removed. I am adding an ability via trigger, and ideally there would be something like " last ability added" capture for me to use, but there is only ability being cast.
 
Level 39
Joined
Feb 27, 2007
Messages
5,016
But to answer your question, the Variable you're looking for is Ability Code.
@Mordeltho Under the hood it's also just an integer variable, but GUI classifies them differently to try to prevent dumb user stuff. In some cases treating it directly as an integer can be preferable (for example you can't store an abilitycode in a hashtable in GUI because it literally will not let you, but you can store an integer easily).

As Uncle alluded to there are two 'kinds' of ability variables. Abilitycode (integers internally) refer to the overall ability as a whole; you might say: "The blizzard spell that Archmages can learn". Most of the time you just need to use abilitycode variables to do whatever you need to do because telling the game "remove the 'Archmage Default Blizzard' type spell from Triggering Unit" does what you need it to do.

A few patches ago Blizzard (re)introduced actual ability instance variables that refer to a specific instance of an ability on a specific unit. They did this because it's now possible to modify a specific instance of an ability rather than the ability as a whole. "This archmage's Blizzard costs 50% less than every other archmage's Blizzard" is something you could do with these ability instance variables without having to have an actually separate version of the ability for each unit whose Blizzard should act uniquely in some fashion.
When they find a new weapon, I want them to switch it out and lose the previous abilities gained. I'll have several potential abilties so unless I code it to remove every single passive given by weapons, I cant just code it to remove the ability.
Along with this functionality to set ability fields dynamically at runtime on a per-instance basis Blizzard introduced the ability to read many Object Editor fields at run-time. This means it's now possible to load and read the list of abilities attached to a given item! You could proceed this way by storing the abilities directly on the manipulated weapon object, then loading the rawcodes of the relevant abilities by reading the object's data fields, and then adding/removing those abilities (by rawcode, which is effectively an abilitycode) as desired.

Another solution is to build your own database in a hashtable. You would use the manipulated weapon object as a parent key in your hashtable and store the relevant information in that hashtable at map init. When a unit manipulates one of these weapons you look in the hashtable under that weapon as a parent key, using the child keys for different things you might want to return. Think of them as x,y coordinates but instead of numbers they can be objects or strings or numbers or anything. Longsword,NumAbilities might return 3, telling you that there are 3 associated abilities with the Longsword. Then you read Longsword,Abil1 and Longsword,Abil2 and Longsword,Abil3 to learn what those abilities are.

IMO grabbing that info directly by reading the OE data fields would be easier, but both are acceptable solutions.
 
Level 39
Joined
Feb 27, 2007
Messages
5,016
Another solution to avoid having to know which abilities were added would be to reverse bear-form morph the unit into something and then reverse-morph it back to what it originally was. By using a reverse morph it won't interrupt orders or require that the unit not be stunned/silenced and it will remove any abilities added through triggers that have not been 'made permanent' with call SetUnitAbilityPermanent(unit, abil, true). So if you never make the weapon bonus abilities permanent any morphing will always remove all of them.
 
Status
Not open for further replies.
Top