• 🏆 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!

Trigger how to check if unit has any ability

Status
Not open for further replies.
Level 5
Joined
Dec 25, 2014
Messages
111
Usually, to see if a unit has a spesific ability or not, we're using trigger like 'Level of Thunder Clap greater than or equal to 0'.
Here, i wonder how to check does a unit have ANY ability or not. I believe it has something to do with ability id. In my mind, we'll do something like check the ID from 'A000' to 'ZZZZ' (Correct me, please), which is very painful and i don't know how to code it but i'm sure they has to be a string.
Since there is no way in GUI to check and convert those string id, we'll do it in JASS/vJASS/LUA, then i found these natives :
JASS:
// Not currently working correctly...
constant native AbilityId                   takes string  abilityIdString   returns integer
constant native AbilityId2String            takes integer abilityId         returns string
It say that isn't currently woking correctly, last time i test, it's absolutely do nothing. Dunno if its my code or no.
Sorry i can't explain correctly, evidently english is still bad for me. But i think you all are understand what i mean.
Well, any thoughts how?

Edit : It's more like we're checking every abilities the unit have.
 
Last edited:
Level 13
Joined
Mar 24, 2013
Messages
1,105
In this post, String to ability or item name

WaterKnight appears to be pulling from the common.j where those functions are listed as not working.

If you don't have hundreds of potential abilities, I think you could easily make a catalog/list and then loop through it checking for the unit.

In pseudo code:

set list = 0
set ability[list) = Chain lightning/'AOcl'
set list = list + 1
set ability[list) = Silence
set list = list + 1

Once you have your abilities in the catalog to check if a unit has an ability on that list loop through the list

int i = 0
loop
exitwhen i >= list
if myUnit has ability then
ABILITY FOUND
endif
set i = i + 1
endloop

Edit: changed [-list-] to [list) because hive thinks I want bullet point formatting
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
Here, i wonder how to check does a unit have ANY ability or not. I believe it has something to do with ability id. In my mind, we'll do something like check the ID from 'A000' to 'ZZZZ' (Correct me, please), which is very painful and i don't know how to code it but i'm sure they has to be a string.
This is not viable. You would be testing the level of several hundred million ability type ID codes. With JASS this would easily hit the op limit. If op limit is bypassed the game client will likely have to freeze for several seconds to several minutes in order to complete the execution.

The easiest solution is to do what FeelsGoodMan suggested.
If the unit starts with no abilities can't you just set a boolean as true as soon as it learns an ability and do a boolean condition check in future triggers?
This is very fast to execute and requires no guess attempts.
Besides, ability that added through trigger won't count.
When a trigger adds an ability to the unit you can set the boolean to true at the same time.

With JASS based GUI this is annoying to do and might require use of a trigger and variables to emulate a function call. With JASS this is best done by defining and using your own add ability to unit function which adds the ability and sets the boolean. With Lua based GUI one can proxy the standard BJ function calls GUI uses to instead call a proxy function which adds the ability and sets the boolean.

One could try/experiment using the following 1.31+ native which might be able to perform what you want to do efficiently. I have no experience using this but it does look like it could be used to iterate through all the abilities a unit has and hence test for their existence.
JASS:
native BlzGetUnitAbilityByIndex takes unit whichUnit,integer index returns ability
 
Level 5
Joined
Dec 25, 2014
Messages
111
Oh I was confused then, as you initially wrote ANY ability.
My apologies.
I think a better solution could be suggested/arrived at if you explain exactly why you want this functionality.
Okay. First of all, it's because of Doom's and Morphling's spell from Dota, Spellbook and new 1.31 natives where we could modify ability field through trigger (It's currently not working tho, but it should be fixed in the future).
With those, adding some abilities from unit to unit or adding it to a Spellbook within a trigger is possible. Then i'm wondering how to check what abilities does the unit have.
 
Status
Not open for further replies.
Top