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

[JASS] (Arrow Keys) Look this code....Help plz!!!!

Status
Not open for further replies.
Level 2
Joined
Jul 6, 2007
Messages
12
How can i make a targetable spell using th arrow keys?, for example: when u cast the spell on a enemy unit, then u can use the arrow keys making a combination of them:( >+v+>=Bash)or(<+^+>=100dmg) , for example , and u only have x seconds per cast to do this.
Help plz, may this code can help?
JASS:
library ArrowKeys initializer Init

//*****************************************************************
//*  ARROW KEYS
//*  written by: Anitarf
//*
//*  A simple library for handling arrow keys. It allows you to
//*  check at any time which arrow keys are pressed as well as
//*  respond to keypress events the moment they happen.
//*****************************************************************

    // whichkey parameter values: 1-left, 2-right, 3-down, 4-up
    // pressed parameter values: true-key was pressed, false-key was released
    public function interface Event takes player whichPlayer, integer whichKey, boolean pressed returns nothing

    // the library is used through the following variables:
    globals
        // the following constant determines the behaviour of the vertical and horizontal
        // variables. For example, if a player presses the up key and then presses the down
        // key afterwards while still holding the up key, the vertical variable will be set
        // to -1. Then, if the player releases the down key while still keeping the up key
        // pressed, if RESUME_PREVIOUS_KEY is true the vertical variable will be set back
        // to 1, else it will be set to 0.
        private constant boolean RESUME_PREVIOUS_KEY = true
    
        // this tells you the status of the arrow keys in the two directions for each player
        // index 0 holds the values for player 1 (red), index 11 for player 12 (brown)
        // a value of 0 means no keys pressed, 1 means right/up, -1 means left/down
        // do not change the value of these variables
        public integer array vertical
        public integer array horizontal
        // this tells you the status of each arrow key individualy for each player
        // index 0 holds the values for player 1 (red), index 11 for player 12 (brown)
        // this is basicaly the same as vertical/horizontal, you can use whichever you want
        // do not change the value of these variables
        public boolean array up
        public boolean array down
        public boolean array left
        public boolean array right
        // these are the "quick press" variables. They work similarly to the variables above,
        // except that they aren't set to 0/false when a key is released. If you are checking
        // the above variables on a periodic timer, you could miss a keypress if a player
        // quickly presses and releases a key, the variables below allow you to catch such
        // quick keypresses. Note that you must set these variables to 0/false yourself once
        // you check them or they'll remain permanently set to 1/-1/true. Basicaly these
        // variables tell you if a key has been pressed since you last set them to 0/false.
        public integer array verticalQP
        public integer array horizontalQP
        public boolean array upQP
        public boolean array downQP
        public boolean array leftQP
        public boolean array rightQP

        // these are the external functions that get called when an arrow key is pressed/released
        // you can set these variables to your functions that follow the Event function interface
        // you don't need a different function for each event, you can set all these variables to
        // a single function, since the function's parameters tell you what event occured.
        public Event pressUp = 0
        public Event releaseUp = 0
        public Event pressDown = 0
        public Event releaseDown = 0
        public Event pressLeft = 0
        public Event releaseLeft = 0
        public Event pressRight = 0
        public Event releaseRight = 0
    endglobals

