TriggerHappy
...
- Reaction score
- 341
SpacebarDetection
TriggerHappy187
Introduction
This is a system that can detect whenever the spacebar is hit.
But before anyone uses it, your map must not contain any of the following;
- Locked cameras (yes units count).
- Can't set spacebar points via triggers.
The Code
JASS:
//***************************************************************************
//*
//* SpacebarDetect - By TriggerHappy187
//*
//***************************************************************************
//*
//* CONS
//* - Cannot define custom spacebar points.
//* - Doesn't work if camera is locked
//
//* Only added cons because the pros obvious (it detects when a spacebar is hit)
//*
//***************************************************************************
//* configurables
library SpacebarDetect initializer InitTrig
globals
private constant real TIMEOUT = 0.03 // Accuracy of spacebar detect.
endglobals
//* endconfigurables
//***************************************************************************
//*
//* Don't modify below this line!
//*
//***************************************************************************
globals
private integer COUNT = 0
private trigger array T
private player array P
private real array X
private real array Y
private timer TIMER = CreateTimer()
endglobals
private function callback takes nothing returns nothing
local integer i = 0
local real x
local real y
local integer c
local boolean b
loop
exitwhen i > COUNT
set b = GetLocalPlayer() == P<i>
set c = GetPlayerId(P<i>)
if b then
set x = GetCameraTargetPositionX()
set y = GetCameraTargetPositionY()
endif
if x == X[c] and y == Y[c] then
if TriggerEvaluate(T<i>) and IsTriggerEnabled(T<i>) then
call TriggerExecute(T<i>)
endif
endif
set X[c] = x+.1
set Y[c] = y+.1
if b then
call SetCameraQuickPosition(X[c], Y[c])
endif
set i = i + 1
endloop
endfunction
function TriggerRegisterPlayerSpacebarEvent takes trigger whichTrigger, player whichPlayer returns nothing
set T[COUNT] = whichTrigger
set P[COUNT] = whichPlayer
set COUNT = COUNT + 1
if COUNT == 1 then
call TimerStart(TIMER, TIMEOUT, true, function callback)
endif
endfunction
private function InitTrig takes nothing returns nothing
local integer i = 0
loop
exitwhen i > 11
if GetLocalPlayer() == Player(i) then
set X<i> = GetCameraTargetPositionX()+.1
set Y<i> = GetCameraTargetPositionY()+.1
call SetCameraQuickPosition(X<i>, Y<i>)
endif
set i = i + 1
endloop
endfunction
endlibrary</i></i></i></i></i></i></i></i></i>
Demo
Check out the demo
Whenever you press the spacebar your unit will jump.