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

[vJASS] [System Extension] ArrowKeyEvent PlayerRegistry

An extension to [System] ArrowKeyEvent.
Check out that thread for its features as I will talk about this extensions feature here.

Just import this extention to your map and it will be auto implemented into any struct that you use the latest update of Bribes [System] ArrowKeyEvent syetem with.
(this will not be directly useable to the public untill Bribe updates his system)

JASS:
library ArrowKeyPlayerEnabled /* v2.0.0.0, created by SA Dashie, Advice from IcemanBo with simplifying further
    
    */ uses /*
        
        */ ArrowKeyEvent /*      http://www.hiveworkshop.com/forums/jass-resources-412/system-arrowkeyevent-205650/
    
    Description
        
        Extra for the ArrowKeyEvent system by Bribe.
        
        Adds a condition if the the player index is enabled.
        
        Just import this extention to your map and it will be auto 
        implemented into any struct that you use the latest update
        of Bribes [System] ArrowKeyEvent syetem with.
        
    Fields
        
        boolean enabled
            - is false by default
        
        static boolean enabledAll

*/

    //! textmacro ARROW_KEY_CONDITION_VARIABLE
        boolean enabled
        
        static boolean enabledAll = true
    //! endtextmacro
    
    //! textmacro ARROW_KEY_CONDITION_ITE
        if not (enabledAll and thistype(.eventPlayerId).canPlayerPass) then
            return
        endif
    //! endtextmacro

endlibrary

JASS:
library ArrowTest uses ArrowKeyEvent, ArrowKeyPlayerEnabled
   
    struct ArrowTest extends array
       
        private static method onArrowKeyEvent takes integer arrow, boolean pressed returns nothing
            call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, GetPlayerName(Player(eventPlayerId)) + " enabled test")
            call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "//--")
           
            call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "Setting enabledAll to false")
           
            call enabledAll = false
        endmethod
       
        private static method onInit takes nothing returns nothing
            call thistype[Player(0)].Enabled = true
           
            call thistype(2).Enabled = true
        endmethod
       
        implement ArrowKey
       
    endstruct
   
endlibrary


An extension to [System] ArrowKeyEvent.
Check out that thread for its features as I will talk about this extensions feature here.

Allows players to be removed and added to any arrow key event system with the use of implementing this module and Bribes [System] ArrowKeyEvent in appropriate structs.

JASS:
/* Created by DeathChef

    module ArrowKeyEvent_PlayerRegister v1.0.0.0
     
        Description
         
            Extension of Bribes [System] ArrowKeyEvent
         
            Allows players to be removed and added to any arrow
            key event system with the use of implementing this
            module and Bribes [System] ArrowKeyEvent
     
     
        Use with
         
            [System] ArrowKeyEvent      [url]http://www.hiveworkshop.com/forums/jass-resources-412/system-arrowkeyevent-205650/[/url]
     
     
        Methods
         
            static method AddArrowKeysPlayerId takes thistype PlayerId returns nothing
            static method RemoveArrowKeysPlayerId takes thistype PlayerId returns nothing
         
            static method AddArrowKeysAllPlayers takes nothing returns nothing
            static method RemoveArrowKeysAllPlayers takes nothing returns nothing
         
         
        Fields
         
            boolean IsPlayerRegistered
         
         
        How to use
         
            Check out the demo for a code example
         
            1. Implement ArrowKeyEvent_PlayerRegister along side with the ArrowKey module
         
            2. Within your onArrowKeyEvent method create as the first ITE line as
                if thistype(.eventPlayerId).IsPlayerRegistered then
                    //code body
                endif
         
            3. Use the custom methods that come with the module

*/

module ArrowKeyEvent_PlayerRegister
 
    boolean IsPlayerRegistered
 
    static method AddArrowKeysPlayerId takes thistype PlayerId returns nothing
     
        set PlayerId.IsPlayerRegistered = GetPlayerSlotState(Player(PlayerId)) == PLAYER_SLOT_STATE_PLAYING and GetPlayerController(Player(PlayerId)) == MAP_CONTROL_USER
    endmethod
 
    static method RemoveArrowKeysPlayerId takes thistype PlayerId returns nothing
     
        set PlayerId.IsPlayerRegistered = false
    endmethod
 
    static method AddArrowKeysAllPlayers takes nothing returns nothing
        local thistype this = 11
     
        loop
            set IsPlayerRegistered = GetPlayerSlotState(Player(this)) == PLAYER_SLOT_STATE_PLAYING and GetPlayerController(Player(this)) == MAP_CONTROL_USER
         
            exitwhen this == 0
         
            set this = this - 1
        endloop
    endmethod
 
    static method RemoveArrowKeysAllPlayers takes nothing returns nothing
        local thistype this = 11
     
        loop
            set IsPlayerRegistered = false
         
            exitwhen this == 0
         
            set this = this - 1
        endloop
    endmethod
 
endmodule

JASS:
library tester uses ArrowKeyEvent
 
    struct tester extends array
     
        method onArrowKeyEvent takes integer arrow, boolean pressed returns nothing
         
            if thistype(.eventPlayerId).IsPlayerRegistered then
             
                static if LIBRARY_ArrowKey then
                    call BJDebugMsg("Axis Focus: X: " + .getKeyName(thistype(0).getAxisKey(ARROW_KEY_X_AXIS)) + ", Y: " + .getKeyName(thistype(0).getAxisKey(ARROW_KEY_Y_AXIS)))
                elseif DEBUG_MODE then
                    if pressed then
                        call BJDebugMsg("Key pressed: " + .getKeyName(arrow))
                    else
                        call BJDebugMsg("Key released: " + .getKeyName(arrow))
                    endif
                endif
             
            endif
        endmethod
     
        static method onInit takes nothing returns nothing
         
            call AddArrowKeysAllPlayers()
        endmethod
     
        implement ArrowKeyEvent_PlayerRegister
     
        implement ArrowKey
     
    endstruct
 
endlibrary



Implement this module into a struct that you want to use Arrow Key Events for.
  • Register and Unregister individual (or all players at once) players. This snippet allows different players to use different key events at the same time
  • Just code the method into your struct for each individual arrow key event

Check out description inside the trigger for how to use this.
Check out the demo for an example of how to use this.

JASS:
module ArrowEvents /* v2.0.0.0, created by DeathChef

    Description
     
        Basic module for registering the arrow key events to
        individual methods
     
        Can register and unregister players arrow keys
     
        If a key event static method does not exist then code
        will not contain errors
     
     
    Fields
     
        boolean IsRegistered
     
        //If a User Defined Method does not exist
        //the corresponding field neither will
     
        trigger PressUp
        trigger PressDown
        trigger PressLeft
        trigger PressRight
     
        trigger ReleaseUp
        trigger ReleaseDown
        trigger ReleaseLeft
        trigger ReleaseRight
     
        triggeraction ActionPressUp
        triggeraction ActionPressDown
        triggeraction ActionPressLeft
        triggeraction ActionPressRight
     
        triggeraction ActionReleaseUp
        triggeraction ActionReleaseDown
        triggeraction ActionReleaseLeft
        triggeraction ActionReleaseRight
     
     
    Methods
     
        static method AddArrowKeysPlayerId takes thistype PlayerId returns nothing
        static method RemoveArrowKeysPlayerId takes thistype PlayerId returns nothing
     
        static method AddArrowKeysAllPlayers takes nothing returns nothing
        static method RemoveArrowKeysAllPlayers takes nothing returns nothing
     
     
    User Defined Methods
     
        static method UpPress takes nothing returns nothing
        static method DownPress takes nothing returns nothing
        static method LeftPress takes nothing returns nothing
        static method RightPress takes nothing returns nothing
     
        static method UpRelease takes nothing returns nothing
        static method DownRelease takes nothing returns nothing
        static method LeftRelease takes nothing returns nothing
        static method RightRelease takes nothing returns nothing
     
     
    How to use
     
        Check out the demo code for example
     
        1. Copy and paste this whole library into your map in a
           unique trigger
        
        2. Implement ArrowEvents at the bottom of your desired struct
         
        3. Create onInit static method
         
            private static method onInit takes nothing returns nothing
                call AddArrowKeysAllPlayers()
                //or
                call AddArrowKeysPlayerId(PlayerId)
            endmethod
     
        3. Code and use any of these static methods into your struct code
         
            static method UpPress takes nothing returns nothing
            static method DownPress takes nothing returns nothing
            static method LeftPress takes nothing returns nothing
            static method RightPress takes nothing returns nothing
         
            static method UpRelease takes nothing returns nothing
            static method DownRelease takes nothing returns nothing
            static method LeftRelease takes nothing returns nothing
            static method RightRelease takes nothing returns nothing
     
        4. Use other methods or/and create body of code for arrow keys

*/
 
    boolean IsRegistered
 
    static if thistype.UpPress.exists then
        private trigger PressUp
        private triggeraction ActionPressUp
    endif
    static if thistype.DownPress.exists then
        private trigger PressDown
        private triggeraction ActionPressDown
    endif
    static if thistype.LeftPress.exists then
        private trigger PressLeft
        private triggeraction ActionPressLeft
    endif
    static if thistype.RightPress.exists then
        private trigger PressRight
        private triggeraction ActionPressRight
    endif
 
    static if thistype.UpRelease.exists then
        private trigger ReleaseUp
        private triggeraction ActionReleaseUp
    endif
    static if thistype.DownRelease.exists then
        private trigger ReleaseDown
        private triggeraction ActionReleaseDown
    endif
    static if thistype.LeftRelease.exists then
        private trigger ReleaseLeft
        private triggeraction ActionReleaseLeft
    endif
    static if thistype.RightRelease.exists then
        private trigger ReleaseRight
        private triggeraction ActionReleaseRight
    endif
 
 
    static method AddArrowKeysPlayerId takes thistype PlayerId returns nothing
     
        if not PlayerId.IsRegistered and GetPlayerSlotState(Player(PlayerId)) == PLAYER_SLOT_STATE_PLAYING and GetPlayerController(Player(PlayerId)) == MAP_CONTROL_USER then
         
            set PlayerId.IsRegistered = true
         
            static if thistype.UpPress.exists then
                set PlayerId.ActionPressUp = TriggerAddAction(PlayerId.PressUp, function thistype.UpPress)
            endif
            static if thistype.DownPress.exists then
                set PlayerId.ActionPressDown = TriggerAddAction(PlayerId.PressDown, function thistype.DownPress)
            endif
            static if thistype.LeftPress.exists then
                set PlayerId.ActionPressLeft = TriggerAddAction(PlayerId.PressLeft, function thistype.LeftPress) 
            endif
            static if thistype.RightPress.exists then
                set PlayerId.ActionPressRight = TriggerAddAction(PlayerId.PressRight, function thistype.RightPress)
            endif
         
            static if thistype.UpRelease.exists then
                set PlayerId.ActionReleaseUp = TriggerAddAction(PlayerId.ReleaseUp, function thistype.UpRelease)
            endif
            static if thistype.DownRelease.exists then
                set PlayerId.ActionReleaseDown = TriggerAddAction(PlayerId.ReleaseDown, function thistype.DownRelease)
            endif
            static if thistype.LeftRelease.exists then
                set PlayerId.ActionReleaseLeft = TriggerAddAction(PlayerId.ReleaseLeft, function thistype.LeftRelease)
            endif
            static if thistype.RightRelease.exists then
                set PlayerId.ActionReleaseRight = TriggerAddAction(PlayerId.ReleaseRight, function thistype.RightRelease)
            endif
     
        endif
     
    endmethod
 
    static method RemoveArrowKeysPlayerId takes thistype PlayerId returns nothing
     
        if PlayerId.IsRegistered then
         
            set PlayerId.IsRegistered = false
         
            static if thistype.UpPress.exists then
                call TriggerRemoveAction(PlayerId.PressUp, PlayerId.ActionPressUp)
            endif
            static if thistype.DownPress.exists then
                call TriggerRemoveAction(PlayerId.PressDown, PlayerId.ActionPressDown)
            endif
            static if thistype.LeftPress.exists then
                call TriggerRemoveAction(PlayerId.PressLeft, PlayerId.ActionPressLeft)
            endif
            static if thistype.RightPress.exists then
                call TriggerRemoveAction(PlayerId.PressRight, PlayerId.ActionPressRight)
            endif
         
            static if thistype.UpRelease.exists then
                call TriggerRemoveAction(PlayerId.ReleaseUp, PlayerId.ActionReleaseUp)
            endif
            static if thistype.DownRelease.exists then
                call TriggerRemoveAction(PlayerId.ReleaseDown, PlayerId.ActionReleaseDown)
            endif
            static if thistype.LeftRelease.exists then
                call TriggerRemoveAction(PlayerId.ReleaseLeft, PlayerId.ActionReleaseLeft)
            endif
            static if thistype.RightRelease.exists then
                call TriggerRemoveAction(PlayerId.ReleaseRight, PlayerId.ActionReleaseRight)
            endif
     
        endif
     
    endmethod
 
    static method AddArrowKeysAllPlayers takes nothing returns nothing
        local thistype this = 11
        local player p = Player(this)
     
        loop
            if GetPlayerSlotState(p) == PLAYER_SLOT_STATE_PLAYING and GetPlayerController(p) == MAP_CONTROL_USER then
             
                call AddArrowKeysPlayerId(this)
             
            endif
         
            exitwhen this == 0
         
            set this = this - 1
            set p = Player(this)
        endloop
     
        set p = null
    endmethod
 
    static method RemoveArrowKeysAllPlayers takes nothing returns nothing
        local thistype this = 11
        local player p = Player(this)
     
        loop
            if GetPlayerSlotState(p) == PLAYER_SLOT_STATE_PLAYING and GetPlayerController(p) == MAP_CONTROL_USER then
             
                call RemoveArrowKeysPlayerId(this)
             
            endif
         
            exitwhen this == 0
         
            set this = this - 1
            set p = Player(this)
        endloop
     
        set p = null
    endmethod
 
 
    private static method onInit takes nothing returns nothing
        local thistype this = 11
        local player p = Player(this)
     
        loop
            if GetPlayerSlotState(p) == PLAYER_SLOT_STATE_PLAYING and GetPlayerController(p) == MAP_CONTROL_USER then
             
                static if thistype.UpPress.exists then
                    set PressUp = CreateTrigger()
                    call TriggerRegisterPlayerEvent(PressUp, p, EVENT_PLAYER_ARROW_UP_DOWN)
                endif
                static if thistype.DownPress.exists then
                    set PressDown = CreateTrigger()
                    call TriggerRegisterPlayerEvent(PressDown, p, EVENT_PLAYER_ARROW_DOWN_DOWN)
                endif
                static if thistype.LeftPress.exists then
                    set PressLeft = CreateTrigger()
                    call TriggerRegisterPlayerEvent(PressLeft, p, EVENT_PLAYER_ARROW_LEFT_DOWN)
                endif
                static if thistype.RightPress.exists then
                    set PressRight = CreateTrigger()
                    call TriggerRegisterPlayerEvent(PressRight, p, EVENT_PLAYER_ARROW_RIGHT_DOWN)
                endif
             
                static if thistype.UpRelease.exists then
                    set ReleaseUp = CreateTrigger()
                    call TriggerRegisterPlayerEvent(ReleaseUp, p, EVENT_PLAYER_ARROW_UP_UP)
                endif
                static if thistype.DownRelease.exists then
                    set ReleaseDown = CreateTrigger()
                    call TriggerRegisterPlayerEvent(ReleaseDown, p, EVENT_PLAYER_ARROW_DOWN_UP)
                endif
                static if thistype.LeftRelease.exists then
                    set ReleaseLeft = CreateTrigger()
                    call TriggerRegisterPlayerEvent(ReleaseLeft, p, EVENT_PLAYER_ARROW_LEFT_UP)
                endif
                static if thistype.RightRelease.exists then
                    set ReleaseRight = CreateTrigger()
                    call TriggerRegisterPlayerEvent(ReleaseRight, p, EVENT_PLAYER_ARROW_RIGHT_UP)
                endif
         
            endif
         
            exitwhen this == 0
         
            set this = this - 1
            set p = Player(this)
        endloop
     
        set p = null
    endmethod
 
