- Joined
- Oct 20, 2007
- Messages
- 353
[System] Press Spacebar and Backspaces Events
Following system allows to call functions when spacebar or backspace is pressed.
Made by me (D.O.G.). Please, give credits if used.
Map with working example attached to the post.
Few issues:
Available functions:
Functions to replace
Testing trigger for local version.
Following system allows to call functions when spacebar or backspace is pressed.
Made by me (D.O.G.). Please, give credits if used.
Map with working example attached to the post.
Few issues:
- System work in single player only!
- Requires dummy unit with TOWN HALL classification (for backspace event)
- System doesn't work when
SetCameraTargetController
(Lock Camera) used (however system includes replacement functions).
Available functions:
function AddSpacebarAction takes code a returns triggercondition
function AddBackspaceAction takes code a returns triggercondition
function RemoveSpacebarAction takes triggercondition c returns nothing
function RemoveBackspaceAction takes triggercondition c returns nothing
function ClearSpacebarActions takes nothing returns nothing
function ClearBackspaceActions takes nothing returns nothing
function EnableSpacebarEvent takes boolean enable returns nothing
function EnableBackspaceEvent takes boolean enable returns nothing
Functions to replace
SetCameraTargetController
:function LockCameraToUnit takes unit u returns nothing
function LockCameraToPoint takes real x, real y returns nothing
function LockCameraToPointLoc takes location loc returns nothing
function UnLockCamera takes nothing returns nothing
JASS:
library SpaceHandlerLocal initializer Init // by D.O.G. version 6.0
/* 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)
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)
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
Testing trigger for local version.
JASS:
library SpaceHandlerLocalTester initializer Init requires SpaceHandlerLocal
globals
private integer msg = 0
endglobals
private function SpacePressed takes nothing returns nothing
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0.0, 0.0, 1.0, "[" + I2S(msg) + "] You have pressed spacebar!")
set msg = msg + 1
endfunction
private function BackspacePressed takes nothing returns nothing
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0.0, 0.0, 1.0, "[" + I2S(msg) + "] You have pressed backspace!")
set msg = msg + 1
endfunction
private function Init takes nothing returns nothing
call AddSpacebarAction(function SpacePressed)
call AddBackspaceAction(function BackspacePressed)
call LockCameraToUnit(gg_unit_Hpal_0005)
call EnableSpacebarEvent(true)
call EnableBackspaceEvent(true)
endfunction
endlibrary
Multiplayer version. Works for now only for message showing))
I need help with this one)
Testing trigger for multiplayer.
I need help with this one)
JASS:
library SpaceHandler initializer Init // by D.O.G. version 5.5
globals
private real Space_X = 1000000000.0
private real Space_Y = 1000000000.0
private timer Space_Timer = CreateTimer()
private trigger Space_Actions = CreateTrigger()
private boolean Not_Sync = true
private gamecache Cache
private integer Local_I
private string Local_S
private player Space_Player = null
endglobals
function AddSpacebarAction takes code a returns triggercondition
return TriggerAddCondition(Space_Actions, Condition(a))
return null
endfunction
function GetSpacePlayer takes nothing returns player
return Space_Player
endfunction
private function Handler takes nothing returns nothing
local real x = GetCameraTargetPositionX()
local real y = GetCameraTargetPositionY()
if Not_Sync then
if GetStoredBoolean(Cache, "p", "0") then
call StoreBoolean(Cache, "p", "0", FALSE)
set Space_Player = Player(0)
call TriggerEvaluate(Space_Actions)
endif
if GetStoredBoolean(Cache, "p", "1") then
call StoreBoolean(Cache, "p", "1", FALSE)
set Space_Player = Player(1)
call TriggerEvaluate(Space_Actions)
endif
if GetStoredBoolean(Cache, "p", "2") then
call StoreBoolean(Cache, "p", "2", FALSE)
set Space_Player = Player(2)
call TriggerEvaluate(Space_Actions)
endif
if GetStoredBoolean(Cache, "p", "3") then
call StoreBoolean(Cache, "p", "3", FALSE)
set Space_Player = Player(3)
call TriggerEvaluate(Space_Actions)
endif
if GetStoredBoolean(Cache, "p", "4") then
call StoreBoolean(Cache, "p", "4", FALSE)
set Space_Player = Player(4)
call TriggerEvaluate(Space_Actions)
endif
if GetStoredBoolean(Cache, "p", "5") then
call StoreBoolean(Cache, "p", "5", FALSE)
set Space_Player = Player(5)
call TriggerEvaluate(Space_Actions)
endif
if GetStoredBoolean(Cache, "p", "6") then
call StoreBoolean(Cache, "p", "6", FALSE)
set Space_Player = Player(6)
call TriggerEvaluate(Space_Actions)
endif
if GetStoredBoolean(Cache, "p", "7") then
call StoreBoolean(Cache, "p", "7", FALSE)
set Space_Player = Player(7)
call TriggerEvaluate(Space_Actions)
endif
if GetStoredBoolean(Cache, "p", "8") then
call StoreBoolean(Cache, "p", "8", FALSE)
set Space_Player = Player(8)
call TriggerEvaluate(Space_Actions)
endif
if GetStoredBoolean(Cache, "p", "9") then
call StoreBoolean(Cache, "p", "9", FALSE)
set Space_Player = Player(9)
call TriggerEvaluate(Space_Actions)
endif
if GetStoredBoolean(Cache, "p", "a") then
call StoreBoolean(Cache, "p", "a", FALSE)
set Space_Player = Player(10)
call TriggerEvaluate(Space_Actions)
endif
if GetStoredBoolean(Cache, "p", "b") then
call StoreBoolean(Cache, "p", "b", FALSE)
set Space_Player = Player(11)
call TriggerEvaluate(Space_Actions)
endif
set Not_Sync = FALSE
//call TriggerSyncStart()
if ((x == Space_X) and (y == Space_Y)) then
call StoreBoolean(Cache, "p", Local_S, TRUE)
else
set Space_X = x
call StoreBoolean(Cache, "p", Local_S, FALSE)
endif
set Space_Y = (y + 0.01)
call SetCameraQuickPosition(Space_X, Space_Y)
call SyncStoredBoolean(Cache, "p", Local_S)
call TriggerSyncReady()
set Not_Sync = TRUE
endif
endfunction
private function Init takes nothing returns nothing
call FlushGameCache(InitGameCache("s"))
set Cache = InitGameCache("s")
set Local_I = GetPlayerId(GetLocalPlayer())
set Local_S = SubString("0123456789abcdef", Local_I, Local_I + 1)
call TimerStart(Space_Timer, 0.1250, true, function Handler)
endfunction
endlibrary
Testing trigger for multiplayer.
JASS:
library SpaceHandlerTester initializer Init requires SpaceHandler
private function SpacePressed takes nothing returns nothing
local player p = GetSpacePlayer() // This function must be called only 1 time
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0.0, 0.0, 3.0, "Spacebar is pressed by: " + GetPlayerName(p))
//call UnitApplyTimedLife(CreateUnit(p, 'hwat', -1000, -500, 0.0), 'BHwe', 3.0) // this causes desync
endfunction
private function Init takes nothing returns nothing
call AddSpacebarAction(function SpacePressed)
endfunction
endlibrary
Attachments
Last edited: