Warcraft III: MapsModelsSkinsIconsSpellsToolsTutorials
WC3 JASS: Code SnippetsJASS and vJASS Spells and SystemsJass Tutorials
Chat @Discord

Author Topic: [Snippet] Single Player Detector  (Read 20885 times)

  • Site Owner
  • Administrator
  • Starter - level 4
  • *
  • Posts: 979
  • WC3 Models: 5
  • WC3 Tutorials: 11
  • WC3 Tools: 10
  • WC3 Maps: 11
  • WC3 Skins: 6
  • WC3 Icons: 2
  • WC3 Spells: 3
  • Reputation: 1153
  • Site Admin - I love fix things
    • View Profile
    • Blizzard Modding Information Center
[Snippet] Single Player Detector
« on: November 03, 2012, 03:15:29 PM »
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  [Select]
  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  [Select]
  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: January 02, 2013, 11:35:17 PM by moyack »

We can give you full hosting for your projects, a complete page!!

A custom altered melee map where you can play Naga and Demons. Check it out!!
Use Dropbox...

  • Your Awesome Site Director
  • Recognized User
  • Starter - level 1
  • *
  • Posts: 382
  • WC3 Models: 0
  • WC3 Tutorials: 0
  • WC3 Tools: 0
  • WC3 Maps: 0
  • WC3 Skins: 0
  • WC3 Icons: 0
  • WC3 Spells: 0
  • Reputation: 677
    • View Profile
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.

  • Newbie - level 1
  • *
  • Posts: 8
  • WC3 Models: 0
  • WC3 Tutorials: 0
  • WC3 Tools: 0
  • WC3 Maps: 0
  • WC3 Skins: 0
  • WC3 Icons: 0
  • WC3 Spells: 0
  • Reputation: 20
  • User
    • View Profile
Re: Single Player Detector
« Reply #2 on: November 05, 2012, 06:02:39 AM »
uhm...

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

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

  • Site Owner
  • Administrator
  • Starter - level 4
  • *
  • Posts: 979
  • WC3 Models: 5
  • WC3 Tutorials: 11
  • WC3 Tools: 10
  • WC3 Maps: 11
  • WC3 Skins: 6
  • WC3 Icons: 2
  • WC3 Spells: 3
  • Reputation: 1153
  • Site Admin - I love fix things
    • View Profile
    • Blizzard Modding Information Center
Re: Single Player Detector
« Reply #3 on: November 05, 2012, 08:34:59 AM »
uhm...

Code: jass  [Select]
  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!!!

We can give you full hosting for your projects, a complete page!!

A custom altered melee map where you can play Naga and Demons. Check it out!!
Use Dropbox...

  • Awesome Global Code Moderator
  • Recognized User
  • Rookie - level 2
  • *
  • Posts: 83
  • WC3 Models: 0
  • WC3 Tutorials: 0
  • WC3 Tools: 0
  • WC3 Maps: 0
  • WC3 Skins: 0
  • WC3 Icons: 0
  • WC3 Spells: 0
  • Reputation: 516
  • vJass Incarnate
    • View Profile
Re: Single Player Detector
« Reply #4 on: November 05, 2012, 02:51:18 PM »
Code: jass  [Select]
  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

  • Rookie - level 1
  • *
  • Posts: 48
  • WC3 Models: 0
  • WC3 Tutorials: 0
  • WC3 Tools: 0
  • WC3 Maps: 0
  • WC3 Skins: 0
  • WC3 Icons: 0
  • WC3 Spells: 0
  • Reputation: 8
  • cool != useful
    • View Profile
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".

  • Site Owner
  • Administrator
  • Starter - level 4
  • *
  • Posts: 979
  • WC3 Models: 5
  • WC3 Tutorials: 11
  • WC3 Tools: 10
  • WC3 Maps: 11
  • WC3 Skins: 6
  • WC3 Icons: 2
  • WC3 Spells: 3
  • Reputation: 1153
  • Site Admin - I love fix things
    • View Profile
    • Blizzard Modding Information Center
Re: Single Player Detector
« Reply #6 on: November 06, 2012, 09:07:12 AM »
Code: jass  [Select]
  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 :)


We can give you full hosting for your projects, a complete page!!