endmodule

JASS:
library ArrowKeyDemo
 
    struct ArrowKeyDemo extends array
     
        boolean UpPressed
     
        private static method UpPress takes nothing returns nothing
            set thistype[GetPlayerId(GetTriggerPlayer())].UpPressed = true
         
            call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "UpPress")
         
            //Function body
        endmethod
     
        private static method UpRelease takes nothing returns nothing
            set thistype[GetPlayerId(GetTriggerPlayer())].UpPressed = false
         
            call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "UpRelease")
         
            //Defunction body
        endmethod
     
     
        private static method LeftPress takes nothing returns nothing
         
            call RemoveArrowKeysPlayerId(GetPlayerId(GetTriggerPlayer()))
         
            //Defunction body
        endmethod
     
     
        private static method onInit takes nothing returns nothing
            call AddArrowKeysAllPlayers()
        endmethod
     
        implement ArrowEvents
     
    endstruct
 
endlibrary


JASS:
library ArrowEvents /* v1.1.0.0, created by DeathChef

    */ uses /*
 
        */ PlayerManager  /*
 
 
    module ArrowEvents
     
        Description
         
            Basic module for registering the arrow key events to
            individual methods
         
            Can register and unregister players arrow keys
         
            If a key event static method does not exist then code
            will not contain errors
         
         
        Fields
         
            boolean IsRegistered
         
            //If a User Defined Method does not exist
            //the corresponding field neither will
         
            trigger PressUp
            trigger PressDown
            trigger PressLeft
            trigger PressRight
         
            trigger ReleaseUp
            trigger ReleaseDown
            trigger ReleaseLeft
            trigger ReleaseRight
         
            triggeraction ActionPressUp
            triggeraction ActionPressDown
            triggeraction ActionPressLeft
            triggeraction ActionPressRight
         
            triggeraction ActionReleaseUp
            triggeraction ActionReleaseDown
            triggeraction ActionReleaseLeft
            triggeraction ActionReleaseRight
         
         
        Methods
         
            static method AddArrowKeysPlayerId takes thistype PlayerId returns nothing
            static method RemoveArrowKeysPlayerId takes thistype PlayerId returns nothing
         
            static method AddArrowKeysAllPlayers takes nothing returns nothing
            static method RemoveArrowKeysAllPlayers takes nothing returns nothing
         
         
        User Defined Methods
         
            static method UpPress takes nothing returns nothing
            static method DownPress takes nothing returns nothing
            static method LeftPress takes nothing returns nothing
            static method RightPress takes nothing returns nothing
         
            static method UpRelease takes nothing returns nothing
            static method DownRelease takes nothing returns nothing
            static method LeftRelease takes nothing returns nothing
            static method RightRelease takes nothing returns nothing
         
         
        How to use
         
            Check out the demo code for example
         
            1. Copy and paste this whole library into your map in a
               unique trigger
            
            2. Implement ArrowEvents at the bottom of your desired struct
             
            3. Create onInit static method
             
                private static method onInit takes nothing returns nothing
                    call AddArrowKeysAllPlayers()
                    //or
                    call AddArrowKeysPlayerId(PlayerId)
                endmethod
         
            3. Code and use any of these static methods into your struct code
             
                static method UpPress takes nothing returns nothing
                static method DownPress takes nothing returns nothing
                static method LeftPress takes nothing returns nothing
                static method RightPress takes nothing returns nothing
             
                static method UpRelease takes nothing returns nothing
                static method DownRelease takes nothing returns nothing
                static method LeftRelease takes nothing returns nothing
                static method RightRelease takes nothing returns nothing
         
            4. Use other methods or/and create body of code for arrow keys

*/

    module ArrowEvents
     
        boolean IsRegistered
     
        static if thistype.UpPress.exists then
            trigger PressUp
            triggeraction ActionPressUp
        endif
        static if thistype.DownPress.exists then
            trigger PressDown
            triggeraction ActionPressDown
        endif
        static if thistype.LeftPress.exists then
            trigger PressLeft
            triggeraction ActionPressLeft
        endif
        static if thistype.RightPress.exists then
            trigger PressRight
            triggeraction ActionPressRight
        endif
     
        static if thistype.UpRelease.exists then
            trigger ReleaseUp
            triggeraction ActionReleaseUp
        endif
        static if thistype.DownRelease.exists then
            trigger ReleaseDown
            triggeraction ActionReleaseDown
        endif
        static if thistype.LeftRelease.exists then
            trigger ReleaseLeft
            triggeraction ActionReleaseLeft
        endif
        static if thistype.RightRelease.exists then
            trigger ReleaseRight
            triggeraction ActionReleaseRight
        endif
     
     
        static method AddArrowKeysPlayerId takes thistype PlayerId returns nothing
         
            if not PlayerId.IsRegistered and Human[PlayerId].get != null then
             
                set PlayerId.IsRegistered = true
             
                static if thistype.UpPress.exists then
                    set PlayerId.ActionPressUp = TriggerAddAction(PlayerId.PressUp, function thistype.UpPress)
                endif
                static if thistype.DownPress.exists then
                    set PlayerId.ActionPressDown = TriggerAddAction(PlayerId.PressDown, function thistype.DownPress)
                endif
                static if thistype.LeftPress.exists then
                    set PlayerId.ActionPressLeft = TriggerAddAction(PlayerId.PressLeft, function thistype.LeftPress) 
                endif
                static if thistype.RightPress.exists then
                    set PlayerId.ActionPressRight = TriggerAddAction(PlayerId.PressRight, function thistype.RightPress)
                endif
             
                static if thistype.UpRelease.exists then
                    set PlayerId.ActionReleaseUp = TriggerAddAction(PlayerId.ReleaseUp, function thistype.UpRelease)
                endif
                static if thistype.DownRelease.exists then
                    set PlayerId.ActionReleaseDown = TriggerAddAction(PlayerId.ReleaseDown, function thistype.DownRelease)
                endif
                static if thistype.LeftRelease.exists then
                    set PlayerId.ActionReleaseLeft = TriggerAddAction(PlayerId.ReleaseLeft, function thistype.LeftRelease)
                endif
                static if thistype.RightRelease.exists then
                    set PlayerId.ActionReleaseRight = TriggerAddAction(PlayerId.ReleaseRight, function thistype.RightRelease)
                endif
         
            endif
         
        endmethod
     
        static method RemoveArrowKeysPlayerId takes thistype PlayerId returns nothing
         
            if PlayerId.IsRegistered then
             
                set PlayerId.IsRegistered = false
             
                static if thistype.UpPress.exists then
                    call TriggerRemoveAction(PlayerId.PressUp, PlayerId.ActionPressUp)
                endif
                static if thistype.DownPress.exists then
                    call TriggerRemoveAction(PlayerId.PressDown, PlayerId.ActionPressDown)
                endif
                static if thistype.LeftPress.exists then
                    call TriggerRemoveAction(PlayerId.PressLeft, PlayerId.ActionPressLeft)
                endif
                static if thistype.RightPress.exists then
                    call TriggerRemoveAction(PlayerId.PressRight, PlayerId.ActionPressRight)
                endif
             
                static if thistype.UpRelease.exists then
                    call TriggerRemoveAction(PlayerId.ReleaseUp, PlayerId.ActionReleaseUp)
                endif
                static if thistype.DownRelease.exists then
                    call TriggerRemoveAction(PlayerId.ReleaseDown, PlayerId.ActionReleaseDown)
                endif
                static if thistype.LeftRelease.exists then
                    call TriggerRemoveAction(PlayerId.ReleaseLeft, PlayerId.ActionReleaseLeft)
                endif
                static if thistype.RightRelease.exists then
                    call TriggerRemoveAction(PlayerId.ReleaseRight, PlayerId.ActionReleaseRight)
                endif
         
            endif
         
        endmethod
     
        static method AddArrowKeysAllPlayers takes nothing returns nothing
            local thistype this = Human.first
         
            loop
                call AddArrowKeysPlayerId(this)
             
                set this = Human[this].next
                exitwhen Human[this].end
            endloop
        endmethod
     
        static method RemoveArrowKeysAllPlayers takes nothing returns nothing
            local thistype this = Human.first
         
            loop
                call RemoveArrowKeysPlayerId(this)
             
                set this = Human[this].next
                exitwhen Human[this].end
            endloop
        endmethod
     
     
        private static method onInit takes nothing returns nothing
            local thistype this = Human.first
            local player p

            loop
                set p = Human[this].get
             
                static if thistype.UpPress.exists then
                    set PressUp = CreateTrigger()
                    call TriggerRegisterPlayerEvent(PressUp, p, EVENT_PLAYER_ARROW_UP_DOWN)
                endif
                static if thistype.DownPress.exists then
                    set PressDown = CreateTrigger()
                    call TriggerRegisterPlayerEvent(PressDown, p, EVENT_PLAYER_ARROW_DOWN_DOWN)
                endif
                static if thistype.LeftPress.exists then
                    set PressLeft = CreateTrigger()
                    call TriggerRegisterPlayerEvent(PressLeft, p, EVENT_PLAYER_ARROW_LEFT_DOWN)
                endif
                static if thistype.RightPress.exists then
                    set PressRight = CreateTrigger()
                    call TriggerRegisterPlayerEvent(PressRight, p, EVENT_PLAYER_ARROW_RIGHT_DOWN)
                endif
             
                static if thistype.UpRelease.exists then
                    set ReleaseUp = CreateTrigger()
                    call TriggerRegisterPlayerEvent(ReleaseUp, p, EVENT_PLAYER_ARROW_UP_UP)
                endif
                static if thistype.DownRelease.exists then
                    set ReleaseDown = CreateTrigger()
                    call TriggerRegisterPlayerEvent(ReleaseDown, p, EVENT_PLAYER_ARROW_DOWN_UP)
                endif
                static if thistype.LeftRelease.exists then
                    set ReleaseLeft = CreateTrigger()
                    call TriggerRegisterPlayerEvent(ReleaseLeft, p, EVENT_PLAYER_ARROW_LEFT_UP)
                endif
                static if thistype.RightRelease.exists then
                    set ReleaseRight = CreateTrigger()
                    call TriggerRegisterPlayerEvent(ReleaseRight, p, EVENT_PLAYER_ARROW_RIGHT_UP)
                endif
             
                set this = Human[this].next
                exitwhen Human[this].end
            endloop
         
            set p = null
        endmethod
     
    endmodule
 
