- Joined
- Jun 23, 2007
- Messages
- 4,066
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:
Example:
I've tested:
- Single Player
- Multiplayer - LAN (1 player)
- Multiplayer - LAN (2 players)
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
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