Warcraft 3 documentation
vJASS & Zinc Documentation
For the latest documentation about how it works vJASS and Zinc language layers for Warcraft III, please follow these links:
Jasshelper documentation - Zinc documentation - WC3 Optimizer documentation

[Snippet] Single Player Detector No New Posts Codes & Snippets

Started by
moyack

0 Members and 1 Guest are viewing this topic.

[Snippet] Single Player Detector
on: November 03, 2012, 03:15:29 PM
Category: Execution
Language: vJASS

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 :D

Requirements

 - None

Actual Code

Code: jass
  1. /******************************************************************
  2. *                   SINGLE PLAYER DETECTOR V3.0                   *
  3. *                           By moyack                             *
  4. *                              2012                               *
  5. *              ===================================                *
  6. *              Exclusive resource from wc3jass.com                *
  7. *              ===================================                *
  8. ******************************************************************/
  9. library SinglePlayerDetector
  10. /*The purpose of this library is to offer a single function which checks if
  11.   the game is played in single player mode or multiplayer. It offers only
  12.   one function:
  13.  
  14.   isSinglePlayer: takes nothing and returns a boolean.
  15.  
  16.   If true, the game is being run in single player mode, else, in multiplayer
  17.   CREDITS TO NESTHARUS for the improved and nice solution to this problem.
  18.   It passed from a long code to a simple line function.
  19.   Credits to Magtheridon96 for the library optimization
  20. */
  21.  
  22. globals
  23.     private boolean sp = ReloadGameCachesFromDisk()
  24. endglobals
  25.  
  26. function IsSinglePlayer takes nothing returns boolean
  27.     return sp
  28. endfunction
  29.  
  30. endlibrary

Example

Code: jass
  1. scope test initializer init
  2.  
  3. private function init takes nothing returns nothing
  4.     if IsSinglePlayer() then
  5.         call DisplayTimedTextFromPlayer(Player(0), 0,0,10, "You're playing alone, forever, happy. You can cheat")
  6.     else
  7.         call DisplayTimedTextFromPlayer(Player(0), 0,0,10, "You're playing multiplayer. You can't cheat")
  8.     endif
  9. endfunction
  10.  
  11. endscope
« Last Edit: December 19, 2017, 07:49:05 PM by moyack »



Re: Single Player Detector
Reply #1 on: November 05, 2012, 12:15:09 AM

Uhhm, can you explain the:

" This function cannot be run at map initialization, otherwise it won't offer a right answer. It relies in "greedisgood" cheat to do the verification. "

What does it mean? Does it mean you have to put cheat first before the library run?

Chronicles of Darkness
by: SonofJay

A BlizzMod Hosted Project

They can hate, let them hate, make them hate.


Re: Single Player Detector
Reply #2 on: November 05, 2012, 06:02:39 AM

uhm...

Code: jass
  1. function IsSinglePlayer takes nothing returns boolean
  2. endfunction
  3.  

the above is the standard way to do this check...



Re: Single Player Detector
Reply #3 on: November 05, 2012, 08:34:59 AM

uhm...

Code: jass
  1. function IsSinglePlayer takes nothing returns boolean
  2. endfunction
  3.  

the above is the standard way to do this check...

I... just... didn't... know... about .... this... AWESOME FEATURE!!!!! I burned a lot of brain cells thinking in one solution for this problem and you came with this :)

Awesome!!! I'll update this library, is offensively simple but it¿s worth bolding the feature of this function.


Uhhm, can you explain the:

" This function cannot be run at map initialization, otherwise it won't offer a right answer. It relies in "greedisgood" cheat to do the verification. "

What does it mean? Does it mean you have to put cheat first before the library run?
In version  yes, but now with the outstanding solution from Nestharus, it's not necessary and works at map init!!!


Re: Single Player Detector
Reply #4 on: November 05, 2012, 02:51:18 PM

Code: jass
  1. library IsSinglePlayer
  2.  
  3.     globals
  4.         private boolean sp = ReloadGameCachesFromDisk()
  5.     endglobals
  6.  
  7.     function IsSinglePlayer takes nothing returns boolean
  8.         return sp
  9.     endfunction
  10.  
  11. endlibrary

Also, it should be IsSinglePlayer, because FunctionNamesAreWrittenLikeThis ;P



Re: Single Player Detector
Reply #5 on: November 05, 2012, 04:56:51 PM

Im quite sure that replays will screw this.

vJass is already a jass preprocessor, no need to (ab)use vJass features in order to make some inferior vJass preprocessor coded "by hand".


Re: Single Player Detector
Reply #6 on: November 06, 2012, 09:07:12 AM

Code: jass
  1. library IsSinglePlayer
  2.  
  3.     globals
  4.         private boolean sp = ReloadGameCachesFromDisk()
  5.     endglobals
  6.  
  7.     function IsSinglePlayer takes nothing returns boolean
  8.         return sp
  9.     endfunction
  10.  
  11. endlibrary

Also, it should be IsSinglePlayer, because FunctionNamesAreWrittenLikeThis ;P
Hmmmm.... And I just haven't noticed that :P Your approach is good too.