endlibrary
 
Last edited:
Level 13
Joined
Nov 7, 2014
Messages
571
It seems to me that "The way you like coding the arrow events" leads to code bloat.

JASS:
struct Foo 
    implement ArrowEvents
endstruct

struct Bar
    implement ArrowEvents
endstruct

The implement <module> statement "copy-pastes" the module, and you have a lot of script in the ArrowEvents module
which if implemented a few times would lead to a [generated] code bloat, slow jasshelper parsing/execution, slow map savings and
in the end slow map testing/development.

There's a module by Bribe (too lazy to look it up now) that does something similar, and I have a "bastardized" version:
JASS:
library OnKeyEvent

// An example of how to use the onkeyevent module:
//
// struct MyStruct extends array
//
//     private static method on_key takes player p, integer key, boolean is_down returns nothing
//         call BJDebugMsg(GetPlayerName(p))
//
//         if     key == KEY_LEFT and is_down then
//             call BJDebugMsg("key left down")
//
//         elseif key == KEY_LEFT then // and not is_down
//             call BJDebugMsg("key left up")
//
//
//         elseif key == KEY_RIGHT and is_down then
//             call BJDebugMsg("key right down")
//
//         elseif key == KEY_RIGHT then // and not is_down
//             call BJDebugMsg("key right up")
//
//
//         elseif key == KEY_UP and is_down then
//             call BJDebugMsg("key up down")
//
//         elseif key == KEY_UP  then // and not is_down
//             call BJDebugMsg("key up up")
//
//
//         elseif key == KEY_DOWN and is_down then
//             call BJDebugMsg("key down down")
//
//         elseif key == KEY_DOWN then // and not is_down
//             call BJDebugMsg("key down up")
//
//
//         elseif key == KEY_ESC then
//             call BJDebugMsg("esc key pressed")
//
//         endif
//
//     endmethod
//     implement onkeyevent
//
// endstruct

