| 03-10-2009, 03:14 AM | #1 |
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 |
Not cricticism on code but why must the function be re-called? |
| 03-10-2009, 06:33 AM | #3 |
Execute on function with return is unsafe as i know. |
| 03-10-2009, 08:59 AM | #4 |
having 2 functions is much saner really ....my opinion |
| 03-10-2009, 09:11 AM | #5 | |
What's the benefit of that "singlefunc coding"? Quote:
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 |
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 |
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 |
it looks more ugly for you, not for me. |
| 03-10-2009, 04:38 PM | #9 | |||
Quote:
b) Proof? Quote:
Quote:
|
| 03-10-2009, 04:53 PM | #10 | |
Quote:
There's not even a need for a loop. InitBlizzardGlobals already does that when the map is loaded. 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 |
Fixed ofc, no more enum and rebj calls. |
| 03-11-2009, 02:30 AM | #12 |
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 |
This is generic any map using cache may fail if 256 caches already saved inside. |
| 03-11-2009, 03:24 AM | #14 |
Aren't there functions that would work even with that limit reached...? I can't remember... |
| 03-11-2009, 04:03 AM | #15 |
Well...i will provide alternative way to detect online state in 1-2 days. |
