HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Leveling abilities inside spellbooks is.. impossible?

11-06-2010, 11:01 PM#1
Ignitedstar
Can I get some help here, please?

I'm having major problems when it comes to increasing the level of abilities when they're inside spellbooks. The Paladin in my map actually has the spell book. I did some research and the only relevant thing I can find was this thread. In it, fX_ says GetUnitAbilityLevel() does not work for abilities that are inside of spellbooks. However, Tide-Arc Ephemera claims that GetUnitAbilityLevel() does work for abilities for spellbooks.

This is the trigger I'm using to upgrade the spells. The spells upgrade as certain researches are upgraded:
Collapse JASS:
scope PaladinAbilities initializer Init

private function Conditions takes nothing returns boolean
    return true //I may need this, so it stays blank
endfunction

private function TriggerActions takes nothing returns nothing
    local unit c = GetLearningUnit()
    local player p = GetOwningPlayer(c)
    local integer id = GetResearched()
    local integer i
    if id == 'R000' then
        set i = GetUnitAbilityLevel(c, 'AHhb')
        call BJDebugMsg(I2S(i))
        call SetUnitAbilityLevel(c, 'AHhb', i+1)
    elseif id == 'R001' then
        set i = GetUnitAbilityLevel(c, 'AHad')
        call BJDebugMsg(I2S(i))
        call SetUnitAbilityLevel(c, 'AHad', i+1)
    elseif id == 'R002' then
        set i = GetUnitAbilityLevel(c, 'AHds')
        call BJDebugMsg(I2S(i))
        call SetUnitAbilityLevel(c, 'AHds', i+1)
    elseif id == 'R003' then
        set i = GetUnitAbilityLevel(c, 'AHre')
        call BJDebugMsg(I2S(i))
        call SetUnitAbilityLevel(c, 'AHre', i+1)
    endif
    set c = null
    set p = null
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    local trigger P = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(P, EVENT_PLAYER_UNIT_RESEARCH_FINISH)
    call TriggerAddAction(P, function TriggerActions)
    call TriggerAddCondition(P, Condition(function Conditions))
endfunction

endscope

I really don't know Tide got this to work. When I use BJDebugMsg to discover whether or not GetUnitAbilityLevel() returns the ability of 'AHhb'-- or Holy Light, BJDebugMsg returns zero. The same thing happens for Devotion Aura, Divine Shield, Resurrection, and most likely whatever other ability I try this on.

I know that this works if I remove the abilities from the spellbook, but I can't do that for what I want. Every hero needs to be able to have about 15+ abilities that they can learn so players have to choose which skills their hero knows because you can't learn everything. The hero learning skill card can only hold 11 abilities and it's even more severely limited because a hero can only have five actual hero abilities.

I thought I could work around this easily by trying by just getting the level of the researched... research (lol). Much to my dismay however, there's no function for that! There's only the function GetPlayerTechResearched() which returns a boolean, not an integer... Unless there's some whacko way to use this so that you can get an integer, but I am really doubting it.

My last alternative is to make individual upgrades for each and every level of every ability... Uugh, god. I'll have to make about 100+ upgrades per hero... PLEASE tell me I don't have to resort to that.
11-06-2010, 11:54 PM#2
Switch33
Collapse JASS:
GetPlayerTechCount(whichPlayer, techid, specificonly)
This will return the level of the researched Tech.

As for upgrading the ability you may want to consider upgrading spellbook levels? hmm. . .

Ah i got it. Disable the spell. Then Set the level. Then Enable the spell.
11-07-2010, 12:06 AM#3
Ignitedstar
Ah, SALVATION!

You saved me. I love you, Switch.

EDIT: Watching you edit your post.

I don't need to disable anything. Using GetPlayerTechCount, I can set the level of any ability using its respective upgrade, and ta-dah! No more work involved. Which is effective and efficient. Yay!

Finished Code:

Collapse JASS:
scope PaladinAbilities initializer Init

globals
    unit Paladin = gg_unit_Hpal_0000
endglobals

private function Conditions takes nothing returns boolean
    return true //I might need this, so it stays blank
endfunction

private function TriggerActions takes nothing returns nothing
    local unit c = Paladin
    local player p = GetOwningPlayer(c)
    local integer id = GetResearched()
    local integer i = GetPlayerTechCount(p, id, true)
    if id == 'R000' then
        call SetUnitAbilityLevel(c, 'AHhb', i)
    elseif id == 'R001' then
        call SetUnitAbilityLevel(c, 'AHad', i)
    elseif id == 'R002' then
        call SetUnitAbilityLevel(c, 'AHds', i)
    elseif id == 'R003' then
        call SetUnitAbilityLevel(c, 'AHre', i)
    endif
    set c = null
    set p = null
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    local trigger P = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(P, EVENT_PLAYER_UNIT_RESEARCH_FINISH)
    call TriggerAddAction(P, function TriggerActions)
    call TriggerAddCondition(P, Condition(function Conditions))
endfunction

endscope
11-07-2010, 12:17 AM#4
Switch33
Nice. I got the disable/enable idea from a dota thread just randomly on a google search. As for the native you should check out wc3 jass vault's common.j every now and then for finding functions. Sometimes it's easier to find what your looking for.

Btw are you working on that hero arena you made a post on in the general development area?
11-07-2010, 12:20 AM#5
Ignitedstar
I suppose now that Tide wasn't saying that it worked; he just found a work-around which does the exact same thing.