- Joined
- Sep 20, 2015
- Messages
- 385
So the title is self explanatory of what my problem is. I use this two blocks of code. But the animation is still the same. I just started to use JASS and i need some help
Trigger of the demo map made by lolreported.
Trigger of the demo map made by lolreported.
JASS:
globals
unit array WASD_PlayerUnit
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
endglobals
function PlayerMoveEvent_Actions takes nothing returns nothing
local integer i = 0
local location loc1 = null
local location loc2 = null
loop
exitwhen(i > 24)
if WASD_IsKeyDown_W[i] == true and WASD_IsKeyDown_D[i] == false and WASD_IsKeyDown_A[i] == false and WASD_IsKeyDown_S[i] == false then
set loc1 = Location(GetUnitX(udg_PlayerUnit[i]), GetUnitY(udg_PlayerUnit[i]))
set loc2 = PolarProjectionBJ(loc1, udg_WASD_PlayerMoveDistance[i], 90.0)
//call SetUnitFacing(udg_PlayerUnit[i], 90)
set udg_WASD_Unit_Facing_Direction[i] = 90
call SetUnitX( udg_PlayerUnit[i],GetLocationX(loc2))
call SetUnitY( udg_PlayerUnit[i],GetLocationY(loc2))
call ConditionalTriggerExecute( gg_trg_WASD_FacingAnim )
call RemoveLocation(loc1)
call RemoveLocation(loc2)
elseif WASD_IsKeyDown_S[i] == true and WASD_IsKeyDown_D[i] == false and WASD_IsKeyDown_A[i] == false and WASD_IsKeyDown_W[i] == false then
set loc1 = Location(GetUnitX(udg_PlayerUnit[i]), GetUnitY(udg_PlayerUnit[i]))
set loc2 = PolarProjectionBJ(loc1, udg_WASD_PlayerMoveDistance[i], 270.0)
//call SetUnitFacing(udg_PlayerUnit[i], 270)
set udg_WASD_Unit_Facing_Direction[i] = 270
call SetUnitX( udg_PlayerUnit[i],GetLocationX(loc2))
call SetUnitY( udg_PlayerUnit[i],GetLocationY(loc2))
call ConditionalTriggerExecute( gg_trg_WASD_FacingAnim )
call RemoveLocation(loc1)
call RemoveLocation(loc2)
elseif WASD_IsKeyDown_A[i] == true and WASD_IsKeyDown_D[i] == false and WASD_IsKeyDown_W[i] == false and WASD_IsKeyDown_S[i] == false then
set loc1 = Location(GetUnitX(udg_PlayerUnit[i]), GetUnitY(udg_PlayerUnit[i]))
set loc2 = PolarProjectionBJ(loc1, udg_WASD_PlayerMoveDistance[i], 180.0)
//call SetUnitFacing(udg_PlayerUnit[i], 180)
set udg_WASD_Unit_Facing_Direction[i] = 180
call SetUnitX( udg_PlayerUnit[i],GetLocationX(loc2))
call SetUnitY( udg_PlayerUnit[i],GetLocationY(loc2))
call ConditionalTriggerExecute( gg_trg_WASD_FacingAnim )
call RemoveLocation(loc1)
call RemoveLocation(loc2)
elseif WASD_IsKeyDown_D[i] and WASD_IsKeyDown_W[i] == false and WASD_IsKeyDown_A[i] == false and WASD_IsKeyDown_S[i] == false then
set loc1 = Location(GetUnitX(udg_PlayerUnit[i]), GetUnitY(udg_PlayerUnit[i]))
set loc2 = PolarProjectionBJ(loc1, udg_WASD_PlayerMoveDistance[i], 0.0)
//call SetUnitFacing(udg_PlayerUnit[i], 0)
set udg_WASD_Unit_Facing_Direction[i] = 0
call SetUnitX( udg_PlayerUnit[i],GetLocationX(loc2))
call SetUnitY( udg_PlayerUnit[i],GetLocationY(loc2))
call ConditionalTriggerExecute( gg_trg_WASD_FacingAnim )
call RemoveLocation(loc1)
call RemoveLocation(loc2)
endif
//OTHER DIRECTIONS TESTS IF AND -----DIAGONALS---
if (WASD_IsKeyDown_W[i]) and WASD_IsKeyDown_D[i] and WASD_IsKeyDown_A[i] == false and WASD_IsKeyDown_S[i] == false then
set loc1 = Location(GetUnitX(udg_PlayerUnit[i]), GetUnitY(udg_PlayerUnit[i]))
set loc2 = PolarProjectionBJ(loc1, udg_WASD_PlayerMoveDistance[i], 45.0)
//call SetUnitFacing(udg_PlayerUnit[i], 45)
set udg_WASD_Unit_Facing_Direction[i] = 45
call SetUnitX( udg_PlayerUnit[i],GetLocationX(loc2))
call SetUnitY( udg_PlayerUnit[i],GetLocationY(loc2))
call ConditionalTriggerExecute( gg_trg_WASD_FacingAnim )
call RemoveLocation(loc1)
call RemoveLocation(loc2)
elseif (WASD_IsKeyDown_W[i]) and WASD_IsKeyDown_A[i] and WASD_IsKeyDown_D[i] == false and WASD_IsKeyDown_S[i] == false then
set loc1 = Location(GetUnitX(udg_PlayerUnit[i]), GetUnitY(udg_PlayerUnit[i]))
set loc2 = PolarProjectionBJ(loc1, udg_WASD_PlayerMoveDistance[i], 135.0)
//call SetUnitFacing(udg_PlayerUnit[i], 135)
set udg_WASD_Unit_Facing_Direction[i] = 135
call SetUnitX( udg_PlayerUnit[i],GetLocationX(loc2))
call SetUnitY( udg_PlayerUnit[i],GetLocationY(loc2))
call ConditionalTriggerExecute( gg_trg_WASD_FacingAnim )
call RemoveLocation(loc1)
call RemoveLocation(loc2)
elseif (WASD_IsKeyDown_S[i]) and WASD_IsKeyDown_D[i] and WASD_IsKeyDown_A[i] == false and WASD_IsKeyDown_W[i] == false then
set loc1 = Location(GetUnitX(udg_PlayerUnit[i]), GetUnitY(udg_PlayerUnit[i]))
set loc2 = PolarProjectionBJ(loc1, udg_WASD_PlayerMoveDistance[i], 315.0)
set udg_WASD_Unit_Facing_Direction[i] = 315
call SetUnitX( udg_PlayerUnit[i],GetLocationX(loc2))
call SetUnitY( udg_PlayerUnit[i],GetLocationY(loc2))
call ConditionalTriggerExecute( gg_trg_WASD_FacingAnim )
call RemoveLocation(loc1)
call RemoveLocation(loc2)
elseif WASD_IsKeyDown_S[i] == true and WASD_IsKeyDown_A[i] == true and WASD_IsKeyDown_D[i] == false and WASD_IsKeyDown_W[i] == false then
set loc1 = Location(GetUnitX(udg_PlayerUnit[i]), GetUnitY(udg_PlayerUnit[i]))
set loc2 = PolarProjectionBJ(loc1, udg_WASD_PlayerMoveDistance[i], 225.0)
set udg_WASD_Unit_Facing_Direction[i] = 225
call SetUnitX( udg_PlayerUnit[i],GetLocationX(loc2))
call SetUnitY( udg_PlayerUnit[i],GetLocationY(loc2))
call ConditionalTriggerExecute( gg_trg_WASD_FacingAnim )
call RemoveLocation(loc1)
call RemoveLocation(loc2)
endif
set i = i + 1
endloop
set loc1 = null
set loc2 = null
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=0
//Not used here, but this way we can detect the meta-key.
//local integer metaKeyPressed = BlzGetTriggerPlayerMetaKey()
loop
exitwhen ( i > 24 )
if (osKeyPressed == WASD_KEY_W) then
set WASD_IsKeyDown_W[GetPlayerId(GetTriggerPlayer())] = isKeyDown
if isKeyDown == true then
set udg_WASD_IsKeyDown_W[GetPlayerId(GetTriggerPlayer())] = true
call SetUnitAnimationByIndex (udg_PlayerUnit[i], udg_AnimationIndexArray[i])
else
set udg_WASD_IsKeyDown_W[GetPlayerId(GetTriggerPlayer())] = false
endif
call ConditionalTriggerExecute( gg_trg_WASDKeyPressed )
elseif (osKeyPressed == WASD_KEY_A) then
set WASD_IsKeyDown_A[GetPlayerId(GetTriggerPlayer())] = isKeyDown
if isKeyDown == true then
set udg_WASD_IsKeyDown_A[GetPlayerId(GetTriggerPlayer())] = true
call SetUnitAnimationByIndex (udg_PlayerUnit[i], udg_AnimationIndexArray[i])
else
set udg_WASD_IsKeyDown_A[GetPlayerId(GetTriggerPlayer())] = false
endif
call ConditionalTriggerExecute( gg_trg_WASDKeyPressed )
elseif (osKeyPressed == WASD_KEY_S) then
set WASD_IsKeyDown_S[GetPlayerId(GetTriggerPlayer())] = isKeyDown
if isKeyDown == true then
set udg_WASD_IsKeyDown_S[GetPlayerId(GetTriggerPlayer())] = true
call SetUnitAnimationByIndex (udg_PlayerUnit[i], udg_AnimationIndexArray[i])
else
set udg_WASD_IsKeyDown_S[GetPlayerId(GetTriggerPlayer())] = false
endif
call ConditionalTriggerExecute( gg_trg_WASDKeyPressed )
elseif (osKeyPressed == WASD_KEY_D) then
set WASD_IsKeyDown_D[GetPlayerId(GetTriggerPlayer())] = isKeyDown
if isKeyDown == true then
set udg_WASD_IsKeyDown_S[GetPlayerId(GetTriggerPlayer())] = true
call SetUnitAnimationByIndex (udg_PlayerUnit[i], udg_AnimationIndexArray[i])
else
set udg_WASD_IsKeyDown_S[GetPlayerId(GetTriggerPlayer())] = false
endif
call ConditionalTriggerExecute( gg_trg_WASDKeyPressed )
endif
set i = i + 1
endloop
endfunction
//===========================================================================
function InitTrig_WASD_PlayerKeyEvent_8_dire 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
exitwhen(i > 24)
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.
set i = i + 1
endloop
call TriggerAddAction( t, function PlayerKeyEvent_Actions )
set t = null
set t = CreateTrigger( )
call TriggerRegisterTimerEvent( t, 0.03, true )
call TriggerAddAction( t, function PlayerMoveEvent_Actions )
endfunction
-
WASD FacingAnim
-
Events
-
Conditions
-
Actions
-
Custom script: local integer i = GetPlayerId(GetTriggerPlayer())
-
Custom script: if ( ( AcosBJ(udg_WASD_Unit_Facing_Direction[i]) - AngleBetweenPoints(GetUnitLoc(udg_PlayerUnit[i]), udg_MousePosition[i]) ) < 45.00 ) then
-
Custom script: call SetUnitTimeScale(udg_PlayerUnit[i], -1)
-
Custom script: else
-
Custom script: call SetUnitTimeScale(udg_PlayerUnit[i], 1)
-
Custom script: endif
-
Custom script: if ( not ( ( AcosBJ(udg_WASD_Unit_Facing_Direction[i]) - AngleBetweenPoints(GetUnitLoc(udg_PlayerUnit[i]), udg_MousePosition[i]) ) < 45.00 ) ) then
-
Custom script: if ( not ( ( AcosBJ(udg_WASD_Unit_Facing_Direction[i]) - AngleBetweenPoints(GetUnitLoc(WASD_PlayerUnit[i]), udg_MousePosition[i]) ) < 45.00 ) ) then
-
Custom script: call SetUnitTimeScale(udg_PlayerUnit[i], -1)
-
-
-
UnitFacing
-
Events
-
Player - Player 1 (Red) issues Mouse Move event
-
-
Conditions
-
Actions
-
Set MousePosition[(Player number of (Triggering player))] = (Mouse Position for Triggered Mouse Event)
-
Unit - Make PlayerUnit[1] face (Angle from (Position of PlayerUnit[1]) to MousePosition[1]) over 0.00 seconds
-
Custom script: call SetUnitFacing(udg_PlayerUnit[GetPlayerId(GetTriggerPlayer())], AngleBetweenPoints(GetUnitLoc(udg_PlayerUnit[GetPlayerId(GetTriggerPlayer())]),udg_MousePosition[GetPlayerId(GetTriggerPlayer())]))
-
Custom script: call RemoveLocation (udg_MousePosition[GetPlayerId(GetTriggerPlayer())])
-
-