• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

This causes a desync

Status
Not open for further replies.
Level 12
Joined
Dec 2, 2016
Messages
733
  • Become Mini
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Dead Human
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Ability being cast) Equal to Become Vampire Minion (Neutral)
        • Then - Actions
          • Unit Group - Pick every unit in (Units in (Entire map) owned by (Owner of (Triggering unit))) and do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Unit-type of (Picked unit)) Equal to Dead Human
                • Then - Actions
                  • Unit - Remove (Picked unit) from the game
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Unit-type of (Picked unit)) Not equal to Vampire Minion
                  • (Unit-type of (Picked unit)) Not equal to Dead Human
                  • (Unit-type of (Picked unit)) Not equal to Vampire Research Center Main
                • Then - Actions
                  • Unit - Change ownership of (Picked unit) to Neutral Hostile and Retain color
                • Else - Actions
          • For each (Integer A) from 1 to 12, do (Actions)
            • Loop - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ((Player((Integer A))) is in Humans) Equal to True
                • Then - Actions
                  • Player Group - Make (Player group((Player((Integer A))))) treat (Player group((Owner of (Last created unit)))) as an Enemy
                  • Player Group - Make (Player group((Owner of (Last created unit)))) treat (Player group((Player((Integer A))))) as an Enemy
                • Else - Actions
                  • Player Group - Make (Player group((Player((Integer A))))) treat (Player group((Owner of (Last created unit)))) as an Ally with shared vision
                  • Player Group - Make (Player group((Owner of (Last created unit)))) treat (Player group((Player((Integer A))))) as an Ally with shared vision
          • Player Group - Add (Owner of (Triggering unit)) to Vampires
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Ability being cast) Equal to Observe Humans (Neutral)
            • Then - Actions
              • Game - Display to (All players) the text: (There are + ((String(HumansCurrentlyPlaying)) + ( humans and + ((String(VampiresCurrentlyPlaying)) + vampires in game, gold mine income is now 2))))
            • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • tempBoolean Equal to False
        • Then - Actions
          • Set tempBoolean = True
          • Player Group - Remove (Owner of (Triggering unit)) from Humans
          • Set HumansCurrentlyPlaying = (HumansCurrentlyPlaying - 1)
          • Set VampiresCurrentlyPlaying = (VampiresCurrentlyPlaying + 1)
          • Unit - Create 1 Vampire Minion for (Owner of (Triggering unit)) at (Player 11 (Dark Green) start location) facing Default building facing degrees
          • Camera - Pan camera as necessary for (Owner of (Triggering unit)) to (Position of (Last created unit)) over 0.10 seconds
          • Special Effect - Create a special effect attached to the chest of (Last created unit) using Abilities\Spells\Orc\Purge\PurgeBuffTarget.mdl
          • Hero - Set (Last created unit) Hero-level to 3, Show level-up graphics
          • Game - Display to (All players) the text: (There are + ((String(HumansCurrentlyPlaying)) + ( humans and + ((String(VampiresCurrentlyPlaying)) + vampires in game, gold mine income is now 2))))
          • Wait 2.00 seconds
          • Special Effect - Destroy (Last created special effect)
          • Set tempBoolean = False
        • Else - Actions
Anyone know why?
Edit: Removed the effect, still happening. Is it the camera movement causing it?
 
Last edited:
Level 13
Joined
May 10, 2009
Messages
868
Camera - Pan camera as necessary for (Owner of (Triggering unit)) to (Position of (Last created unit)) over 0.10 seconds

This action causes the desync, because it creates a point (location) within a GetLocalPlayer block.

JASS:
function SmartCameraPanBJ takes player whichPlayer, location loc, real duration returns nothing
    local real dist
    if (GetLocalPlayer() == whichPlayer) then
        // Use only local code (no net traffic) within this block to avoid desyncs.

        set dist = DistanceBetweenPoints(loc, GetCameraTargetPositionLoc())
        if (dist >= bj_SMARTPAN_TRESHOLD_SNAP) then
            // If the user is too far away, snap the camera.
            call PanCameraToTimed(GetLocationX(loc), GetLocationY(loc), 0)
        elseif (dist >= bj_SMARTPAN_TRESHOLD_PAN) then
            // If the user is moderately close, pan the camera.
            call PanCameraToTimed(GetLocationX(loc), GetLocationY(loc), duration)
        else
            // User is close enough, so don't touch the camera.
        endif
    endif
endfunction
 
Level 12
Joined
Dec 2, 2016
Messages
733
Camera - Pan camera as necessary for (Owner of (Triggering unit)) to (Position of (Last created unit)) over 0.10 seconds

This action causes the desync, because it creates a point (location) within a GetLocalPlayer block.