A custom altered melee map where you can play Naga and Demons. Check it out!!
Use Dropbox...

  • Rookie - level 1
  • *
  • Posts: 41
  • WC3 Models: 0
  • WC3 Tutorials: 0
  • WC3 Tools: 0
  • WC3 Maps: 0
  • WC3 Skins: 0
  • WC3 Icons: 0
  • WC3 Spells: 0
  • Reputation: 13
    • View Profile
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. :)

  • Site Owner
  • Administrator
  • Starter - level 4
  • *
  • Posts: 979
  • WC3 Models: 5
  • WC3 Tutorials: 11
  • WC3 Tools: 10
  • WC3 Maps: 11
  • WC3 Skins: 6
  • WC3 Icons: 2
  • WC3 Spells: 3
  • Reputation: 1153
  • Site Admin - I love fix things
    • View Profile
    • Blizzard Modding Information Center
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.

We can give you full hosting for your projects, a complete page!!

A custom altered melee map where you can play Naga and Demons. Check it out!!
Use Dropbox...

  • Rookie - level 1
  • *
  • Posts: 48
  • WC3 Models: 0
  • WC3 Tutorials: 0
  • WC3 Tools: 0
  • WC3 Maps: 0
  • WC3 Skins: 0
  • WC3 Icons: 0
  • WC3 Spells: 0
  • Reputation: 8
  • cool != useful
    • View Profile
Re: Single Player Detector
« Reply #9 on: November 13, 2012, 12:00:57 PM »
Code: jass  [Select]
  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".

  • Newbie - level 1
  • *
  • Posts: 8
  • WC3 Models: 0
  • WC3 Tutorials: 0
  • WC3 Tools: 0
  • WC3 Maps: 0
  • WC3 Skins: 0
  • WC3 Icons: 0
  • WC3 Spells: 0
  • Reputation: 20
  • User
    • View Profile
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.

  • Site Owner
  • Administrator
  • Starter - level 4
  • *
  • Posts: 979
  • WC3 Models: 5
  • WC3 Tutorials: 11
  • WC3 Tools: 10
  • WC3 Maps: 11
  • WC3 Skins: 6
  • WC3 Icons: 2
  • WC3 Spells: 3
  • Reputation: 1153
  • Site Admin - I love fix things
    • View Profile
    • Blizzard Modding Information Center
[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.

We can give you full hosting for your projects, a complete page!!

A custom altered melee map where you can play Naga and Demons. Check it out!!
Use Dropbox...

  • Awesome Global Code Moderator
  • Recognized User
  • Rookie - level 2
  • *
  • Posts: 83
  • WC3 Models: 0
  • WC3 Tutorials: 0
  • WC3 Tools: 0
  • WC3 Maps: 0
  • WC3 Skins: 0
  • WC3 Icons: 0
  • WC3 Spells: 0
  • Reputation: 516
  • vJass Incarnate
    • View Profile
[Snippet] Single Player Detector
« Reply #12 on: March 13, 2013, 12:48:49 PM »
A warning. Good enough for me :p

Approved.

 

[Snippet] Group Units in line, with distance and optional spread-value

Started by rvonsonsnadtzBoard Codes & Snippets

Replies: 5
Views: 11350
Last post March 13, 2013, 06:52:16 PM
by rvonsonsnadtz
[Snippet] Simple Unit Indexer

Started by moyackBoard Codes & Snippets

Replies: 17
Views: 25689
Last post September 30, 2013, 08:07:19 AM
by moyack
[Snippet] Disable Transmission Skip

Started by PurgeandfireBoard Codes & Snippets

Replies: 2
Views: 8661
Last post July 02, 2013, 01:34:55 PM
by Purgeandfire
[Snippet] Timed Effects

Started by moyackBoard Codes & Snippets

Replies: 0
Views: 7311
Last post January 09, 2012, 07:03:32 PM
by moyack
[Snippet] Parabolic Function

Started by moyackBoard Codes & Snippets

Replies: 1
Views: 7001
Last post January 13, 2012, 12:11:45 PM
by Magtheridon96
Blizzard Modding Information Center Starcraft II Modding Information Center Wacraft III Modding Information Center WC3JASS.com - The JASS Vault Chronicles of Darkness - A Warcraft III mod Jetcraft - A Starcraft II mod Troll Smash - A Warcraft III Arena
  Mod DB - Change the Game Power of Corruption - A Warcraft III altered melee map Chaos Realm - The world of Game modders and wc3 addicts Follow us on Facebook!!