13 years
edited 8 years
Description
The purpose of this library is to offer a single function which checks if the game is played in single player mode or multiplayer.
Important: This function must be used only to define if the player is in single player or in Bnet or lan game. This function will fail in replays (it will show that you're in a LAN game by default).
Credits to Nestharus for the awesome solution to this problem
Requirements
- None
Actual Code
Example
The purpose of this library is to offer a single function which checks if the game is played in single player mode or multiplayer.
Important: This function must be used only to define if the player is in single player or in Bnet or lan game. This function will fail in replays (it will show that you're in a LAN game by default).
Credits to Nestharus for the awesome solution to this problem

Requirements
- None
Actual Code
/******************************************************************
* SINGLE PLAYER DETECTOR V3.0 *
* By moyack *
* 2012 *
* =================================== *
* Exclusive resource from wc3jass.com *
* =================================== *
******************************************************************/
library SinglePlayerDetector
/*The purpose of this library is to offer a single function which checks if
the game is played in single player mode or multiplayer. It offers only
one function:
isSinglePlayer: takes nothing and returns a boolean.
If true, the game is being run in single player mode, else, in multiplayer
CREDITS TO NESTHARUS for the improved and nice solution to this problem.
It passed from a long code to a simple line function.
Credits to Magtheridon96 for the library optimization
*/
globals
private boolean sp = ReloadGameCachesFromDisk()
endglobals
function IsSinglePlayer takes nothing returns boolean
return sp
endfunction
endlibraryExample
scope test initializer init
private function init takes nothing returns nothing
if IsSinglePlayer() then
call DisplayTimedTextFromPlayer(Player(0), 0,0,10, "You're playing alone, forever, happy. You can cheat")
else
call DisplayTimedTextFromPlayer(Player(0), 0,0,10, "You're playing multiplayer. You can't cheat")
endif
endfunction
endscope

Your approach is good too.