library CamFreeze initializer InitTrig_CF
globals
private constant real TOUT = 0.1 // Camera update rate
private constant real TPAN = 0.1 // Camera pan time
private constant integer PLRS = 1 // Max number of players
endglobals
globals
private integer P = 0
private timer TMR = CreateTimer()
private force FOR = CreateForce()
private trigger TRG = CreateTrigger()
private camerasetup array CSA
private hashtable ht = InitHashtable()
endglobals
function CF_LoadCam takes player p returns nothing
local integer pid = GetPlayerId(p)
if GetLocalPlayer() == p then
call SetCameraPosition(LoadReal(ht, pid, StringHash("camX")), LoadReal(ht, pid, StringHash("camY")))
call SetCameraField(CAMERA_FIELD_ANGLE_OF_ATTACK, bj_RADTODEG*LoadReal(ht, pid, StringHash("camAOA")), 0)
call SetCameraField(CAMERA_FIELD_FARZ, LoadReal(ht, pid, StringHash("camFarZ")), 0)
call SetCameraField(CAMERA_FIELD_FIELD_OF_VIEW, bj_RADTODEG*LoadReal(ht, pid, StringHash("camFOW")), 0)
call SetCameraField(CAMERA_FIELD_ROTATION, bj_RADTODEG*LoadReal(ht, pid, StringHash("camRot")), 0)
call SetCameraField(CAMERA_FIELD_TARGET_DISTANCE, LoadReal(ht, pid, StringHash("camDist")), 0)
call SetCameraField(CAMERA_FIELD_ZOFFSET, LoadReal(ht, pid, StringHash("camZOff")), 0)
endif
endfunction
function CF_SaveCam takes player p returns nothing
local integer pid = GetPlayerId(p)
if GetLocalPlayer() == p then
if not LoadBoolean(ht, GetPlayerId(p), 0) then
call SaveReal(ht, pid, StringHash("camX"), GetCameraTargetPositionX())
call SaveReal(ht, pid, StringHash("camY"), GetCameraTargetPositionY())
call SaveReal(ht, pid, StringHash("camAOA"), GetCameraField(CAMERA_FIELD_ANGLE_OF_ATTACK))
call SaveReal(ht, pid, StringHash("camFarZ"), GetCameraField(CAMERA_FIELD_FARZ))
call SaveReal(ht, pid, StringHash("camFOW"), GetCameraField(CAMERA_FIELD_FIELD_OF_VIEW))
call SaveReal(ht, pid, StringHash("camRot"), GetCameraField(CAMERA_FIELD_ROTATION))
call SaveReal(ht, pid, StringHash("camDist"), GetCameraField(CAMERA_FIELD_TARGET_DISTANCE))
call SaveReal(ht, pid, StringHash("camZOff"), GetCameraField(CAMERA_FIELD_ZOFFSET))
endif
endif
endfunction
private function Updt takes nothing returns boolean
if GetLocalPlayer() == GetFilterPlayer() then
call CameraSetupApplyForceDuration(CSA[GetPlayerId(GetFilterPlayer())], true, TPAN)
endif
return false
endfunction
private function Loop takes nothing returns nothing
call ForceEnumPlayers(FOR, function Updt)
endfunction
function CF_Release takes player p returns nothing
if LoadBoolean(ht, GetPlayerId(p), 0) then
set P = P - 1
if 0 == P then
call PauseTimer(TMR)
endif
//call EnableSelect(true, true)
call ForceRemovePlayer(FOR, p)
call SaveBoolean(ht, GetPlayerId(p), 0, false)
endif
endfunction
function CF_LockPos takes player p, real x, real y returns nothing
local integer id = GetPlayerId(p)
set CSA[id] = CSA[id+PLRS]
if not(LoadBoolean(ht, GetPlayerId(p), 0)) then
call ForceAddPlayer(FOR, p)
call SaveBoolean(ht, GetPlayerId(p), 0, true)
set P = P + 1
if 1 == P then
call TimerStart(TMR, TOUT, true, function Loop)
endif
endif
//call EnableSelect(false, false)
endfunction
function CF_LockCam takes player p, camerasetup c returns nothing
local integer id = GetPlayerId(p)
set CSA[id+PLRS] = CSA[id]
set CSA[id] = c
if not(LoadBoolean(ht, GetPlayerId(p), 0)) then
call ForceAddPlayer(FOR, p)
call SaveBoolean(ht, GetPlayerId(p), 0, true)
set P = P + 1
if 1 == P then
call TimerStart(TMR, TOUT, true, function Loop)
endif
endif
//call EnableSelect(false, false)
endfunction
private function InitTrig_CF takes nothing returns nothing
local integer i
local integer j
set i = 0
loop
exitwhen i == PLRS
set CSA[i] = CreateCameraSetup()
set CSA[i+PLRS] = CSA[i]
call CameraSetupSetField(CSA[i], CAMERA_FIELD_ANGLE_OF_ATTACK, 270, 0)
call CameraSetupSetField(CSA[i], CAMERA_FIELD_FARZ, 2000, 0)
call CameraSetupSetField(CSA[i], CAMERA_FIELD_FIELD_OF_VIEW, 90, 0)
call CameraSetupSetField(CSA[i], CAMERA_FIELD_ROLL, 0, 0)
call CameraSetupSetField(CSA[i], CAMERA_FIELD_ROTATION, 90, 0)
call CameraSetupSetField(CSA[i], CAMERA_FIELD_TARGET_DISTANCE, 800, 0)
call CameraSetupSetField(CSA[i], CAMERA_FIELD_ZOFFSET, 0, 0)
call CameraSetupSetDestPosition(CSA[i], 0, 0, 0)
set i = i + 1
endloop
endfunction
endlibrary