- Joined
- Sep 20, 2015
- Messages
- 385
Hello when i test this script with two istances of warcraft the player blue unit ( PXHero[1] ) does not move. It plays the walk animation tho. I don't know what to do anymore. Can someone help me
Thanks in advance
JASS:
globals
boolean array WASD_IsKeyDown_W
boolean array WASD_IsKeyDown_A
boolean array WASD_IsKeyDown_S
boolean array WASD_IsKeyDown_D
constant oskeytype WASD_KEY_W = ConvertOsKeyType($57)
constant oskeytype WASD_KEY_A = ConvertOsKeyType($41)
constant oskeytype WASD_KEY_S = ConvertOsKeyType($53)
constant oskeytype WASD_KEY_D = ConvertOsKeyType($44)
constant real WASD_MoveDistance = 10.0
real array Fangl
endglobals
function PlayerMoveEvent_Actions takes nothing returns nothing
//local integer i = GetPlayerId(GetTriggerPlayer())
local integer i = GetPlayerId(GetOwningPlayer( udg_PXHero[GetPlayerId(GetTriggerPlayer())] ))
local real array dx
local real array dy
local real array angle
local real array angleDEG
local location array TerrainCheck
local location array BlockPoint
//local real array angle
set dx[i] = 0.
set dy[i] = 0.
if WASD_IsKeyDown_W[i] and (not ( WASD_IsKeyDown_S[i] or WASD_IsKeyDown_A[i] or WASD_IsKeyDown_D[i])) and (IsKeyDown_SHIFT[i] or not ( IsKeyDown_SHIFT[i])) and ( isLeftMbDown[i] or not(isLeftMbDown[i])) then
set dy[i] = dy[i] + 1.
elseif WASD_IsKeyDown_S[i] and (not ( WASD_IsKeyDown_W[i] or WASD_IsKeyDown_A[i] or WASD_IsKeyDown_D[i])) and (IsKeyDown_SHIFT[i] or not ( IsKeyDown_SHIFT[i])) and ( isLeftMbDown[i] or not(isLeftMbDown[i])) then
set dy[i] = dy[i] - 1.
elseif WASD_IsKeyDown_A[i] and (not ( WASD_IsKeyDown_S[i] or WASD_IsKeyDown_W[i] or WASD_IsKeyDown_D[i])) and (IsKeyDown_SHIFT[i] or not ( IsKeyDown_SHIFT[i])) and ( isLeftMbDown[i] or not(isLeftMbDown[i])) then
set dx[i] = dx[i] - 1.
elseif WASD_IsKeyDown_D[i] and (not ( WASD_IsKeyDown_S[i] or WASD_IsKeyDown_A[i] or WASD_IsKeyDown_W[i])) and (IsKeyDown_SHIFT[i] or not ( IsKeyDown_SHIFT[i])) and ( isLeftMbDown[i] or not(isLeftMbDown[i])) then
set dx[i] = dx[i] + 1.
elseif WASD_IsKeyDown_W[i] and WASD_IsKeyDown_D[i] and (not ( WASD_IsKeyDown_S[i] or WASD_IsKeyDown_A[i])) and (IsKeyDown_SHIFT[i] or not ( IsKeyDown_SHIFT[i])) and ( isLeftMbDown[i] or not(isLeftMbDown[i])) then
set dy[i] = dy[i] + 0.5
set dx[i] = dx[i] + 0.5
elseif WASD_IsKeyDown_W[i] and WASD_IsKeyDown_A[i] and (not ( WASD_IsKeyDown_S[i] or WASD_IsKeyDown_D[i])) and (IsKeyDown_SHIFT[i] or not ( IsKeyDown_SHIFT[i])) and ( isLeftMbDown[i] or not(isLeftMbDown[i])) then
set dy[i] = dy[i] + 0.5
set dx[i] = dx[i] - 0.5
elseif WASD_IsKeyDown_S[i] and WASD_IsKeyDown_D[i] and (not ( WASD_IsKeyDown_W[i] or WASD_IsKeyDown_A[i])) and (IsKeyDown_SHIFT[i] or not ( IsKeyDown_SHIFT[i])) and ( isLeftMbDown[i] or not(isLeftMbDown[i])) then
set dy[i] = dy[i] - 0.5
set dx[i] = dx[i] + 0.5
elseif WASD_IsKeyDown_S[i] and WASD_IsKeyDown_A[i] and (not ( WASD_IsKeyDown_W[i] or WASD_IsKeyDown_D[i])) and (IsKeyDown_SHIFT[i] or not ( IsKeyDown_SHIFT[i])) and ( isLeftMbDown[i] or not(isLeftMbDown[i])) then
set dy[i] = dy[i] - 0.5
set dx[i] = dx[i] - 0.5
endif
set angle[i] = Atan2(dy[i], dx[i]) //gives the angle, in radians not degrees
if WASD_IsKeyDown_W[i] or WASD_IsKeyDown_S[i] or WASD_IsKeyDown_A[i] or WASD_IsKeyDown_D[i] and (IsKeyDown_SHIFT[i] or not ( IsKeyDown_SHIFT[i])) then
set udg_Temp_Point_A[i] = Location( (GetUnitX(udg_PXHero[i]) + 100*Cos(angle[i])) ,(GetUnitY(udg_PXHero[i]) + 100*Sin(angle[i])) )
if IsPointWalkable(GetLocationX(udg_Temp_Point_A[i]), GetLocationY(udg_Temp_Point_A[i])) then
call SetUnitX(udg_PXHero[i], GetUnitX(udg_PXHero[i]) + udg_WASD_PlayerMoveDistance[i]*Cos(angle[i]))
call SetUnitY(udg_PXHero[i], GetUnitY(udg_PXHero[i]) + udg_WASD_PlayerMoveDistance[i]*Sin(angle[i]))
elseif IsTerrainPathable( GetLocationX(udg_Temp_Point_A[i]), GetLocationY(udg_Temp_Point_A[i]), PATHING_TYPE_FLOATABILITY) then
elseif GetUnitAbilityLevel(udg_PXHero[i], 'A00M') > 0 then
call SetUnitX(udg_PXHero[i], GetUnitX(udg_PXHero[i]) + udg_WASD_PlayerMoveDistance[i]*Cos(angle[i]))
call SetUnitY(udg_PXHero[i], GetUnitY(udg_PXHero[i]) + udg_WASD_PlayerMoveDistance[i]*Sin(angle[i]))
call BJDebugMsg(I2S(i))
else
call SetUnitX(udg_PXHero[i], GetUnitX(udg_PXHero[i]))
call SetUnitY(udg_PXHero[i], GetUnitY(udg_PXHero[i]))
endif
endif
call RemoveLocation ( udg_Temp_Point_A[i]
endfunction
function PlayerKeyEvent_Actions takes nothing returns nothing
local oskeytype osKeyPressed = BlzGetTriggerPlayerKey() // What key was pressed or released?
local boolean isKeyDown = BlzGetTriggerPlayerIsKeyDown() // Was the event key pressed or released?
local integer i=GetPlayerId(GetTriggerPlayer())
local effect testef
//Not used here, but this way we can detect the meta-key.
local integer metaKeyPressed = BlzGetTriggerPlayerMetaKey()
call DisplayTimedTextToForce( GetPlayersAll(), 1.00, I2S(BlzGetTriggerPlayerMetaKey()) )
//loop
//exitwhen (i > 24)
if (osKeyPressed == WASD_KEY_W) then
set WASD_IsKeyDown_W[i] = isKeyDown
elseif (osKeyPressed == WASD_KEY_A) then
set WASD_IsKeyDown_A[i] = isKeyDown
elseif (osKeyPressed == WASD_KEY_S) then
set WASD_IsKeyDown_S[i] = isKeyDown
elseif (osKeyPressed == WASD_KEY_D) then
set WASD_IsKeyDown_D[i] = isKeyDown
endif
if isKeyDown and (IsKeyDown_SHIFT[i] or not ( IsKeyDown_SHIFT[i])) and ( isLeftMbDown[i] or not(isLeftMbDown[i])) then
call SetUnitAnimationByIndex (udg_PXHero[i], udg_AnimationIndexArray[i])
call BlzUnitDisableAbility ( udg_PXHero[i], 'Aatk' , true, false)
call BJDebugMsg(I2S(i))
else
call BlzUnitDisableAbility ( udg_PXHero[i], 'Aatk' , false, false)
if WASD_IsKeyDown_W[i] or WASD_IsKeyDown_A[i] or WASD_IsKeyDown_S[i] or WASD_IsKeyDown_D[i] and (IsKeyDown_SHIFT[i] or not ( IsKeyDown_SHIFT[i])) then
else
call ResetUnitAnimation( udg_PXHero[i] )
endif
endif
endfunction
//===========================================================================
function InitTrig_WASD_PlayerKeyEvent_8_direMetakeytest takes nothing returns nothing
local trigger t = CreateTrigger( )
local integer i = 0
//takes trigger whichTrigger, player whichPlayer, oskeytype key, integer metaKey, boolean keyDown returns event
/* metaKey = In order to fire the event the player must press down another key at the same time,
0 = No additional key required.
1 = Shift-key required
2 = Ctrl-key required
3 = ????
4 = Alt-key required
5+ = ????
*/
loop
call BlzTriggerRegisterPlayerKeyEvent( t, Player(i), WASD_KEY_W, 0, true ) // Presses the "W"-key.
call BlzTriggerRegisterPlayerKeyEvent( t, Player(i), WASD_KEY_W, 0, false )// Releases the "W"-key.
call BlzTriggerRegisterPlayerKeyEvent( t, Player(i), WASD_KEY_A, 0, true ) // Presses the "A"-key.
call BlzTriggerRegisterPlayerKeyEvent( t, Player(i), WASD_KEY_A, 0, false )// Releases the "A"-key.
call BlzTriggerRegisterPlayerKeyEvent( t, Player(i), WASD_KEY_S, 0, true ) // Presses the "S"-key.
call BlzTriggerRegisterPlayerKeyEvent( t, Player(i), WASD_KEY_S, 0, false )// Releases the "S"-key.
call BlzTriggerRegisterPlayerKeyEvent( t, Player(i), WASD_KEY_D, 0, true ) // Presses the "D"-key.
call BlzTriggerRegisterPlayerKeyEvent( t, Player(i), WASD_KEY_D, 0, false )// Releases the "D"-key.
//METAKEY 1 SHIFT
call BlzTriggerRegisterPlayerKeyEvent( t, Player(i), WASD_KEY_W, 1, true ) // Presses the "W"-key.
call BlzTriggerRegisterPlayerKeyEvent( t, Player(i), WASD_KEY_W, 1, false )// Releases the "W"-key.
call BlzTriggerRegisterPlayerKeyEvent( t, Player(i), WASD_KEY_A, 1, true ) // Presses the "A"-key.
call BlzTriggerRegisterPlayerKeyEvent( t, Player(i), WASD_KEY_A, 1, false )// Releases the "A"-key.
call BlzTriggerRegisterPlayerKeyEvent( t, Player(i), WASD_KEY_S, 1, true ) // Presses the "S"-key.
call BlzTriggerRegisterPlayerKeyEvent( t, Player(i), WASD_KEY_S, 1, false )// Releases the "S"-key.
call BlzTriggerRegisterPlayerKeyEvent( t, Player(i), WASD_KEY_D, 1, true ) // Presses the "D"-key.
call BlzTriggerRegisterPlayerKeyEvent( t, Player(i), WASD_KEY_D, 1, false )// Releases the "D"-key.
//METAKEY 2 CTRL
call BlzTriggerRegisterPlayerKeyEvent( t, Player(i), WASD_KEY_W, 2, true ) // Presses the "W"-key.
call BlzTriggerRegisterPlayerKeyEvent( t, Player(i), WASD_KEY_W, 2, false )// Releases the "W"-key.
call BlzTriggerRegisterPlayerKeyEvent( t, Player(i), WASD_KEY_A, 2, true ) // Presses the "A"-key.
call BlzTriggerRegisterPlayerKeyEvent( t, Player(i), WASD_KEY_A, 2, false )// Releases the "A"-key.
call BlzTriggerRegisterPlayerKeyEvent( t, Player(i), WASD_KEY_S, 2, true ) // Presses the "S"-key.
call BlzTriggerRegisterPlayerKeyEvent( t, Player(i), WASD_KEY_S, 2, false )// Releases the "S"-key.
call BlzTriggerRegisterPlayerKeyEvent( t, Player(i), WASD_KEY_D, 2, true ) // Presses the "D"-key.
call BlzTriggerRegisterPlayerKeyEvent( t, Player(i), WASD_KEY_D, 2, false )// Releases the "D"-key.
//MEETAKEY 3 ??
call BlzTriggerRegisterPlayerKeyEvent( t, Player(i), WASD_KEY_W, 3, true ) // Presses the "W"-key.
call BlzTriggerRegisterPlayerKeyEvent( t, Player(i), WASD_KEY_W, 3, false )// Releases the "W"-key.
call BlzTriggerRegisterPlayerKeyEvent( t, Player(i), WASD_KEY_A, 3, true ) // Presses the "A"-key.
call BlzTriggerRegisterPlayerKeyEvent( t, Player(i), WASD_KEY_A, 3, false )// Releases the "A"-key.
call BlzTriggerRegisterPlayerKeyEvent( t, Player(i), WASD_KEY_S, 3, true ) // Presses the "S"-key.
call BlzTriggerRegisterPlayerKeyEvent( t, Player(i), WASD_KEY_S, 3, false )// Releases the "S"-key.
call BlzTriggerRegisterPlayerKeyEvent( t, Player(i), WASD_KEY_D, 3, true ) // Presses the "D"-key.
call BlzTriggerRegisterPlayerKeyEvent( t, Player(i), WASD_KEY_D, 3, false )// Releases the "D"-key.
//METAKEY 4 ALT
call BlzTriggerRegisterPlayerKeyEvent( t, Player(i), WASD_KEY_W, 4, true ) // Presses the "W"-key.
call BlzTriggerRegisterPlayerKeyEvent( t, Player(i), WASD_KEY_W, 4, false )// Releases the "W"-key.
call BlzTriggerRegisterPlayerKeyEvent( t, Player(i), WASD_KEY_A, 4, true ) // Presses the "A"-key.
call BlzTriggerRegisterPlayerKeyEvent( t, Player(i), WASD_KEY_A, 4, false )// Releases the "A"-key.
call BlzTriggerRegisterPlayerKeyEvent( t, Player(i), WASD_KEY_S, 4, true ) // Presses the "S"-key.
call BlzTriggerRegisterPlayerKeyEvent( t, Player(i), WASD_KEY_S, 4, false )// Releases the "S"-key.
call BlzTriggerRegisterPlayerKeyEvent( t, Player(i), WASD_KEY_D, 4, true ) // Presses the "D"-key.
call BlzTriggerRegisterPlayerKeyEvent( t, Player(i), WASD_KEY_D, 4, false )// Releases the "D"-key.
//METAKEY 5 ???
call BlzTriggerRegisterPlayerKeyEvent( t, Player(i), WASD_KEY_W, 5, true ) // Presses the "W"-key.
call BlzTriggerRegisterPlayerKeyEvent( t, Player(i), WASD_KEY_W, 5, false )// Releases the "W"-key.
call BlzTriggerRegisterPlayerKeyEvent( t, Player(i), WASD_KEY_A, 5, true ) // Presses the "A"-key.
call BlzTriggerRegisterPlayerKeyEvent( t, Player(i), WASD_KEY_A, 5, false )// Releases the "A"-key.
call BlzTriggerRegisterPlayerKeyEvent( t, Player(i), WASD_KEY_S, 5, true ) // Presses the "S"-key.
call BlzTriggerRegisterPlayerKeyEvent( t, Player(i), WASD_KEY_S, 5, false )// Releases the "S"-key.
call BlzTriggerRegisterPlayerKeyEvent( t, Player(i), WASD_KEY_D, 5, true ) // Presses the "D"-key.
call BlzTriggerRegisterPlayerKeyEvent( t, Player(i), WASD_KEY_D, 5, false )// Releases the "D"-key.
set i = i + 1
exitwhen(i > 24)
endloop
call TriggerAddAction( t, function PlayerKeyEvent_Actions )
//set t = null
call TimerStart(CreateTimer(), 0.03, true, function PlayerMoveEvent_Actions)
//set t = CreateTrigger( )
//call TriggerRegisterTimerEvent( t, 0.03, true )
//call TriggerAddAction( t, function PlayerMoveEvent_Actions )
endfunction
Thanks in advance
Last edited: