- Joined
- Jun 23, 2007
- Messages
- 4,066
Requires:
Code:
Example:
Code:
JASS:
library SpacebarDetect initializer Init requires SyncInteger
/***************************************************************
*
* v1.0.3 by TriggerHappy
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
*
* Allows detection of when the spacebar is pressed. This library does not
* work with a locked camera. You must also use SetCameraQuickPositionEx
* if you want to set a custom spacebar point.
* _________________________________________________________________________
* 1. Installation
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
* Copy the script and it's requirements to your map and save it (requires JassHelper *or* JNGP)
* _________________________________________________________________________
* 2. API
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
* function TriggerRegisterSpacebarEvent takes trigger t returns nothing
* function OnSpacebarPress takes filterfunc func returns triggercondition
* function SpacebarRemoveEvent takes triggercondition func returns nothing
*
* function SetCameraQuickPositionEx takes real x, real y returns nothing
*
***************************************************************/
globals
// config
private constant real CHECK_INTERVAL = 0.03
private constant real DETECT_X = 0.142 // random
private constant real DETECT_Y = 0.241
// end
private real FireEvent = 0
private trigger EventTrig = CreateTrigger()
private integer NotifyID = 0
private real QP_X = DETECT_X + 0.1
private real QP_Y = DETECT_Y + 0.1
private SelectionSync Synchronizer = 0
endglobals
function OnSpacebarPress takes filterfunc func returns triggercondition
return TriggerAddCondition(EventTrig, func)
endfunction
function SpacebarRemoveEvent takes triggercondition func returns nothing
call TriggerRemoveCondition(EventTrig, func)
endfunction
function TriggerRegisterSpacebarEvent takes trigger t returns nothing
call TriggerRegisterVariableEvent(t, SCOPE_PRIVATE + "FireEvent", EQUAL, 1)
endfunction
function SetCameraQuickPositionEx takes real x, real y returns nothing
set QP_X = x
set QP_Y = y
endfunction
private function FireEvents takes nothing returns nothing
set FireEvent = 1
set FireEvent = 0.0
call TriggerEvaluate(EventTrig)
endfunction
private function OnSync takes nothing returns boolean
if (GetSyncedInstance() == Synchronizer) then
call FireEvents()
endif
return false
endfunction
private function OnUpdate takes nothing returns nothing
local real x = GetCameraTargetPositionX()
local real y = GetCameraTargetPositionY()
call SetCameraQuickPosition(DETECT_X, DETECT_Y)
if (x == DETECT_X and y == DETECT_Y) then
//call BJDebugMsg("yes")
call SetCameraPosition(QP_X, QP_Y)
call Synchronizer.syncValue(GetLocalPlayer(), 1)
endif
endfunction
private function Init takes nothing returns nothing
set Synchronizer = SelectionSync.create() // creates many unused dummy units, will fix in future
call TimerStart(CreateTimer(), CHECK_INTERVAL, true, function OnUpdate)
call OnSyncInteger(Filter(function OnSync))
endfunction
endlibrary
Example:
JASS:
scope SpacebarTest initializer Init
private function Actions takes nothing returns nothing
local player p = GetTriggerPlayer()
call BJDebugMsg(GetPlayerName(p) + " pressed the spacebar.")
endfunction
//===========================================================================
private function Init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterSpacebarEvent(t)
call TriggerAddAction(t, function Actions)
endfunction
endscope
Attachments
Last edited: