• 🏆 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!

[JASS] Replay Detect function has been re-written

Status
Not open for further replies.
Level 3
Joined
Sep 4, 2007
Messages
49
To anyone that was using the older version of the replay detect function, there were issues with it. When it was first posted on this site, the returning boolean for the function was unsynchronised which means when used will almost inevitably cause a desync. As a way to prevent this I synchronised the variable using gamecache and sync natives. Although this solved the multiplayer problem it seemed it also synchronised the boolean with replays which means it always returned true (even in replays). The function has been completely recoded, a lot of silly uneeded stuff was removed (the 2 sync functions have been removed and the globals) and I have just tested it and it works prefectly as intended

You can find instructions and the function at here http://www.hiveworkshop.com/forums/showthread.php?t=40777

For those who have no idea what im talking about :eekani: I discovered a function which returns true if your actually playing in the game, and returns false if the game is being viewed as a replay. The only downsides to the function is it uses a pause which makes a noticable message (for this reason the returning value of the function should always be stored as a global boolean for future use). Here is the function for those lazy asses that dont wont to follow the link

JASS:
//<- InGame function created by PandaMine with help from Captain Griffein
function IsInGame takes nothing returns boolean
local integer counter = 1
local real camerax
local real cameray
local real x
local real y
local boolean output
loop
    exitwhen counter > 12
    if GetLocalPlayer() == Player(counter-1) then
        set camerax = GetCameraTargetPositionX()
        set cameray = GetCameraTargetPositionY()
    endif
    set counter = counter + 1
endloop
set counter = 1
call PauseGame(true)
call TriggerSleepAction(0)
loop
    exitwhen counter > 12
    if GetLocalPlayer() == Player(counter-1) then
        call SetCameraPosition(camerax + 1,cameray + 1)
    endif
    set counter = counter + 1
endloop
call TriggerSleepAction(0)
call PauseGame(false)
set counter = 1
loop
    exitwhen counter > 12
    if GetLocalPlayer() == Player(counter-1) 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

With the new change to the function, it no longer needs to be synchronised however you should still initialize it like this because it has been reported that selecting units + triggersleepaction can cause desyncs

JASS:
function Initiate takes nothing returns nothing
call EnableUserControl(false)
call TriggerSleepAction(.0)
set udg_InGame = IsInGame()
call EnableUserControl(true)
endfunction
 
Level 3
Joined
Sep 4, 2007
Messages
49
I did bump the thread, its just that many people don't notice a thread that has already been bumped when It has been bumped again
 
Status
Not open for further replies.
Top