// ================================================================
    
    private function KeyPressLeft takes nothing returns nothing
        local integer i = GetPlayerId(GetTriggerPlayer())
        set left[i]=true
        set horizontal[i]=-1
        set leftQP[i]=true
        set horizontalQP[i]=-1
        if pressLeft != 0 then
            call pressLeft.execute(GetTriggerPlayer(), 1, true)
        endif
    endfunction
    private function KeyPressRight takes nothing returns nothing
        local integer i = GetPlayerId(GetTriggerPlayer())
        set right[i]=true
        set horizontal[i]=1
        set rightQP[i]=true
        set horizontalQP[i]=1
        if pressRight != 0 then
            call pressRight.execute(GetTriggerPlayer(), 2, true)
        endif
    endfunction
    private function KeyPressDown takes nothing returns nothing
        local integer i = GetPlayerId(GetTriggerPlayer())
        set down[i]=true
        set vertical[i]=-1
        set downQP[i]=true
        set verticalQP[i]=-1
        if pressDown != 0 then
            call pressDown.execute(GetTriggerPlayer(), 3, true)
        endif
    endfunction
    private function KeyPressUp takes nothing returns nothing
        local integer i = GetPlayerId(GetTriggerPlayer())
        set up[i]=true
        set vertical[i]=1
        set upQP[i]=true
        set verticalQP[i]=1
        if pressUp != 0 then
            call pressUp.execute(GetTriggerPlayer(), 4, true)
        endif
    endfunction

    private function KeyReleaseLeft takes nothing returns nothing
        local integer i = GetPlayerId(GetTriggerPlayer())
        set left[i]=false
        if RESUME_PREVIOUS_KEY and right[i] then
            set horizontal[i]=1
        else
            set horizontal[i]=0
        endif
        if releaseLeft != 0 then
            call releaseLeft.execute(GetTriggerPlayer(), 1, false)
        endif
    endfunction
    private function KeyReleaseRight takes nothing returns nothing
        local integer i = GetPlayerId(GetTriggerPlayer())
        set right[i]=false
        if RESUME_PREVIOUS_KEY and left[i] then
            set horizontal[i]=-1
        else
            set horizontal[i]=0
        endif
        if releaseRight != 0 then
            call releaseRight.execute(GetTriggerPlayer(), 2, false)
        endif
    endfunction
    private function KeyReleaseDown takes nothing returns nothing
        local integer i = GetPlayerId(GetTriggerPlayer())
        set down[i]=false
        if RESUME_PREVIOUS_KEY and up[i] then
            set vertical[i]=1
        else
            set vertical[i]=0
        endif
        if releaseDown != 0 then
            call releaseDown.execute(GetTriggerPlayer(), 3, false)
        endif
    endfunction
    private function KeyReleaseUp takes nothing returns nothing
        local integer i = GetPlayerId(GetTriggerPlayer())
        set up[i]=false
        if RESUME_PREVIOUS_KEY and down[i] then
            set vertical[i]=-1
        else
            set vertical[i]=0
        endif
        if releaseUp != 0 then
            call releaseUp.execute(GetTriggerPlayer(), 4, false)
        endif
    endfunction

    private function TriggerRegisterKeypressEvent takes trigger t, playerevent ev returns nothing
        local integer i = 0
        loop
            exitwhen i == 12
            call TriggerRegisterPlayerEvent( t, Player(i), ev )
            set i = i + 1
        endloop
    endfunction
    private function Init takes nothing returns nothing
        local trigger t

        //press left
        set t = CreateTrigger()
        call TriggerRegisterKeypressEvent( t, EVENT_PLAYER_ARROW_LEFT_DOWN )
        call TriggerAddAction( t, function KeyPressLeft )
        //release left
        set t = CreateTrigger()
        call TriggerRegisterKeypressEvent( t, EVENT_PLAYER_ARROW_LEFT_UP )
        call TriggerAddAction( t, function KeyReleaseLeft )

        //press right
        set t = CreateTrigger()
        call TriggerRegisterKeypressEvent( t, EVENT_PLAYER_ARROW_RIGHT_DOWN )
        call TriggerAddAction( t, function KeyPressRight )
        //release right
        set t = CreateTrigger()
        call TriggerRegisterKeypressEvent( t, EVENT_PLAYER_ARROW_RIGHT_UP )
        call TriggerAddAction( t, function KeyReleaseRight )

        //press down
        set t = CreateTrigger()
        call TriggerRegisterKeypressEvent( t, EVENT_PLAYER_ARROW_DOWN_DOWN )
        call TriggerAddAction( t, function KeyPressDown )
        //release down
        set t = CreateTrigger()
        call TriggerRegisterKeypressEvent( t, EVENT_PLAYER_ARROW_DOWN_UP )
        call TriggerAddAction( t, function KeyReleaseDown )

        //press up
        set t = CreateTrigger()
        call TriggerRegisterKeypressEvent( t, EVENT_PLAYER_ARROW_UP_DOWN )
        call TriggerAddAction( t, function KeyPressUp )
        //release up
        set t = CreateTrigger()
        call TriggerRegisterKeypressEvent( t, EVENT_PLAYER_ARROW_UP_UP )
        call TriggerAddAction( t, function KeyReleaseUp )

        set t = null
    endfunction

endlibrary
Thanks
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
I haven't really read into it.

My first question is is this game going to be online? If so, I don't suggest arrow keys. I was going to make a system exactly like this, but I was going to use ability keys or num pad keys to do this. So firstly, I suggest you don't use the arrow keys. I say this because arrow keys lag horrifically.

Next, you can't just make the system first. First you need a system to manage all of the data for each and every unit. An array won't work unless you have a pointer inside of each unit pointing to a specific array, and in that case, it might collide with other systems.

So first: A data management system. You could store it all in the game cache and have it point to that, but eh. It really all depends on what type of memory management system you use. Right now, I'm designing one too because I can't make any systems without it : P. But yea, to create a system like this, you need something to manage the memory. Most systems have memory management systems built into them, but I seriously don't suggest building one specifically to go with this, otherwise you're going to have to build up a new memory management system every time you design something new.