Im quite sure that replays will screw this.
I have to test it :)



Re: Single Player Detector
Reply #7 on: November 06, 2012, 09:51:45 PM

http://www.wc3c.net/showthread.php?t=104921&page=3

That has a bit of a discussion about it. That one is about it being online though. So it really depends on what definition of single player you're after.

So you "might" have to revert to the cheat method, it depends on what you're trying to do. You should probably test it anyway just in case. :)



Re: Single Player Detector
Reply #8 on: November 12, 2012, 12:11:49 PM

http://www.wc3c.net/showthread.php?t=104921&page=3

That has a bit of a discussion about it. That one is about it being online though. So it really depends on what definition of single player you're after.

So you "might" have to revert to the cheat method, it depends on what you're trying to do. You should probably test it anyway just in case. :)

The purpose of this script is to detect if you're playing in mode "single player" AKA you can cheat or if you're playing on LAN or B.net.


Re: Single Player Detector
Reply #9 on: November 13, 2012, 12:00:57 PM

Code: jass
  1. library Detector initializer init
  2.  
  3.     globals
  4.         public constant real DELAY = 0.3
  5.         private boolean Is_multi = false
  6.         private timer Tim
  7.     endglobals
  8.    
  9.     // these 2 functions can only be used only when the timer has expired or after the TSA in the DoInit2 function
  10.    
  11.     function IsMulti takes nothing returns boolean
  12.         return Is_multi
  13.     endfunction
  14.    
  15.     function IsSolo takes nothing returns boolean
  16.         return not Is_multi
  17.     endfunction
  18.    
  19.     private function EndOfTimer takes nothing returns nothing
  20.         set Is_multi = true
  21.     endfunction
  22.    
  23.     private function DoInit2 takes nothing returns nothing
  24.         local diag = DialogCreate()
  25.         call DialogDisplay(GetLocalPlayer(),diag,true)
  26.         call TriggerSleepAction(DELAY)
  27.         call PauseTimer(Tim) // just in case
  28.         call DestroyTimer(Tim)
  29.         set Tim = null
  30.         call DialogDestroy(diag)
  31.         set diag = null
  32.     endfunction
  33.  
  34.     private function DoInit takes nothing returns nothing
  35.         call ExecuteFunc("DoInit2")
  36.         call TimerStart(Tim,DELAY,false,function EndOfTimer)
  37.     endfunction
  38.    
  39.     private function init takes nothing returns nothing
  40.         set Tim = CreateTimer()
  41.         call TimerStart(Tim,0,false,function DoInit)
  42.     endfunction
  43.    
  44. endlibrary

This is just a proof of concept i don't know if it works, and yes it can be improved, i will eventually do it if it works and the ReloadGame... bug is confirmed on replays.

EDIT :

Or if Diod's way work 100 % i suppose it doesn't worth it, especially because it would be even more noticeable than his way.
Now maybe the select unit trick mentionned also works and then it would be much better because much faster, in fact could be used just after a Timer(0) and not really noticeable ...

Note, that i don't know what happens if there is a noticeable delay or not.

EDIT 2 :

And just to be clear, no i don't care to test it, and yes you're free to use any part, all, or nothing of this code without any credit required (ofc it's sthe same about the wc3c's post.

And btw Nestharus shouldn't be credited for the Reload... way, he has not dicovered it, even if yeah i suppose we are just re-discovering the same things again and again.
But here i'm just sure that someone told him.
« Last Edit: November 14, 2012, 01:57:47 PM by Troll-Brain »

vJass is already a jass preprocessor, no need to (ab)use vJass features in order to make some inferior vJass preprocessor coded "by hand".


Re: [Snippet] Single Player Detector
Reply #10 on: December 15, 2012, 11:47:27 PM

never said it came from me

TriggerHappy was the first person I saw to post it, but it's really obvious given that gamecache doesn't work in single player ;p.



[Snippet] Single Player Detector
Reply #11 on: January 02, 2013, 11:36:27 PM

Updated, and as Trollbrain said, it will fail in replays. I've added a warning in the first post.


[Snippet] Single Player Detector
Reply #12 on: March 13, 2013, 12:48:49 PM

A warning. Good enough for me :p

Approved.



 

Started by PitzerMike

Replies: 0
Views: 1588
Codes & Snippets

Started by Purgeandfire

Replies: 0
Views: 1672
Codes & Snippets

Started by Bribe

Replies: 0
Views: 1916
Codes & Snippets

Started by moyack

Replies: 0
Views: 9828
Codes & Snippets

Started by Magtheridon96

Replies: 1
Views: 8623
Codes & Snippets
Vivir aprendiendo.co - A place for learning stuff, in Spanish   Chaos Realm - The world of Game modders and wc3 addicts   Diplo, a gaming community   Power of Corruption, an altered melee featuring Naga and Demon. Play it now!!!   WC3JASS.com - The JASS Vault + vJASS and Zinc   Jetcraft - A Starcraft II mod   WormTastic Clan (wTc)   Warcraft RESOURCES Reforged: Modelos, mapas, proyectos y mas...