1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still haven't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. Join the 6th Melee Mapping Contest for a chance to have your map featured in this year's Hive Cup!
    Dismiss Notice
  4. Shoot to thrill, play to kill. Sate your hunger with the 33rd Modeling Contest!
    Dismiss Notice
  5. Do you hear boss music? It's the 17th Mini Mapping Contest!
    Dismiss Notice
  6. Weave light to take you to your highest hopes - the 6th Special Effect Contest is here!
    Dismiss Notice
  7. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[Solved] BlzUnitHideAbility sometimes not working

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

Tags:
  1. loktar

    loktar

    Model Reviewer

    Joined:
    Nov 2, 2004
    Messages:
    1,151
    Resources:
    38
    Models:
    15
    Icons:
    16
    Packs:
    1
    Tools:
    3
    Spells:
    2
    Tutorials:
    1
    Resources:
    38
    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,471
    Resources:
    8
    Models:
    1
    Icons:
    2
    Maps:
    1
    Spells:
    3
    JASS:
    1
    Resources:
    8
    Is unit u captured within the function HideAbil? Perhaps posting the full script may give a clue.
     
  3. loktar

    loktar

    Model Reviewer

    Joined:
    Nov 2, 2004
    Messages:
    1,151
    Resources:
    38
    Models:
    15
    Icons:
    16
    Packs:
    1
    Tools:
    3
    Spells:
    2
    Tutorials:
    1
    Resources:
    38
    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,471
    Resources:
    8
    Models:
    1
    Icons:
    2
    Maps:
    1
    Spells:
    3
    JASS:
    1
    Resources:
    8
    I assume it has something to do with your page1 variable in SetupCtrls. Try debugging its' value
     
  5. loktar

    loktar

    Model Reviewer

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