• 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.

[Snippet] [Needs revision] Is Game Replay

Level 3
Joined
Sep 4, 2007
Messages
49
This function I discovered myself (and with the help of Captain Griffein from wc3campaigns). Simply put, if your actually playing a game, it will return true HOWEVER if your viewing the game as a replay it will return false. The function has been tested in MultiPlayer and it now causes no desyncs. There is only one downside, and that is the function uses up one pause (if anyone knows how to prevent this please tell)

How does it work?
Simply put a replay is just a file that contains the inputs from the various players when playing a game. However when Wc3 views a replay, there are differences then if you were physically playing the game. One of the differences is pausing. If you are actually playing and you pause a game, it is paused. However during a replay, if you pause a game the replay simply finishes at the point you paused the game, if the game is resumed some time later then the replay completely skips the pause phase. There are only a few things that work in real time during pauses when your playing the game (anything else you do during the pause just gets 'suspended' until the game is resumed). The 2 things that work in real time are camera angles and trigger sleep action.

The function works by moving the camera during the pause. If the camera is moved during the pause, then you are playing the actual game. If the camera isn't moved then it is the replay (since the pause phase is totally skipped)
Notes:

- You can hide the pause message that happens in multiplayer (i.e. ******** has paused the game) by calling the function in Cinematic Mode. The cinematic mode has to last around 10 seconds to fully hide the message

- It is HIGHLY recommended that you save the returning value of the function into a boolean variable i.e.
JASS:
 set someboolean = IsInGame()
So you only call the function once (since it takes up a pause)
HERE IS THE FUNCTION
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
 
Last edited:
Level 3
Joined
Sep 4, 2007
Messages
49
I actually did the setting of ints and reals to 0 for concerns about desyncs, but it doesnt really matter

Yes it can be annoying to use in the game, but as far as I know its the only fullproof multiplayer way of determining if the game is being played or viewed as a replay. Like I mentioned if you call the function in Cinematic mode the message is hidden
 
Level 3
Joined
Sep 4, 2007
Messages
49
Id just like to mention (forgot to say this before and had problems with it) that the returning variable is NOT synchronised. This means that you either need to use sync natives or the various sync functions out there to synchronise the returning boolean otherwise you would get various problems
 
Level 3
Joined
Sep 4, 2007
Messages
49
There was a problem with this version of the function, it seemed that synchronising the boolean also synchronised it with replays, which meant that it always returned true. To prevent this the function has completely been rewritten, the returning value now does not need to be synchronised and it works fully functionally with replays and in multiplayer

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
 
Level 7
Joined
Mar 6, 2006
Messages
282
I'd just like to say that in multiplayer, you cannot see what other people are saying while a Dialog is being shown. Even after it has been hidden, the messages are not there.

I use this in my map and I thank you; it is wonderful. What I've added though, is I display a Dialog while the game pauses and then hide it afterwards so no one saw the game was paused.

GJ
 
Level 9
Joined
Nov 28, 2008
Messages
704
I may be wrong, but a friend used this and if you alt tab while the game pauses and checks for replay, it apparently doesnt detect properly (it thinks you're in a replay when you arent). I dont suppose its possible to fix this by chance?
 
Level 7
Joined
Mar 6, 2006
Messages
282
If this is done at the beginning, you don't need to worry about that and also, it almost less than a second to happen so how could you Alt + Tab in that time? I'll try it though.

I do have one question though. Can this function be run while your camera is being controlled by another trigger? Like what if your camera was locked to a unit?
 
Level 9
Joined
Nov 28, 2008
Messages
704
I'm pretty much 100% sure if you do any camera trigger after you set your camera to a unit, it unlocks it.

And you can just keep warcraft 3 minimzied during loading, and the bug happens. o_O
 
Level 9
Joined
Nov 28, 2008
Messages
704
There should just be a "Warning: do not minimize while the game is loading" thing.

Well yes, but what if you want your replays to add extra functionality, like recording events and displaying them as they happen for a larger experience?

If it was like a murder mystery game and your replay extra stuff displayed messages about whot he "murderer" was and such, people could cheat and minimize at the start.

There should be some sort of way to prevent that, but blargh at Warcraft 3 I guess.
 
This entire script could be shortened to this:

JASS:
function IsGameReplay takes nothing returns nothing
    local real x = GetCameraTargetPositionX()
    local real y = GetCameraTargetPositionY()
    call PauseGame(true)
    call TriggerSleepAction(0)
    call SetCameraPosition(x + 1, y)
    call TriggerSleepAction(0)
    call PauseGame(false)
    if GetCameraTargetPositionX() == x then
        return true
    endif
    call SetCameraPosition(x, y)
    return false
endfunction

And it also was not mentioned in the first post that having wc3 minimized causes it to bug. Think about players who minimize wc3 while waiting for the game to start. It can happen a lot and cause a lot of bugs. I don't particularly feel this is reliable at all.

I am not even sure if this even works with 1.26. I am just bumping this thread for discussion.
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
You could improve this script safety by synchronising all players data.
Then, all players have to minimize wc3 in order to break the detection.
Ofc it's still easy for one player.

For your resource too bad it doesn't work as intented in an "online" game, i think you have lost lot of time by finding what that was already found (no offense).
I'm pretty sure i had linked you Diod's resource on wc3c.net before, and afair, all was stated in this thread.
 
Top