- Joined
- Oct 9, 2015
- Messages
- 721
Is there any way to detect spacebar press?
if ((x == Space_X) and (y == Space_Y)) then
call TriggerEvaluate(Space_Actions)
else
The snippet works in multiplayer as long as you keep your actions in local player blocks.
library SpaceHandlerLocal initializer Init // by D.O.G. version 6.0
private function SpacebarAction takes nothing returns nothing
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0.0, 0.0, 1.0, "You have pressed spacebar!")
endfunction
private function BackspaceAction takes nothing returns nothing
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0.0, 0.0, 1.0, "You have pressed backspace!")
endfunction
/* SETTINGS */
globals
private constant real Period = 0.01562500
// Unit must have TOWN HALL classification!!!
private constant integer DummyUnit = 'u000'
endglobals
/* SETTINGS END */
globals
private real Space_X = 1000000000.0
private real Space_Y = 1000000000.0
private real Backspace_X = 1000000000.0
private real Backspace_Y = 1000000000.0
private real Lock_X = 1000000000.0
private real Lock_Y = 1000000000.0
private boolean Space_Enabled = false
private boolean Backspace_Enabled = false
private timer Timer = CreateTimer()
private trigger Space_Actions = CreateTrigger()
private trigger Backspace_Actions = CreateTrigger()
private unit Backspace_Unit = null
private unit Lock_Unit = null
private integer Lock_Mode = 0
endglobals
/*
function AddSpacebarAction takes code a returns triggercondition
return TriggerAddCondition(Space_Actions, Condition(a))
return null
endfunction
function AddBackspaceAction takes code a returns triggercondition
return TriggerAddCondition(Backspace_Actions, Condition(a))
return null
endfunction
function RemoveSpacebarAction takes triggercondition c returns nothing
call TriggerRemoveCondition(Space_Actions, c)
endfunction
function RemoveBackspaceAction takes triggercondition c returns nothing
call TriggerRemoveCondition(Backspace_Actions, c)
endfunction
function ClearSpacebarActions takes nothing returns nothing
call TriggerClearConditions(Space_Actions)
endfunction
function ClearBackspaceActions takes nothing returns nothing
call TriggerClearConditions(Backspace_Actions)
endfunction
*/
function EnableSpacebarEvent takes boolean enable returns nothing
local integer p
set Space_Enabled = enable
if not enable then
set p = GetPlayerStartLocation(GetLocalPlayer())
call SetCameraQuickPosition(GetStartLocationX(p), GetStartLocationY(p))
endif
endfunction
function EnableBackspaceEvent takes boolean enable returns nothing
set Backspace_Enabled = enable
if not enable then
call RemoveUnit(Backspace_Unit)
endif
endfunction
function LockCameraToUnit takes unit u returns nothing
set Lock_Unit = u
set Lock_Mode = 1
endfunction
function LockCameraToPoint takes real x, real y returns nothing
set Lock_X = x
set Lock_Y = y
set Lock_Mode = 2
endfunction
function LockCameraToPointLoc takes location loc returns nothing
set Lock_X = GetLocationX(loc)
set Lock_Y = GetLocationY(loc)
set Lock_Mode = 2
endfunction
function UnLockCamera takes nothing returns nothing
set Lock_Unit = null
set Lock_Mode = 0
endfunction
private function Handler takes nothing returns nothing
local real x = GetCameraTargetPositionX()
local real y = GetCameraTargetPositionY()
if Lock_Mode == 1 then
set Lock_X = GetUnitX(Lock_Unit)
set Lock_Y = GetUnitY(Lock_Unit)
endif
if Space_Enabled then
if ((x == Space_X) and (y == Space_Y)) then
//call TriggerEvaluate(Space_Actions)
call SpacebarAction()
else
set Space_X = x
if Lock_Mode > 0 then
call PanCameraTo(Lock_X, Lock_Y)
endif
endif
set Space_Y = y + 0.01
call SetCameraQuickPosition(Space_X, Space_Y)
endif
if Backspace_Enabled then
if ((x == Backspace_X) and (y == Backspace_Y)) then
//call TriggerEvaluate(Backspace_Actions)
call BackspaceAction()
else
set Backspace_Y = y
if Lock_Mode > 0 then
call PanCameraTo(Lock_X, Lock_Y)
endif
endif
set Backspace_X = x + 0.01
call RemoveUnit(Backspace_Unit)
set Backspace_Unit = CreateUnit(GetLocalPlayer(), DummyUnit, Backspace_X, Backspace_Y, 270.0)
call SetUnitPosition(Backspace_Unit, Backspace_X, Backspace_Y)
endif
endfunction
private function Init takes nothing returns nothing
call TimerStart(Timer, Period, true, function Handler)
endfunction
endlibrary