So #1: Something to Manage the Memory

After you do this, you can easily record the key combinations through various ability hot keys or inventory num pad keys ; ). From here, you can create a unique timer for each one (once again you'll need that system to manage your memory and pointers) so you can countdown how much time they have left to do the next one. Perhaps you could make it so it had to be specifically timed?

Another way you can do this is by creating a 2D grid. From here you could place a trackable or locust unit in each of the cells. After this, you could connect the different trackables or locust units to the different units once again through the memory management system. The units would have to be pointing to the trackables. From here, you could create numpad key icons or symbols signifying when to press down the key. They could light up. After this, you could easily make it follow you around, in essence, creating buttons like an information menu button etc like in a regular game. All you need to do is move it from cell to cell. The precision of the movements will be largely based upon your cell sizes.

Oh well, those are just some different methods of doing it. Right now, in your code, I really don't see much. You have no way to track anything, all you have are booleans.

Now, structs aren't going to help you in this case. Why? they don't manage memory. If you use the game cache, you're still going to have to make something that'll retrieve memory and store it. It'll be easy and quick though. As I said before, I'm designing a system as well : P. A lot of people think I'm all talk about it, but I can't make any maps or systems until I design this -.-. So to say the least, I haven't released anything for awhile. A lot of stuff's been getting in the way of its design so it's been taking me forever.

If you say you want to use this system, I'll make it a top priority and I might even get a beta form released by tomorrow for you to try out -.-. Don't share this beta form with anyone because I want to have a formal release data with a map and everything so everyone can look at it in aw and say how cool I am ^^.

Oh well, up to you.

-Fate Industries.
 
Level 2
Joined
Jul 6, 2007
Messages
12
Yes, the game will be online. but will you make a system using arrow keys or arrow keys+my request? Well, I forgot that I want to make the spell like the combination of arrows in street fighter or mortl kmbt for example but if it werent possible, I'd wante t
This idea comes from a spell created by uNmI and posted in wc3search (when that page existed) but it was somehow erased.
Ok his spell ,in fact was a succession of arrows where u have to press each key accordly
to text showed in the screen but if you take more than x seconds making the sequence the spell ended, oh and for each key pressed the caster of the spell did more damage and better combos.
Anyways, I will wait your beta system : )
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
I don't think you quite understand. It'll be impossible for players to play if you use arrow keys. The delay is too much .. I had 6-8 second delay on a very good host in a simple game of chess with the arrow keys and I'm on a 4 megabit connection (up/down, but the up doesn't matter unless i is hosting ^_^). So.. that's just to give you an idea of why I said you can't use arrow keys to do it k.
 
Level 2
Joined
Jul 6, 2007
Messages
12
I understood it -.-, but in my game only one player will use the arrow keys, no more. Can it cause lag anyways?
And I'm still waiting for ur system : )
 
Level 8
Joined
Jun 20, 2004
Messages
229
using 3rd party programs you can remove the delay completely or near it. there are many bnet to lan programs that will trick the game into letting you play online using lan speeds. Blizzard for some reason made bnet have slow rates which causes the delay. I can name some but not in forum, pretty sure it is against the rules.
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
That won't remove the arrow delay. The delay in speed is there so that the game has a chance to send information back and forth, it's almost like a timer. It's the set ms you can have. B.net is set for 250. LAN is set for 100. If you go lower than a person's lowest limit, you'll start having things like lag spikes.

140 is safe in most cases but 250 is the safest bet for any type of host. That's why it's set so high. For LAN, it's lower because it's over a LAN line, but the computers may suck so it's still higher than it should be in 95% of cases.

You can safely lower it on b.net to 100 for most games. If someone pings higher than 100, it's safest to set it to their ping.

The delay in arrows is just how the native was done. I don't think the host delays heavily though. I never actually tested it, but I really don't imagine they would.

= )

And on a sidenote, it looks like I'm not releasing v2.0. It looks like nobody will be happy until I skip to v2.1 = P. So.. I'm going to have to rewrite it again. I never released v1.0 because in the middle of its design it became obsolete to v2.0. v2.1 is the same type of design as v2.0 syntax wise, but the back design is very different. It'll raise the speed and manage the memory more efficiently.

Sry : (. My original plan was to release v2.0 for everyone to try out and so on, but everyone says it's a pointless system, so... I gotta go ahead and lock up v2.0 meaning it'll never get released to the public. v2.1 ftw. ETA, 2 weeks considering work and college ><
 
Level 2
Joined
Jul 6, 2007
Messages
12
Ok, thx anyways, but I need a quick solution to my request
can anyone help with this spell?
At least help giving a short example of how the Anitarf's system works

Thanks
 
Status
Not open for further replies.
Top