globals
    /* export */ constant integer KEY_LEFT  = 0
    /* export */ constant integer KEY_RIGHT = 1
    /* export */ constant integer KEY_DOWN  = 2
    /* export */ constant integer KEY_UP    = 3

    private constant integer MAX_PLAYERS = 12 // bj_MAX_PLAYERS
    // meant to be used inside a timer handler function / loop
    /* export */ boolean array is_player_key_down[MAX_PLAYERS][4]

    constant integer KEY_ESC   = 4
endglobals

private module OnKeyEvent
    static trigger arrow_key_trigger = CreateTrigger()
    static trigger esc_key_trigger   = CreateTrigger()
    static player  p
    static integer key
    static boolean is_down


    private static method on_arrow_key takes nothing returns boolean
        // EVENT_PLAYER_ARROW_LEFT_DOWN  = ConvertPlayerEvent(261) // 0
        // EVENT_PLAYER_ARROW_LEFT_UP    = ConvertPlayerEvent(262) // 1
        // EVENT_PLAYER_ARROW_RIGHT_DOWN = ConvertPlayerEvent(263) // 2
        // EVENT_PLAYER_ARROW_RIGHT_UP   = ConvertPlayerEvent(264) // 3
        // EVENT_PLAYER_ARROW_DOWN_DOWN  = ConvertPlayerEvent(265) // 4
        // EVENT_PLAYER_ARROW_DOWN_UP    = ConvertPlayerEvent(266) // 5
        // EVENT_PLAYER_ARROW_UP_DOWN    = ConvertPlayerEvent(267) // 6
        // EVENT_PLAYER_ARROW_UP_UP      = ConvertPlayerEvent(268) // 7
        local integer eid = GetHandleId(GetTriggerEventId()) - 261

        set p       = GetTriggerPlayer()
        set key     = eid / 2
        set is_down = eid == 2 * key
        set is_player_key_down[GetPlayerId(p)][key] = is_down

        call TriggerEvaluate(arrow_key_trigger)

        return false
    endmethod

    private static method on_esc_key takes nothing returns boolean
        set p       = GetTriggerPlayer()
        set key     = KEY_ESC
        set is_down = true

        call TriggerEvaluate(esc_key_trigger)

        return false
    endmethod

    private static method onInit takes nothing returns nothing
        local player p
        local trigger t
        local integer i

        set t = CreateTrigger()
        set i = 0
        loop
            exitwhen i >= bj_MAX_PLAYERS

            set p = Player(i)
            if GetPlayerSlotState(p) == PLAYER_SLOT_STATE_PLAYING and GetPlayerController(p) == MAP_CONTROL_USER then

                call TriggerRegisterPlayerEvent(t, p, EVENT_PLAYER_ARROW_LEFT_DOWN)
                call TriggerRegisterPlayerEvent(t, p, EVENT_PLAYER_ARROW_LEFT_UP)
                call TriggerRegisterPlayerEvent(t, p, EVENT_PLAYER_ARROW_RIGHT_DOWN)
                call TriggerRegisterPlayerEvent(t, p, EVENT_PLAYER_ARROW_RIGHT_UP)
                call TriggerRegisterPlayerEvent(t, p, EVENT_PLAYER_ARROW_DOWN_DOWN)
                call TriggerRegisterPlayerEvent(t, p, EVENT_PLAYER_ARROW_DOWN_UP)
                call TriggerRegisterPlayerEvent(t, p, EVENT_PLAYER_ARROW_UP_DOWN)
                call TriggerRegisterPlayerEvent(t, p, EVENT_PLAYER_ARROW_UP_UP)

            endif

            set i = i + 1
        endloop
        call TriggerAddCondition(t, Condition(function thistype.on_arrow_key))

        set t = CreateTrigger()
        set i = 0
        loop
            exitwhen i >= bj_MAX_PLAYERS

            set p = Player(i)
            if GetPlayerSlotState(p) == PLAYER_SLOT_STATE_PLAYING and GetPlayerController(p) == MAP_CONTROL_USER then
                call TriggerRegisterPlayerEvent(t, p, EVENT_PLAYER_END_CINEMATIC)
            endif

            set i = i + 1
        endloop
        call TriggerAddCondition(t, Condition(function thistype.on_esc_key))

        set t = null
    endmethod
