Player current camera distance

Status
Not open for further replies.
Level 10
Joined
Apr 18, 2012
Messages
96
Is there a way get this to refer to a player of choice in multiplayer?

upload_2020-12-11_17-24-17.png
 
[Solved] - Target of (Current Camera) desync

Tasyen posted the code for a fix at the bottom.

If you use his code you also need two global Real (array) variables called:
PlayerCamX
PlayerCamY

Then you reference them by plugging the desired player's number into the index. So like this:
  • Actions
    • Set Variable TempPoint = (Point(PlayerCamX[(Player number of (Triggering player))], PlayerCamY[(Player number of (Triggering player))]))
    • Special Effect - Create a special effect at TempPoint using Abilities\Spells\Human\ThunderClap\ThunderClapCaster.mdl
His code updates the X/Y once every 1.00 second, so you may want to lower the interval. Otherwise, it'll be inconsistent.
 
Last edited:
Ah, my mistake, but it should be an easy fix. Take the code Tasyen made and adjust it to this:

vJASS:
function SyncCamDataRead takes nothing returns nothing
   if BlzGetTriggerSyncPrefix() == "SyncCamX" then
       set udg_PlayerCamX[GetConvertedPlayerId(GetTriggerPlayer())] = S2R(BlzGetTriggerSyncData())
   elseif BlzGetTriggerSyncPrefix() == "SyncCamY" then
       set udg_PlayerCamY[GetConvertedPlayerId(GetTriggerPlayer())] = S2R(BlzGetTriggerSyncData())
   else
       set udg_PlayerCamDist[GetConvertedPlayerId(GetTriggerPlayer())] = S2R(BlzGetTriggerSyncData())
   endif
endfunction
function SyncCamDataSend takes nothing returns nothing
   call BlzSendSyncData("SyncCamX", R2S(GetCameraTargetPositionX()))
   call BlzSendSyncData("SyncCamY", R2S(GetCameraTargetPositionY()))
   call BlzSendSyncData("SyncCamDist", R2S(GetCameraEyePositionZ()))
endfunction
function SyncCamDataInit takes nothing returns nothing
   local integer playerIndex = 0
   local trigger trig = CreateTrigger()
   call TriggerAddAction(trig, function SyncCamDataRead)
   loop
       call BlzTriggerRegisterPlayerSyncEvent(trig, Player(playerIndex), "SyncCamX", false)
       call BlzTriggerRegisterPlayerSyncEvent(trig, Player(playerIndex), "SyncCamY", false)
       call BlzTriggerRegisterPlayerSyncEvent(trig, Player(playerIndex), "SyncCamDist", false)
       set playerIndex = playerIndex + 1
       exitwhen playerIndex == bj_MAX_PLAYER_SLOTS
   endloop
   call TimerStart(CreateTimer(), 0.1, true, function SyncCamDataSend) // Adjust interval
endfunction

You'll also need another Real (array) variable:
PlayerCamDist

Edit: Fixed and attached an example map. I THINK this is what you wanted.
 

Attachments

Last edited:
All of the complex stuff is done behind the scenes.

Don't be intimidated by the code, it's very easy to get this working:

Step 1: In the Trigger Editor, press Control + U to create a New Custom Script. Then copy and paste the code I posted above into this Script.

Step 2: Create a new Trigger that looks like this:
  • Start Camera Sync
    • Events
      • Time - Elapsed game time is 0.10 seconds
    • Conditions
    • Actions
      • Custom script: call SyncCamDataInit()
IMPORTANT - Make sure this new Trigger is positioned below the Custom Script inside the Trigger Editor. Otherwise, you'll get an error.

Step 3: Create 3 new Real variables. Check on Array for all of them. Then make sure their names are EXACTLY as follows: PlayerCamX, PlayerCamY, PlayerCamDist

Done.


Now to take advantage of this system you simply reference any of these variables.

For example:

PlayerCamDist[1] will always be equal to Player 1's camera distance. PlayerCamDist[2] will be equal to Player 2's camera distance. Simple enough.
  • Show player 1 camera distance
    • Events
      • Time - Every 0.15 seconds of game time
    • Conditions
    • Actions
      • Game - Display to (All players) for 30.00 seconds the text: (String(PlayerCamDist[1]))
It also has PlayerCamX/Y to get the position of the player's Camera. This is done using x,y coordinates but you can very easily convert those to a Point -> Convert coordinates to a Point.
  • Actions
    • Set Variable TempPoint = (Point(PlayerCamX[1], PlayerCamY[1]))
    • Special Effect - Create a special effect at TempPoint using Abilities\Spells\Human\ThunderClap\ThunderClapCaster.mdl
 
Last edited:
Status
Not open for further replies.
Back
Top