• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Hero ability list

Level 2
Joined
Apr 2, 2023
Messages
3
Hello guys, is there any easy way to get a list of hero's abilities using GUI or script ?

I know a solution using ability level check, but it is inconvenient because I have to go through and check the whole list of them, and in my map there are hundreds of skills.

In my map a unit gets a random set of abilities, (like Ability Draft in dota), so there is no way to know in advance.
 

Uncle

Warcraft Moderator
Level 65
Joined
Aug 10, 2018
Messages
6,682
Hello guys, is there any easy way to get a list of hero's abilities using GUI or script ?

I know a solution using ability level check, but it is inconvenient because I have to go through and check the whole list of them, and in my map there are hundreds of skills.

In my map a unit gets a random set of abilities, (like Ability Draft in dota), so there is no way to know in advance.
Hello, so whenever you add a random ability to a Hero you should store the abilities Integer Id in a Hashtable. The Hero would be the Parent key and the Child keys will range from 1 to however many abilities the Hero can have. Then you can access that whenever you want. If each Player only controls one Hero then it'd make more sense to use the Player's Number as the Parent key since this gives you quick and easy access from any trigger.

So you would implement these Actions into your trigger that runs when your Hero receives a new ability:
  • Actions
    • Set Variable The_Ability = (The new ability that was chosen)
    • Set Variable Hero = (The hero learning the new ability)
    • Set Variable PN = (Player number of (Owner of Hero))
    • Set Variable X = (The ability index - if it's your first ability then it'd be set to 1)
    • Custom script: set udg_Ability_Id = udg_The_Ability
    • Hashtable - Save Ability_Id as X of PN in Hero_Ability_Hashtable
Ability_Id is an Integer variable. The_Ability is an Ability Code variable. PN and X are Integers.

You can use that Custom Script to convert the Ability Code into it's Integer form.

Also, Hashtables need to be initialized before any of this happens:
  • Events
    • Time - Elapsed game time is 0.00 seconds
  • Conditions
  • Actions
    • Hashtable - Create a hashtable
    • Set Variable Hero_Ability_Hashtable = (Last created hashtable)
When loading the Ability Id from the Hashtable you would use the Custom Script trick again, but this time reverse it to convert the Integer into an Ability Code:
  • Set Variable Ability_Id = (Load X of PN from Hero_Ability_Hashtable)
  • Custom script: set udg_The_Ability = Ability_Id
  • // we now have the ability!
 
Last edited:
Level 2
Joined
Apr 2, 2023
Messages
3
Wow, thanks for such a quick reply, I was thinking about something like that, but it's complicated by the fact that units also have standard abilities, so I can't always keep track of when a unit gets a new ability, but I would like to get a list of all abilities, including those that were there when the unit was created.

I mean now I have to manually write lists of abilities for each type of unit + what you described at the moment of getting a new ability, and in my map there are also a lot of types of units.

I thought maybe there is some object or array that contains Id or names of unit abilities and it could be read by a script that is not available through GUI.
 

Uncle

Warcraft Moderator
Level 65
Joined
Aug 10, 2018
Messages
6,682
Wow, thanks for such a quick reply, I was thinking about something like that, but it's complicated by the fact that units also have standard abilities, so I can't always keep track of when a unit gets a new ability, but I would like to get a list of all abilities, including those that were there when the unit was created.

I mean now I have to manually write lists of abilities for each type of unit + what you described at the moment of getting a new ability, and in my map there are also a lot of types of units.

I thought maybe there is some object or array that contains Id or names of unit abilities and it could be read by a script that is not available through GUI.
Unfortunately not, but you should probably already have an Array of all of your abilities, at least that'd make your life a lot easier. I hope you don't have like 1 trigger per ability, that'd be a nightmare to manage and a lot of unnecessary work. 2 to 3 triggers can manage ALL of the abilities assuming you've got Arrays of the necessary data.
 
Level 18
Joined
Oct 17, 2012
Messages
826
If you are on the live patch, you can use BlzGetUnitAbilityByIndex(unit, index) to get all abilities of a unit. Now, the function returns a value of type ability. To convert ability to integer id, use BlzGetAbilityId(ability).

JASS:
function PrintUnitAbilities takes unit u returns nothing
    local integer i = 0
    local ability a
    loop
        set a = BlzGetUnitAbilityByIndex(u, i)
        exitwhen (a == null)
        call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 5, GetAbilityName(BlzGetAbilityId(a)))
        set i = i + 1
    endloop
endfunction
 
Last edited:
Top