HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

IsGameOnline

03-10-2009, 03:14 AM#1
DioD
Collapse JASS:
library isGameOnline initializer INIT

globals

    boolean IS_GAME_ONLINE = false
    //TRUE  = Game is online, no cheats possible.
    //FALSE = Game is offline, cheats possible.
    //If your map have some sort of secrets, you can cover them in offline games
endglobals

private function INIT takes nothing returns nothing
    if GetExpiredTimer() != null then
        set IS_GAME_ONLINE = not IsNoDefeatCheat()
        call Cheat("StrengthAndHonor")
        call DestroyTimer(GetExpiredTimer())
        return
    endif

    call Cheat("StrengthAndHonor")
    call TimerStart(CreateTimer(),1.0,false,function INIT)
endfunction

endlibrary

This small system allow you to detect "online game state".

-cons
It will display "cheat enabled\disabled" message.
Takes a second to complete.
03-10-2009, 05:08 AM#2
fX_
Not cricticism on code but why must the function be re-called?
03-10-2009, 06:33 AM#3
DioD
Execute on function with return is unsafe as i know.
03-10-2009, 08:59 AM#4
akolyt0r
having 2 functions is much saner really ....my opinion
03-10-2009, 09:11 AM#5
ToukoAozaki
What's the benefit of that "singlefunc coding"?

Quote:
having 2 functions is much saner really ....my opinion

Well, actually that "singlefunc coding" is causing unnecessary code bloat. ForForce part can be just put inside INIT, and then simply call ForForce with MAIN as a callback. By changing that, unnecessary overhead -which doesn't affect the result at all- will be gone.

bj_isSinglePlayer does exactly the same of IS_GAMETYPE_SINGLE, so you can just check for not SaveGameCache(InitGameCache("1337")). Then you don't need any enum thing.

Edit: make sure you read the value after InitBlizzardGlobals is called.
03-10-2009, 10:01 AM#6
DioD
singlefunc coding much more faster then traditional coding (not perfomance, human time) since you have entire code before you.
03-10-2009, 10:41 AM#7
akolyt0r
yeah that surely makes a huge difference for this extremley long code snippet ...
beside that ...that function looks more ugly
03-10-2009, 11:46 AM#8
DioD
it looks more ugly for you, not for me.
03-10-2009, 04:38 PM#9
Vexorian
Quote:
Execute on function with return is unsafe as i know.
a) Unsafe == ?
b) Proof?

Quote:
What's the benefit of that "singlefunc coding"?
None.

Quote:
singlefunc coding much more faster then traditional coding (not perfomance, human time) since you have entire code before you.
You could just... use a loop for the players, there are always 16 players, ya know. it would save you of that horrid hack, look cleaner and be faster to code than this. There's no point in using enums/forforce with players....
03-10-2009, 04:53 PM#10
ToukoAozaki
Quote:
Originally Posted by Vexorian
You could just... use a loop for the players, there are always 16 players, ya know. it would save you of that horrid hack, look cleaner and be faster to code than this. There's no point in using enums/forforce with players....

There's not even a need for a loop. InitBlizzardGlobals already does that when the map is loaded.

Collapse Excerpt of InitBlizzardGlobals:
    // Init singleplayer check
    set bj_isSinglePlayer = false
    set userControlledPlayers = 0
    set index = 0
    loop
        exitwhen index >= bj_MAX_PLAYERS
        if (GetPlayerController(Player(index)) == MAP_CONTROL_USER and GetPlayerSlotState(Player(index)) == PLAYER_SLOT_STATE_PLAYING) then
            set userControlledPlayers = userControlledPlayers + 1
        endif
        set index = index + 1
    endloop
    set bj_isSinglePlayer = (userControlledPlayers == 1)
03-10-2009, 10:50 PM#11
DioD
Fixed ofc, no more enum and rebj calls.
03-11-2009, 02:30 AM#12
Captain Griffen
init cache can fail, no, when you have 256 caches? Which, I think I do, on my profile? Not sure...don't take this too seriously.
03-11-2009, 02:42 AM#13
DioD
This is generic any map using cache may fail if 256 caches already saved inside.
03-11-2009, 03:24 AM#14
Captain Griffen
Aren't there functions that would work even with that limit reached...? I can't remember...
03-11-2009, 04:03 AM#15
DioD
Well...i will provide alternative way to detect online state in 1-2 days.