endmodule
private struct OnKeyEventDummy extends array
    implement OnKeyEvent
endstruct


module onkeyevent
    private static method call_on_key_event_handler takes nothing returns boolean
        call thistype.on_key(OnKeyEventDummy.p, OnKeyEventDummy.key, OnKeyEventDummy.is_down)
        return false
    endmethod

    private static method onInit takes nothing returns nothing
        static if thistype.on_key.exists then
            call TriggerAddCondition(OnKeyEventDummy.arrow_key_trigger, Condition(function thistype.call_on_key_event_handler))
            call TriggerAddCondition(OnKeyEventDummy.esc_key_trigger, Condition(function thistype.call_on_key_event_handler))
        endif
    endmethod
endmodule

endlibrary

Notice that the module that's required to be implemented is very short.

Also, I tried to comiple ArrowEvents but it has the PlayerManager requirement, fine... I follow the link, copy paste the script... but
it has a requirement of it's own called Event, which has requirements of it's own, etc, etc...

In the end I couldn't satisfy all the requirements/dependencies and I gave up..., even if I really, really wanted to use ArrowEvents
and I didn't mind all the other libraries that it needs (implicitly via PlayerManager) I would have to spend a lot of time being a
"human dependency manager", which is annoying.
 
Pros:
  • Events triggers straight to each function without having to go through ITE
    + on efficiency
  • Optional to code any arrow key methods
    + on dynamics
  • Allows individual players to register and deregister arrow key event systems so different players can use different arrow key systems at once
    + on dynamics

I don't think it would be much more efficient that seeting all the arrow key events to go to one method.
This is just another way of coding Arrow Event systems.

I tried using Bribe's snippet, although it didn't have the dynamics I need.

Surely you could create even more conditioned dependancies to patch up these issues, but I don't like the idea of that.

It seems to me that "The way you like coding the arrow events" leads to code bloat...
...
I would have made it to the methods were outside the module, although each method the unique variables needed inside each implement. The code isn't significantly large enough to cause issues anyway, even if implemented 5 times over.

Surely static ifs could be removed, although it won't cause any noticeable compile time change to have any significance.

Ingame objects are more to be worried about like destructables, units and doodads.

That library looks decent though.

Also, I tried to comiple ArrowEvents but it has the PlayerManager requirement, fine... I follow the link, copy paste the script... but
it has a requirement of it's own called Event, which has requirements of it's own, etc, etc...

In the end I couldn't satisfy all the requirements/dependencies and I gave up..., even if I really, really wanted to use ArrowEvents
and I didn't mind all the other libraries that it needs (implicitly via PlayerManager) I would have to spend a lot of time being a
"human dependency manager", which is annoying.

https://github.com/nestharus/JASS/blob/master/jass/Systems/Event/script.j

Wow, Nestharus hasn't even updated his snippet links even on GitHub.
I don't remember Event having any requiments (atleast the one I'm using).

I might have to make a version without any requirments.
Although I'm not at home atm.
 

Bannar

Code Reviewer
Level 26
Joined
Mar 19, 2008
Messages
3,140
If this is to achieve anything, please provide wrapper around Bribe's snippet.

JASS:
library_once ArrowEvents
    { body }
endlibrary

library ArrowKeyEvent requires ArrowEvents
endlibrary
I'm not a fan of "module-library" if it's concentrated only on "module" part.

JASS:
struct MyStruct1 extends array
    { body }
    { functional onArrowEvent handler }
    implement ArrowEvents
