• Check out the results of the Techtree Contest #19!
  • Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!

[JASS] Why is this desyncing?

Status
Not open for further replies.
Level 11
Joined
Dec 31, 2007
Messages
780
This is a replay detect system made by pandamine. the problem with it is that when my map is played by more than 6 people it tends to desync :/.

Can anybody see what's the problem here? or if is there another way to do this? (that doesn't involve using GetLocalPlayer())



JASS:
//**************************************************************************************
//*                                                                                    *
//*                         REPLAY DETECT ENGINE V1.30                                 *
//*                     CONFIGURATION SETTINGS START HERE                              *
//*                                                                                    *
//**************************************************************************************
library ReplayDetectEngine
globals
boolean InGame = true
boolean array AMHS_FogDisable
boolean array AMHS_InvisDisable
unit array AMHS_FogDummy
unit array AMHS_InvisDummy
endglobals

//-> IsInGame created by PandaMine with help from Captain Griffen
//This function is what makes it possible for the system not to break replays,
//simply put if your actually playing the game, this function will return false.
//It will return true if the game is being viewed in a replay

private function IsInGame takes nothing returns boolean
local integer counter = 0
local real camerax
local real cameray
local real x
local real y
local boolean output
loop
    exitwhen counter > 11
    if GetLocalPlayer() == Player(counter) then
        set camerax = GetCameraTargetPositionX()
        set cameray = GetCameraTargetPositionY()
    endif
    set counter = counter + 1
endloop
set counter = 0
call PauseGame(true)
call TriggerSleepAction(0)
loop
    exitwhen counter > 11
    if GetLocalPlayer() == Player(counter) then
        call SetCameraPosition(camerax + 1,cameray + 1)
    endif
    set counter = counter + 1
endloop
call TriggerSleepAction(0)
call PauseGame(false)
set counter = 0
loop
    exitwhen counter > 11
    if GetLocalPlayer() == Player(counter) then
        set x = GetCameraTargetPositionX()
        if x == camerax + 1 then
            set output = true
        else
            set output = false
        endif
        call SetCameraPosition(camerax,cameray)
    endif
    set counter = counter + 1
endloop
return output
endfunction 

function AMHS_ReplayEngine takes nothing returns nothing
call EnableUserControl(false)
call PauseGame(false)
call TriggerSleepAction(.0)
call PauseGame(false)
set InGame = IsInGame()
call EnableUserControl(true)
endfunction

//===========================================================================
function InitTrig_Replay_Detect_Engine takes nothing returns nothing
    set gg_trg_Replay_Detect_Engine = CreateTrigger(  )
endfunction
endlibrary


PS: The creator of this is no longer active, so i can't ask him
 
JASS:
call SetCameraPosition(camerax + 1,cameray + 1)
I think the problem lies there. You localize an action. In order to avoid the desync, you will need to set a real value within the GetLocalPlayer() branch and make the call out of it.
e.g.
JASS:
local real x
local real y
if GetLocalPlayer() == Player(0) then
set x = 90
set y = 119
endif
call SetCameraPosition(x,y)
 
JASS:
call SetCameraPosition(camerax + 1,cameray + 1)
I think the problem lies there. You localize an action. In order to avoid the desync, you will need to set a real value within the GetLocalPlayer() branch and make the call out of it.
e.g.
JASS:
local real x
local real y
if GetLocalPlayer() == Player(0) then
set x = 90
set y = 119
endif
call SetCameraPosition(x,y)

No. Totally wrong. Have you ever looked at the SetCameraPositionForPlayer function?
JASS:
function SetCameraPositionForPlayer takes player whichPlayer, real x, real y returns nothing
    if (GetLocalPlayer() == whichPlayer) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call SetCameraPosition(x, y)
    endif
endfunction

I think the problem lies beyond something else.
 
I would start by removing PauseGame and TriggerSleepAction calls. The camera cannot be changed while the game is paused, and in combination with local code that may cause players to desync. I don't know why it is necessary that you pause the game anyways.

Also, if you're using a library, why not use the initializer keyword to define your initialization function, rather than using the crappy InitTrig_Name protocol. You can also make your functions public, rather than having to use a prefix like you are.

JASS:
    if GetLocalPlayer() == Player(counter) then
        set x = GetCameraTargetPositionX()
        if x == camerax + 1 then
            set output = true
        else
            set output = false
        endif
        call SetCameraPosition(camerax,cameray)
    endif

This could be your problem. This seems like quite a bit of local code, it may be causing the desyncs.

I don't really see the necessity of local code here, though. Each player will return different values from GetCameraTargetPositionX so that automatically localizes whatever is happening. This should do the same thing:

JASS:
private function IsInGame takes nothing returns boolean
	local integer counter = 0
	local real camerax
	local real cameray
	local real x
	local real y
	local boolean output
 
		set camerax = GetCameraTargetPositionX()
		set cameray = GetCameraTargetPositionY()

		call PauseGame(true)
		call TriggerSleepAction(0)

		call SetCameraPosition(camerax+1, cameray+1)

		call TriggerSleepAction(0)
		call PauseGame(false)

		set x = GetCameraTargetPositionX()
		set output = false
		if x == (camerax+1) then
			set output = true
		endif
		call SetCameraPosition(camerax, cameray)

	return output
endfunction
 
i think that the game is paused because if you pause it and the game is running the camera wont move, but if the game is a replay, the game won't be paused and the camera will move, thus, telling you that it is a replay and not a normal game. (dunno about this thou)

PS: Im a jass absolutely noob, so if you can help me to fix this and implement it into my map, it will be of great assistance
 
I haven't done this library, pandamine did it (he is no longer active so i can't bother him with this :P) plus im a jass illiterate (i understand some, but i can't manage to write it).

I run this library once per game and then i use InGame to do some stuff (after running this trigger once, i create some units only if the game is a "game" but not a replay) from GUI.

If you take a look at Berb's post (a few before yours) he wrote what could be a solution, but as im a GUIer i dont know how to implement it (i tried, but it requires an init trigger and i don't know how to make one :/

Oh wait, you are saying that im creating those units for some local players and for some others i dont and that is what causes the desync?. If thats the case, how can I make it non local?

oh my god! it is so clear now! xD

Thanks a lot

PS: Can you help me fix it? xD

EDIT: Of course, now i get what the problem is. Just imagine this, you check for local players the camera thingy detecting if it is a replay or not. But for some reason, one of those players gives a false negative (it is a game but the library takes it as a replay for that player) then i locally create units for every player except that one... and thats it... desync!. You really helped me on this one! thanks =D
 
Ok... another bump. Unfortunately i couldn't make it work in either GUI or JASS. I would really like to have some assistance to implement the last jass script posted. I don't know if an "Init trigger" is hard to make or not... but seems like that's everything I need

Thanks ^^
 
Status
Not open for further replies.
Back
Top