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?
Thanks
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