[Solved] UnitAddAbility() returns false Why ?

Status
Not open for further replies.
Level 11
Joined
Jan 2, 2016
Messages
472
JASS:
function Trig_HeroLearnAbilities_Actions takes nothing returns nothing
       local unit u = GetTriggerUnit()
       local integer playerID = GetPlayerId(GetOwningPlayer(u))
       local integer whichAbi
       local integer learnedAbi = GetLearnedSkill()
       local integer curLevel = GetUnitAbilityLevel(u, learnedAbi)
       local integer loadAbiId
       if learnedAbi == 'A004' then
           set whichAbi = 0
       elseif learnedAbi == 'A005' then
           set whichAbi = 1
       elseif learnedAbi == 'A006' then
           set whichAbi = 2
       elseif learnedAbi == 'A003' then
           set whichAbi = 3
       endif
       set loadAbiId = LoadInteger(udg_HeroAbilities, playerID, whichAbi)
       call UnitAddAbility(u, loadAbiId)
       //call SetUnitAbilityLevel(u, loadAbiId, curLevel)

       set u = null
       
endfunction

The action is called by the EVENT_PLAYER_HERO_SKILL.

What's wrong ? Well the UnitAddAbility(...) returns false for reasons unknown.Printing the unit's name and the ability's name ( loadAbiId ) works fine.

I may have missed something simple though. If you need more information about this please tell me.
 
AFAIK, when UnitAddAbility returns false it means that the ability couldn't be added to the unit. As far as I know, the only reason why is because the unit already has this ability, so it can't be added again.

That, and if the ability cannot be included for some reason, like removing attack and adding it again ('Aatk'). In any case, try checking if the ability exists through the GetUnitAbilityLevel native. Here's a wrapper for a unit has ability function (redundant).

JASS:
function UnitHasAbilityEx takes unit u, integer abilId returns boolean
    return UnitAddAbility(u, abilId) or GetUnitAbilityLevel(u, abilId) != 0
endfunction
 
Level 11
Joined
Jan 2, 2016
Messages
472
It seems that the ability level is 0.

And one more thing.I can add the standard spells via UnitAddAbility(...) but not the custom ones.

EDIT#1: Even setting these abilities for hero to learn won't work.

EDIT#2: This is solved and it was pretty simple.According to DSG you can't add hero abilites with the current native.I changed them to unit ones and everything went well.
 
Last edited:
Status
Not open for further replies.
Top