- Joined
- Mar 29, 2011
- Messages
- 2,607
I want to detect when player's camera is inside a region, is there a way to do this? The camera is not locked in my map.
You will need to periodically poll the player's camera target if it is inside the point is inside the desired rect/region. Be aware that the player camera target is probably a local value (I cannot find a native that takes a player value) so the value of each player will have to be synchronized before use if the map is multiplayer otherwise players will go out of sync.I want to detect when player's camera is inside a region, is there a way to do this? The camera is not locked in my map.
constant native GetCameraTargetPositionX takes nothing returns real
constant native GetCameraTargetPositionY takes nothing returns real
native IsPointInRegion takes region whichRegion, real x, real y returns boolean
if Cam_XY_IsAtRegion...() then
// For some player this is true
Action_A()
else
// For some player this is not true
Action_B()
endif
Cam_XY_IsAtRegion...()
The player's camera can never be inside a point as a point has no area or volume for the camera to be in.when player's camera is inside a point
function SyncPlayerCameraXYZ takes player whichPlayer returns nothing
local string spid = I2S(GetPlayerId(whichPlayer))
if GetLocalPlayer() == whichPlayer then
// Locally store camera position
call StoreReal(udg_GPCXY_Gamecache, spid, "X", GetCameraTargetPositionX())
call StoreReal(udg_GPCXY_Gamecache, spid, "Y", GetCameraTargetPositionY())
call StoreReal(udg_GPCXY_Gamecache, spid, "Z", GetCameraTargetPositionZ())
// Order game cache to synchronize previous-stored coordinates
call SyncStoredReal(udg_GPCXY_Gamecache, spid, "X")
call SyncStoredReal(udg_GPCXY_Gamecache, spid, "Y")
call SyncStoredReal(udg_GPCXY_Gamecache, spid, "Z")
endif
call TriggerSyncStart()
call TriggerSyncReady()
endfunction
function SyncCameraXYZ takes nothing returns nothing
local integer i = 0
local string spid = ""
local player locp = GetLocalPlayer()
loop
exitwhen i > 11
if locp == Player(i) then
set spid = I2S(GetPlayerId(Player(i)))
// Locally store camera position
call StoreReal(udg_GPCXY_Gamecache, spid, "X", GetCameraTargetPositionX())
call StoreReal(udg_GPCXY_Gamecache, spid, "Y", GetCameraTargetPositionY())
call StoreReal(udg_GPCXY_Gamecache, spid, "Z", GetCameraTargetPositionZ())
// Order game cache to synchronize previous-stored coordinates
call SyncStoredReal(udg_GPCXY_Gamecache, spid, "X")
call SyncStoredReal(udg_GPCXY_Gamecache, spid, "Y")
call SyncStoredReal(udg_GPCXY_Gamecache, spid, "Z")
endif
set i = i + 1
endloop
set locp = null
call TriggerSyncStart()
call TriggerSyncReady()
endfunction
function IsPlayerCameraInRect takes player whichPlayer, rect whichRect returns boolean
local string spid = I2S(GetPlayerId(whichPlayer))
local real x = GetStoredReal(udg_GPCXY_Gamecache, spid, "X")
local real y = GetStoredReal(udg_GPCXY_Gamecache, spid, "Y")
return x >= GetRectMinX(whichRect) and x <= GetRectMaxX(whichRect) and y >= GetRectMinY(whichRect) and y <= GetRectMaxY(whichRect)
endfunction
// Optional
function GetPlayerCameraX takes player whichPlayer returns real
return GetStoredReal(udg_GPCXY_Gamecache, I2S(GetPlayerId(whichPlayer)), "X")
endfunction
function GetPlayerCameraY takes player whichPlayer returns real
return GetStoredReal(udg_GPCXY_Gamecache, I2S(GetPlayerId(whichPlayer)), "Y")
endfunction
function GetPlayerCameraZ takes player whichPlayer returns real
return GetStoredReal(udg_GPCXY_Gamecache, I2S(GetPlayerId(whichPlayer)), "Z")
endfunction
//===========================================================================
function InitTrig_GetPlayerCameraXY takes nothing returns nothing
if udg_GPCXY_Gamecache == null then
call FlushGameCache(InitGameCache("HIVEGPCXY"))
set udg_GPCXY_Gamecache = InitGameCache("HIVEGPCXY")
endif
endfunction
I've come up with the following code, and I have tested it in a LAN with a virtual machine running windows 7. It didn't get desync'd. Also, I don't have friends who play warcraft 3 anymore, so I can't test it on BNet.
It doesn't. It's safe to use.I'm afraid to say that it desyncs your game as you are modifying a unit's pos/state for only for a certain player.
It has an extremely high chance it will. If that unit interacts with anything nearby its new location, or fails to interact with anything nearby its old location an OoS will occur.It doesn't.