• 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 faction for Warcraft 3 and enter Hive's 19th Techtree Contest: Co-Op Commanders! Click here to enter!
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 21st Texturing Contest: Upgrade is now concluded, time to vote for your favourite set of icons! Click here to vote!

Replay Detection Script

Status
Not open for further replies.
This script seems to be able to accurately detect replays. I haven't tested in Battle.net yet, or maybe I a forgetting something, so I'm posting here first.

I've tested:
  • Single Player
  • Multiplayer - LAN (1 player)
  • Multiplayer - LAN (2 players)
I was able to run code specifically in replays in each of those scenarios.

JASS:
library GameStatus requires PlayerUtils

//configuration
globals
    // Dummy unit is only created once, and removed directly after.
    private constant integer DUMMY_UNIT_ID = 'hfoo'
endglobals
//endconfig

globals
    constant integer GAME_STATUS_OFFLINE = 0
    constant integer GAME_STATUS_ONLINE  = 1
    constant integer GAME_STATUS_REPLAY  = 2
   
    private integer status = 0
endglobals

function GetGameStatus takes nothing returns integer
    return status
endfunction

private module GameStatusInit

    private static method onInit takes nothing returns nothing
        local player firstPlayer = User.fromPlaying(0).handle
        local unit u = CreateUnit(firstPlayer, DUMMY_UNIT_ID, 0, 0, 0)
        local boolean selected
       
        call SelectUnit(u, true)
        set selected = IsUnitSelected(u, firstPlayer)
        call RemoveUnit(u)
        set u = null
       
        if (selected) then
       
            if (User.AmountPlaying > 1) then
                set status = GAME_STATUS_REPLAY
                return
            endif
           
            if (ReloadGameCachesFromDisk()) then
                set status = GAME_STATUS_OFFLINE
            else
                set status = GAME_STATUS_REPLAY
            endif
           
        else
            set status = GAME_STATUS_ONLINE
        endif
       
    endmethod
   
endmodule

private struct GameStatus
    implement GameStatusInit
endstruct

endlibrary
Example:

JASS:
scope GameStatusExample initializer Init

    private function OnMapStart takes nothing returns nothing
        local integer status = GetGameStatus()
       
        if (status == GAME_STATUS_OFFLINE) then
            call BJDebugMsg("This game is offline.")
        elseif(status == GAME_STATUS_ONLINE) then
            call BJDebugMsg("This game is online.")
        elseif(status == GAME_STATUS_REPLAY) then
            call BJDebugMsg("You are viewing a replay")
        endif
    endfunction
   
    private function Init takes nothing returns nothing
        call TimerStart(CreateTimer(), 0.00, false, function OnMapStart)
    endfunction
   
endscope
 
Status
Not open for further replies.
Top