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

[Solved] BlzUnitHideAbility sometimes not working

Status
Not open for further replies.
There's something weird (not) happening. BlzUnitHideAbility and BlzUnitDisableAbility are not working in certain cases.

The calls to SetupCtrls in the initializer work as expected.

When ButtonControlCndAcn is triggered (SPELL_CAST event) to "OPEN", CTRL_SFX and CTRL_CAM are not hidden as they should be, but the other abilities are shown as expected.
If I do BlzUnitHideAbility(MVUnit, CTRL_SFX, true/false) in ButtonControlCndAcn itself instead, they are shown/hidden as expected.

When ButtonControlCndAcn is triggered (SPELL_CAST event) to "NEXT PAGE", abilities that should be hidden are hidden, but the ones that should be shown are not.

JASS:
library ModelViewer initializer InitModelViewer
    globals
        private constant integer CTRL_SFX = 'A004'
        private constant integer CTRL_CAM = 'A00J'
        private constant key     CTRL_OPEN
        private constant key     CTRL_OFF
        private unit        MVUnit
    endglobals

    private function SetupCtrls takes integer id, boolean close returns nothing
        local boolean page1 = (not close) and GetUnitAbilityLevel(MVUnit, id) == 1
 
        call BlzUnitHideAbility(MVUnit, CTRL_SFX, not close) // These aren't hidden when close == false
        call BlzUnitHideAbility(MVUnit, CTRL_CAM, not close) // But they are when called in the trigger func instead

        if id == CTRL_SFX then
            call BlzUnitHideAbility(MVUnit, 'A00N', not page1) // PosX
            call BlzUnitHideAbility(MVUnit, 'A00O', not page1) // PosY
            call BlzUnitHideAbility(MVUnit, 'A00Q', not page1) // PosZ
            call BlzUnitHideAbility(MVUnit, 'A00R', not page1) // Scale
            call BlzUnitHideAbility(MVUnit, 'A00S', not page1) // Roll
            call BlzUnitHideAbility(MVUnit, 'A00T', not page1) // Pitch
            call BlzUnitHideAbility(MVUnit, 'A00U', not page1) // Yaw
            call BlzUnitHideAbility(MVUnit, 'A00V', close or page1) // Alpha
            call BlzUnitHideAbility(MVUnit, 'A010', close or page1) // Color
     
        elseif id == CTRL_CAM then
            call BlzUnitHideAbility(MVUnit, 'A007', not page1) // PosX
            call BlzUnitHideAbility(MVUnit, 'A003', not page1) // PosY
            call BlzUnitHideAbility(MVUnit, 'A00E', not page1) // PosZ
            call BlzUnitHideAbility(MVUnit, 'A00D', not page1) // Distance
            call BlzUnitHideAbility(MVUnit, 'A00C', not page1) // Rotation
            call BlzUnitHideAbility(MVUnit, 'A000', not page1) // AoA
            call BlzUnitHideAbility(MVUnit, 'A00B', not page1) // Roll
            call BlzUnitHideAbility(MVUnit, 'A006', close or page1) // FoV
            call BlzUnitHideAbility(MVUnit, 'A005', close or page1) // FarZ
        endif
    endfunction
    //=========
 
    //==== Button Control ====
    private function ButtonControlCndAcn takes nothing returns boolean
        local integer spellId = GetSpellAbilityId()
        local integer id
 
        // OPEN
        if spellId == CTRL_SFX or spellId == CTRL_CAM then
            call UnitRemoveAbility(MVUnit, 'A00H') // Apply Cam
            call UnitRemoveAbility(MVUnit, 'A00A') // Save Cam
            call UnitRemoveAbility(MVUnit, 'A00G') // Delete Cam
            call UnitRemoveAbility(MVUnit, 'A008') // Mouse Controls
 
            call SetupCtrls(spellId, false)
            call UnitAddAbility(MVUnit, 'A009') // Increase
            call UnitAddAbility(MVUnit, 'A00M') // Decrease
            call UnitAddAbility(MVUnit, 'A00L') // Reset
            call UnitAddAbility(MVUnit, 'A00P') // Page
            call UnitAddAbility(MVUnit, 'A00I') // Back
  
            call SaveInteger(htbToggles, CTRL_OPEN, 0, spellId)

        // CLOSE
        elseif spellId == 'A00I' then
            call UnitRemoveAbility(MVUnit, 'A009') // Increase
            call UnitRemoveAbility(MVUnit, 'A00M') // Decrease
            call UnitRemoveAbility(MVUnit, 'A00L') // Reset
            call UnitRemoveAbility(MVUnit, 'A00P') // Page
            call UnitRemoveAbility(MVUnit, 'A00I') // Back
            call SetupCtrls(LoadInteger(htbToggles, CTRL_OPEN, 0), true)

            call UnitAddAbility(MVUnit, 'A00H') // Apply Cam
            call UnitAddAbility(MVUnit, 'A00A') // Save Cam
            call UnitAddAbility(MVUnit, 'A00G') // Delete Cam
            call UnitAddAbility(MVUnit, 'A008') // Mouse Controls

            call SaveInteger(htbToggles, CTRL_OPEN, 0, CTRL_OFF)

        // NEXT PAGE
        elseif spellId == 'A00P' then
            set id = LoadInteger(htbToggles, CTRL_OPEN, 0)
            if GetUnitAbilityLevel(MVUnit, id) == 1 then
                call SetUnitAbilityLevel(MVUnit, id, 2)
            else
                call SetUnitAbilityLevel(MVUnit, id, 1)
            endif
            call SetupCtrls(id, false)
       endif
       return false
    endfunction

    private function InitModelViewer takes nothing returns nothing
            set MVUnit = gg_unit_hhou_0002
      
            call SaveInteger(htbToggles, CTRL_OPEN, 0, CTRL_OFF)
            call SetupCtrls(CTRL_SFX, true)
            call SetupCtrls(CTRL_CAM, true)
    endfunction
endlibrary
 
Last edited:
I've updated the original post with the relevant parts copied from my script. The unit variable is assigned in the library initializer, from a generated global.

Edit: the other "erratic behaviour" of hiding/showing abilities was because of an oversight on my part. The main issue remains, but I guess I can just leave it in the second function.

Edit: I've added some more code, the NEXT PAGE part, which also isn't working as expected :(
 
Last edited:
I did, it's always either 1 or 2, as it's supposed to be. (edit: I meant the ability level, I will test the page1 value separately) I don't think it would have any effect on the function calls outside the if statement anyway.
I also debugged the value of close or page1 and it's always what I expect it to be, yet the two "page 2" abilities aren't unhidden.
When I go back to "page 1", those abilities aren't unhidden either, even though they are each time CTRL_SFX or CTRL_CAM are used when the next-page ability is never used.

Edit: (solved)
Turns out, when you hide an ability that's already hidden, it's actually "double" hidden. You will need to unhide it twice. And vice versa.
I assume the same is true for whichever number of times you do this.
Example:

JASS:
// a will be visible
call BlzUnitHideAbility(u, a, false)
call BlzUnitHideAbility(u, a, true)

// a will still be hidden
call BlzUnitHideAbility(u, a, false)
call BlzUnitHideAbility(u, a, false)
call BlzUnitHideAbility(u, a, true)

// a will be visible
call BlzUnitHideAbility(u, a, false)
call BlzUnitHideAbility(u, a, false)
call BlzUnitHideAbility(u, a, true)
call BlzUnitHideAbility(u, a, true)

// Other way around:

// a will be hidden
call BlzUnitHideAbility(u, a, true)
call BlzUnitHideAbility(u, a, false)

// a will still be visible
call BlzUnitHideAbility(u, a, true)
call BlzUnitHideAbility(u, a, true)
call BlzUnitHideAbility(u, a, false)

// a will be hidden
call BlzUnitHideAbility(u, a, true)
call BlzUnitHideAbility(u, a, true)
call BlzUnitHideAbility(u, a, false)
call BlzUnitHideAbility(u, a, false)

An explanation by IcemanBo is here.


Edit: I could've avoided this whole mess by just adding/removing all the abilities -_- I'm pretty sure there was a reason I didn't, but I can't remember what, and it doesn't apply anymore (or never did).
Edit: ok yeah, there's a serious lag spike when add/removing that many abilities
 
Last edited:
Status
Not open for further replies.
Top