1. The contestants were to create water structures for the 20th Terraining Contest. Choose one in the public poll!
    Dismiss Notice
  2. Join other hivers in a friendly concept-art contest. The contestants have to create a genie coming out of its container. We wish you the best of luck!
    Dismiss Notice
  3. The Melee Mapping Contest #4: 2v2 - Results are out! Step by to congratulate the winners!
    Dismiss Notice
  4. We're hosting the 15th Mini-Mapping Contest with YouTuber Abelhawk! The contestants are to create a custom map that uses the hidden content within Warcraft 3 or is inspired by any of the many secrets within the game.
    Dismiss Notice
  5. Check out the Staff job openings thread.
    Dismiss Notice

[Solved] BlzUnitHideAbility sometimes not working

Discussion in 'Triggers & Scripts' started by loktar, May 1, 2019.

Tags:
  1. loktar

    loktar

    Joined:
    Nov 2, 2004
    Messages:
    715
    Resources:
    24
    Models:
    2
    Icons:
    16
    Packs:
    1
    Tools:
    2
    Spells:
    2
    Tutorials:
    1
    Resources:
    24
    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.

    Code (vJASS):

    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: May 1, 2019
  2. MyPad

    MyPad

    Spell Reviewer

    Joined:
    May 9, 2014
    Messages:
    1,244
    Resources:
    6
    Models:
    1
    Icons:
    1
    Spells:
    3
    JASS:
    1
    Resources:
    6
    Is unit u captured within the function HideAbil? Perhaps posting the full script may give a clue.
     
  3. loktar

    loktar

    Joined:
    Nov 2, 2004
    Messages:
    715
    Resources:
    24
    Models:
    2
    Icons:
    16
    Packs:
    1
    Tools:
    2
    Spells:
    2
    Tutorials:
    1
    Resources:
    24
    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: May 1, 2019
  4. MyPad

    MyPad

    Spell Reviewer

    Joined:
    May 9, 2014
    Messages:
    1,244
    Resources:
    6
    Models:
    1
    Icons:
    1
    Spells:
    3
    JASS:
    1
    Resources:
    6
    I assume it has something to do with your page1 variable in SetupCtrls. Try debugging its' value
     
  5. loktar

    loktar

    Joined:
    Nov 2, 2004
    Messages:
    715
    Resources:
    24
    Models:
    2
    Icons:
    16
    Packs:
    1
    Tools:
    2
    Spells:
    2
    Tutorials:
    1
    Resources:
    24
    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:

    Code (vJASS):

    // 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: May 1, 2019