quraji
zap
- Reaction score
- 144
CameraPanEvent
v1.0
v1.0
This is a singleplayer ONLY snippet, until I can figure out how to make it work in multiplayer as well (without desynchs).
Requirements:
-Jass NewGen
-Event by Jesus4Lyf
What is it?
It's an event to detect when a player pans his camera :thup:
JASS:
// CameraPanEvent - by quraji - v1.01
//
// What is it?
// This library adds a CameraPanEvent event that will fire
// when a player pans his camera.
//
// How do I use it?
// Use the provided functions:
//
// TriggerRegisterCameraPanEvent(trigger whichTrigger)
// - this will register the CameraPan event to whichTrigger
// Ex:
// local trigger t = CreateTrigger()
// call TriggerRegisterCameraPanEvent(t)
// call TriggerAddAction(t, function DoStuffOnCameraPan)
//
// GetCameraPanEventPlayer()
// - this will return the player that fired the event
//
// The only thing you need to configure is UPDATE_PERIOD below.
library CameraPanEvent initializer init requires Event
// CONFIG
globals
private constant real UPDATE_PERIOD = .1 // how quickly the system will react to a pan event
endglobals
// ENDCONFIG
globals
player CameraPanEventPlayer
private timer T = CreateTimer()
private Event e
private real camX
private real camY
endglobals
private function update takes nothing returns nothing
local real x = GetCameraTargetPositionX()
local real y = GetCameraTargetPositionY()
if (camX!=x or camY!=y) then
set CameraPanEventPlayer = GetLocalPlayer()
call e.fire()
endif
set camX = x
set camY = y
endfunction
private function init takes nothing returns nothing
set e = Event.create()
set camX = GetStartLocationX(GetPlayerStartLocation(GetLocalPlayer())) // so the event doesn't fire as soon as the game loads
set camY = GetStartLocationY(GetPlayerStartLocation(GetLocalPlayer()))
call TimerStart(T, UPDATE_PERIOD, true, function update)
endfunction
function GetCameraPanEventPlayer takes nothing returns player
return CameraPanEventPlayer
endfunction
function TriggerRegisterCameraPanEvent takes trigger whichTrigger returns nothing
call e.register(whichTrigger)
endfunction
endlibrary
Changelog (because changelogs are fun):
v1.10 - Edited this to work better with single player (until I can figure out how to make it work in multiplayer)
v1.01 - Fixed a bug that would cause desynchs, thanks to Troll-Brain for pointing it out EDIT: Nevermind, I can't fix it at the moment
v1.00 - Release
v1.01 - Fixed a bug that would cause desynchs, thanks to Troll-Brain for pointing it out EDIT: Nevermind, I can't fix it at the moment
v1.00 - Release
Notes:
Thanks to Jesus4Lyf for the submission template which I copied.