endstruct

struct MyStruct2 extends array
    { body }
    { functional onArrowEvent handler }
    implement ArrowEvents
endstruct
Leads to heavy code bloat as stated, and unnecessarly increased file size.
The new "Event" of Nes' shouldn't be surprising to you, since Nes basically wrapped and coded everything around Trigger of his TL:DR implement 15 libraries before you start writing your stuff.

Struct-based implementation is good, especially if it follows some generic concepts thus allowing for use without forcing user to perform any additional tasks. Treat "module" part as addition - not base. This is what Bribe did in his implementation.

Everyone has thier own way of coding, at least when working "casualy" (being a part of design team forces you to follow some specific convention), but it's not really an excuse to upload all the custom implementations just becuase of that.

Your entry is missing demo part:
JASS:
struct test_me extends array
    { body }
endstruct
 
If this is to achieve anything, please provide wrapper around Bribe's snippet.

JASS:
library_once ArrowEvents
    { body }
endlibrary

library ArrowKeyEvent requires ArrowEvents
endlibrary

I'm not a fan of "module-library" if it's concentrated only on "module" part.

This isn't an extension to his library and I use library only for requirements.
Besides this snipped is to different from his. His snipped would need a direct edit to achieve what I'm trying to here.
(That being registering and de-registering unique players)


Leads to heavy code bloat as stated, and unnecessarly increased file size.
It's necessary for the functionality it brings.
The static ifs are there to so that users don't break the code.

The new "Event" of Nes' shouldn't be surprising to you, since Nes basically wrapped and coded everything around Trigger of his TL:DR implement 15 libraries before you start writing your stuff.
I suppose your right with the direction he's going.

Struct-based implementation is good, especially if it follows some generic concepts thus allowing for use without forcing user to perform any additional tasks. Treat "module" part as addition - not base. This is what Bribe did in his implementation.

Everyone has thier own way of coding, at least when working "casualy" (being a part of design team forces you to follow some specific convention), but it's not really an excuse to upload all the custom implementations just becuase of that.
It's what I'm trying to achieve as well.
I want my stuff to be understandable and useful by as many as I can while achieving what I want.


Your entry is missing demo part:
JASS:
struct test_me extends array
    { body }
endstruct
Added


//


I also updated this snippet:
  • To not require PlayerManager (still have a version that requires it)
  • Updated description
  • Created demo
  • Removed boolean setting DEFAULT_ALL_REGISTERED (so user will always have to init player register)
  • Added safety to check if player is registered to struct arrow key events
  • Removed private keyword from trigger and triggeraction variables
 
Last edited:

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,456
Again, I refer back to ArrowKey:

  • Light as possible. +9000 on no code duplication with some magic math and a few short if/elses to interpret events. It cannot get any shorter when you have all events on one trigger.
  • Supports axis multiplier (*1, *0, *-1) with ArrowKey addon.
  • All events stored on one parent trigger; reduces handle count.
    ---- Ok, let's say yours doesn't create the handle if the player isn't registered. Let's call it roughly even for the sake of argument. But then, your "multiple libraries using this" argument will definitely expand that handle count and the trophy returns to ArrowKey.
  • Does not use triggeractions because they are less efficient. Oh, the efficiency lost from the if/elses has been remedied. Having waits on an arrow key press is not the most ideal since it can be released and re-pressed again before the wait is over. If the user needs to open a new thread for whatever reason, they still can but must do it themselves.
  • A boolean array made by the user indexed by player ID would work best as a replacement to this library. If they also just wanted a couple of the key events, a short if/else structure works well.
  • Really, arrow keys are typically for movement systems and that's why I have ArrowKey setup like that. The system was engineered specifically for simplifying movement using the multiplier of the extension library, with the bonus of the user not even needing to know which key was pressed/released or can even avoid using the events altogether and just calculate movement on a periodic timer.
 
^You seem to be referring more to efficiency and minimizing your code duplication.
I am cool with the way you are coding all of this and am not in any way looking to overwrite your snippet.

I am not referring to triggeraction tracking for efficiency and code minimizing however.
I am using it for functionality so individual players go in and out of different arrow key even structs.

Then lets say I try and use your snippet to satisfy my needs with the functionality that I tried to create.
With the aid of your demo code I have come up with this.

Even though the arrow key event will trigger the method all the time this way, arrow key events are light (I presume) to fire anyway.
This way would be less code heavy as well.

JASS:
struct Tester extends array

    boolean IsPlayerRegistered
    
    method onArrowKeyEvent takes integer arrow, boolean pressed returns nothing
        
        if ArrowKey.eventPlayerId.IsPlayerRegistered then
            
            static if LIBRARY_ArrowKey then
                call BJDebugMsg("Axis Focus: X: " + .getKeyName(thistype(0).getAxisKey(ARROW_KEY_X_AXIS)) + ", Y: " + .getKeyName(thistype(0).getAxisKey(ARROW_KEY_Y_AXIS)))
            else
                if pressed then
                    call BJDebugMsg("Key pressed: " + .getKeyName(arrow))
                else
                    call BJDebugMsg("Key released: " + .getKeyName(arrow))
                endif
            endif
            
        endif
    endmethod
    
    static method AddArrowKeysPlayerId takes thistype PlayerId returns nothing
        
        set ArrowKey.eventPlayerId.IsPlayerRegistered = GetPlayerSlotState(Player(PlayerId)) == PLAYER_SLOT_STATE_PLAYING and GetPlayerController(Player(PlayerId)) == MAP_CONTROL_USER
    endmethod
    
    static method RemoveArrowKeysPlayerId takes thistype PlayerId returns nothing
        
        if PlayerId.IsRegistered then
            
            set ArrowKey.eventPlayerId.IsPlayerRegistered = false
            
        endif
    endmethod
    
    static method AddArrowKeysAllPlayers takes nothing returns nothing
        local thistype this = 11
        local player p = Player(this)
        
        loop
            call AddArrowKeysPlayerId(ArrowKey.eventPlayerId)
           
            exitwhen this == 0
           
            set this = this - 1
            set p = Player(this)
        endloop
       
        set p = null
    endmethod
    
    static method RemoveArrowKeysAllPlayers takes nothing returns nothing
        local thistype this = 11
        local player p = Player(this)
       
        loop
            call RemoveArrowKeysPlayerId(ArrowKey.eventPlayerId)
           
            exitwhen this == 0
           
            set this = this - 1
            set p = Player(this)
        endloop
       
        set p = null
    endmethod
    
    static method onInit takes nothing returns nothing
        
        call AddKeysAllPlayers()
    endmethod
    
    implement ArrowKey
endstruct
 
Can you renamed this thread to '[System Extension] ArrowKeyEvent PlayerRegister' by the forum index?

Updated to make this an extension to your system.

I would have liked to made this a condition add-on or something so the user didn't have to manually add an ITE line to their code, but you use a static trigger that compiles with all arrow event handles.

Any criticism with description and stuff might be useful.
 
Last edited:
Level 23
Joined
Apr 16, 2012
Messages
4,041
JPAG structMembersLikeThis NotLikeThis, if you feel that the current names are justified and required to be in such format, let me know, but you should follow JPAG where applicable

I think last call should go to Bribe since it is extension to his resource. Maybe this could even be incorporated to the original resource.
 
This system is pretty useless actually as all you need is this variable.
(His system already filters so only humans are passed, and even if a CPU did it wouldn't be possible in the first place to press an arrow key)

boolean isPlayerRegistered
(correct JPAG here, sorry for the mistake)

Just follow each vairable index with the player id and setup an ITE code in your onArrowKeyEvent struct method if you want the player function to pass.

It would be nice if Bribe added an ITE function in his pre functions of the onArrowKeyEvent user method, but it's his choice.

Either way this is just another failed attempt, as I made things seem more complicated to myself than it actually is.
I vote for this being graveyarded.
 
This is my idea for the text macros that would be implemented.
Hopefully it makes enough sense to be easily used.
I've designed it so the users can use as little lines of code as necessary.
I think it's best to use operators, but users might get confused?
JASS:
library ArrowKeyPlayerPass /* v1.0.0.0, created by SA Dashie
  
    */ uses /*
  
        */ ArrowKeyEvent /*
  
    Description
      
        Extra for the ArrowKeyEvent system by Bribe. It adds a player
        condition directly into the ArrowKey module to check if the player
        can pass through or not.
      
        boolean canPlayerPass is the only variable changed when setting variables.
        The other variables are operators and only write like a variable.

    Fields
      
        boolean canPlayerPass
             - is false by default
          
        static boolean canAllPlayersPass
             - can either set all players to pass or not pass
             - returns true if all players can pass
           
        readonly static boolean canAllPlayersNotPass
             - returns true if all players can't pass

*/

    //! textmacro ARROW_KEY_CONDITION_VARIABLE
        boolean canPlayerPass
      
        static method operator canAllPlayersPass= takes boolean b returns nothing
            local thistype this = 11
          
            loop
                set canPlayerPass = b
              
                exitwhen this == 0
                set this = this - 1
            endloop
        endmethod
      
        static method operator canAllPlayersPass takes nothing returns boolean
            local thistype this = 11
          
            loop
                if not canPlayerPass then
                    return false
                endif
              
                exitwhen this == 0
                set this = this - 1
            endloop
          
            return true
        endmethod
      
        static method operator canAllPlayersNotPass takes nothing returns boolean
            local thistype this = 11
         
            loop
                if canPlayerPass then
                    return false
                endif
             
                exitwhen this == 0
                set this = this - 1
            endloop
          
            return true
        endmethod
    //! endtextmacro

    //! textmacro ARROW_KEY_CONDITION_ITE
        if not thistype(.eventPlayerId).canPlayerPass then
            return
        endif
    //! endtextmacro

endlibrary
And Bribe this is where I would have it implemented in the user implemented module.

JASS:
module ArrowKey

    //Delegates are fun, you should try them out.
    private delegate ArrowKey AK
   
    //===================================================================
    // Please call this method from *below the module implement statement
    // if you know what's good for you.
    //
    static method operator [] takes player who returns thistype
        return GetPlayerId(who)
    endmethod
   
    //! runtextmacro optional ARROW_KEY_CONDITION_VARIABLE()
   
    static if thistype.onArrowKeyEvent.exists then
        private static method eventProxy takes nothing returns nothing
            //! runtextmacro optional ARROW_KEY_CONDITION_ITE()
            call thistype(.eventPlayerId).onArrowKeyEvent(.eventKey, .eventKeyPressed)
        endmethod
    endif
   
    private static method onInit takes nothing returns nothing
        local thistype i = 12
        loop
            set i = i - 1
            set i.AK = i  //Delegates require some delegation of course.
            exitwhen i == 0
        endloop
        static if thistype.onArrowKeyEvent.exists then
            call ArrowKey.registerEvent(function thistype.eventProxy)
        endif
    endmethod

endmodule
 
Last edited:
It can be a useful feature to register/unregister players to the arrowkey event if Bribe integrates it directly in the code.
Though I also think it pretty much can be reduced to two members:
JASS:
boolean enabled
static boolean enabledAll

if enabledAll and .enabled then
   return
endif
But then I somehow ask me if it's really worth it. What do you think?
 
@Bribe @SA Dashie -- I would maybe suggest that Bribe implements something like enabled/enabledAll into the ArrowKeyEvent system, and give credits to you SA, Dashie.
I'm personaly not fully convinced to have it as a seperate approved submission, as it is actually useful yes, but the effort is minimalistic in comparison. :(
Me would have no problem with with if Bribe accepts it as a valid addon, but just saying that in my opinion it would make sense to directly implement it + credits.
 

Submission:
[Snippet] [System Extension] ArrowKeyEvent PlayerRegistry

Date:
18 October 16

Status:
Graveyard
Note:

It's too simple to be a seperate approved resource in my opinion.
Though I think it's useful and would be good as addition if directly implemented in [System] ArrowKeyEvent.
Sorry for lacking response, I will try to contact Bribe again to make things faster. But this thread is moved to Graveyard for now.
 
Top