JASS:
function SmartCameraPanBJ takes player whichPlayer, location loc, real duration returns nothing
    local real dist
    if (GetLocalPlayer() == whichPlayer) then
        // Use only local code (no net traffic) within this block to avoid desyncs.

        set dist = DistanceBetweenPoints(loc, GetCameraTargetPositionLoc())
        if (dist >= bj_SMARTPAN_TRESHOLD_SNAP) then
            // If the user is too far away, snap the camera.
            call PanCameraToTimed(GetLocationX(loc), GetLocationY(loc), 0)
        elseif (dist >= bj_SMARTPAN_TRESHOLD_PAN) then
            // If the user is moderately close, pan the camera.
            call PanCameraToTimed(GetLocationX(loc), GetLocationY(loc), duration)
        else
            // User is close enough, so don't touch the camera.
        endif
    endif
endfunction


How do I go about keeping the camera pan without having the desync?
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
How do I go about keeping the camera pan without having the desync?
Using this function instead...
JASS:
function SmartCameraPanBJFixed takes player whichPlayer, location loc, real duration returns nothing
    local real dist
    local location l = GetCameraTargetPositionLoc()
    if (GetLocalPlayer() == whichPlayer) then
        // Use only local code (no net traffic) within this block to avoid desyncs.

        set dist = DistanceBetweenPoints(loc, l)
        if (dist >= bj_SMARTPAN_TRESHOLD_SNAP) then
            // If the user is too far away, snap the camera.
            call PanCameraToTimed(GetLocationX(loc), GetLocationY(loc), 0)
        elseif (dist >= bj_SMARTPAN_TRESHOLD_PAN) then
            // If the user is moderately close, pan the camera.
            call PanCameraToTimed(GetLocationX(loc), GetLocationY(loc), duration)
        else
            // User is close enough, so don't touch the camera.
        endif
    endif
    call RemoveLocation(l)
    set l = null
endfunction
It should work (I hope).
 
Last edited:
Level 12
Joined
Dec 2, 2016
Messages
733
Sorry my Jass skills are not so good.

How do I assign 'whichPlayer' to the triggering unit?
Would you not create a variable and store the triggering unit in the variable?
Also 'duration' is this just an example and I assign the variables, or am I not understanding this?
 
Level 13
Joined
May 10, 2009
Messages
868
Copy DSG's fixed version, and put it in your map header. Be careful when pasting that function, you should change its name from SmartCameraPanBJ to something else, like SmartCameraPan. Then:

  • Camera - Pan camera as necessary for (Owner of (Triggering unit)) to (Position of (Last created unit)) over 0.10 seconds
->
call SmartCameraPan(GetOwningPlayer(GetTriggerUnit()), GetUnitLoc(GetTriggerUnit(), .1))

But let's avoid leaks.

  • Actions
    • Set unit = (Triggering unit)
    • Set point = (Position of unit)
    • Custom script: call SmartCameraPan(GetOwningPlayer(udg_unit), udg_point, .1))
    • Custom script: call RemoveLocation(udg_point)
 
Level 12
Joined
Dec 2, 2016
Messages
733
But what I don't understand is how to declare these units in the function
function SmartCameraPanBJ takes player whichPlayer, location loc, real duration returns nothing

How do you declare 'whichPlayer' 'loc' 'duration'

Right now it errors telling me they aren't declared.
 
Level 13
Joined
May 10, 2009
Messages
868
When you do:
JASS:
function SmartCameraPan takes player whichPlayer, location loc, real duration returns nothing
endfunction
You are basically creating/declaring a new function, in this case named as SmartCameraPan. Anything between takes and returns are the parameters - they are basically variables. That means every time you call that function, you must pass values to it, obeying the parameter order.

So, according to the function declared above, you need to tell which player, point, and decimal value will be transferred to it whenever calling it. Example:

  • Custom script: call SmartCameraPan(Player(0), GetUnitLoc(GetTriggerUnit()), 0.1)
Now, your function is capable to perform anything towards the player 1 (red), with triggering unit's position, with a specific real value.


Important notes:
  • Functions must have unique names. Otherwise, the editor will throw an error, because the game won't know which one should be executed.
  • Functions must be declared ABOVE anything that will reference it. So you can't do this:
    JASS:
    call ABC() // <-- Error.
    
    function ABC takes nothing returns nothing
    endfunction
    That's why the map header exists, so that all of your triggers will be able to reference new functions.


Untitled-2.png


  • Untitled Trigger 001
    • Events
      • Player - Player 1 (Red) skips a cinematic sequence
    • Conditions
    • Actions
      • Custom script: call SmartCameraPan(Player(0), Location(0.,0.), 0.5)
This should pan player red's camera to the coordinates x: 0., y: 0. (This is generally the center of the map)
 
Last edited:
Status
Not open for further replies.
Top