Bribe
vJass errors are legion
- Reaction score
- 67
JASS:
library GameStatus initializer Ini /*
GameStatus 2.0 by Bribe, special thanks to Troll-Brain
Check if a game is single-player online or is a single-player replay. Due
to Warcraft 3 limitations there is no known bugfree way to detect a multi-
player replay.
Even if you start a timer, pause the game, wait 0 seconds and unpause the
game, the timer will show 0.025 elapsed for both online games and for re-
plays.
However, the main thing you need to detect is when the game is single-
player, which means it's possible for the user to cheat. If you are doing
an RPG and the user wants to play it single-player, the player can do it
by selecting "LAN" as the method of play which doesn't even require an
Internet connection. This way he/she can progress through the story line
without needing other players and without you risking the player cheating.
function IsGameSinglePlayer
takes nothing
returns boolean
Returns true if the game is single player, where cheat codes can be
used. This can be called during map initialization reliably.
function OnGameStatusFound
takes string func
returns nothing
Executes the function when the game's status has been detected. The 2
functions "IsGameOnline" and "IsGameReplay" cannot be used reliably
from an initializer, you must wait for this function to run first.
function IsGameOnline
takes nothing
returns boolean
Returns true if the game is being played over a network or a replay
from a network game.
function IsGameReplay
takes nothing
returns boolean
Returns true if the game is a single-player replay. I have not been
able to find a bug-free way to detect a replay from a game which was
played online.
*/
globals
//If RGCFD returns true, cheat codes can be used (it's a non-network
//single-player game).
private integer iGame = IntegerTertiaryOp(ReloadGameCachesFromDisk(), 0, 1)
private integer n = 0
private string array funcs
endglobals
//=======================================================================
function IsGameOnline takes nothing returns boolean
return iGame == 2
endfunction
//=======================================================================
function IsGameReplay takes nothing returns boolean
return iGame == 1
endfunction
//=======================================================================
function IsGameSinglePlayer takes nothing returns boolean
return iGame == 0
endfunction
//=======================================================================
function OnGameStatusFound takes string func returns nothing
set funcs[n] = func
set n = n + 1
endfunction
//=======================================================================
/* private */ function GameStatus___aDs0F83254K43593Jfs takes nothing returns nothing
call TriggerSleepAction(0)
loop
set n = n - 1
exitwhen n < 0
call ExecuteFunc(funcs[n])
endloop
endfunction
//=======================================================================
private function Ini takes nothing returns nothing
call ExecuteFunc("GameStatus___aDs0F83254K43593Jfs")
if iGame > 0 then
//Replays ignore any thread-sleep type things which were not in
//the original game - thus this is perfect for detecting a single-
//player replay. TriggerSyncReady fires before TriggerSleepAction.
call TriggerSyncReady()
set iGame = 2
endif
endfunction
endlibrary