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] NoSaveGame

nel · 589

0 Members and 1 Guest are viewing this topic.

Rating

Average Score - 5 / 5

« Created: November 29, 2018, 07:20:28 PM by moyack »

[Snippet] NoSaveGame
on: November 28, 2018, 11:50:18 PM
Category: Interface, System
Language: ZINC
Download Demo Map

NoSaveGame

It prevents to use Save Game function to all players.

Code: jass
  1. //! zinc
  2. library NoSaveGame  /* v1.0.0.5
  3. ************************************************************************************
  4. *
  5. *    No Save Game
  6. *        by nel
  7. *
  8. *       It prevents to use Save Game function to all players.
  9. *
  10. ***********************************************************************************/
  11.  
  12.  
  13.        requires
  14.  
  15.            optional SimError,         /* http://www.wc3c.net/showthread.php?t=101260 */
  16.            optional RegisterGameEvent /* https://www.hiveworkshop.com/threads/snippet-registerevent-pack.250266/ */
  17.  
  18.  
  19. /***********************************************************************************
  20. *
  21. *   SETTINGS
  22. *
  23. */
  24. {
  25.     public {
  26.         /*
  27.         *    It's a content of the error message.
  28.         */
  29.         string  nsgErrMsg = "You are not allowed to use Save Game.";
  30.  
  31.         /*
  32.         *    Toggleable Error Message.
  33.         */
  34.         boolean nsgDisplayErrMsg = true;
  35.  
  36.         /*
  37.         *    Toggleable NoSaveGame.
  38.         */
  39.         boolean nsg = true;
  40.     }
  41.  
  42. /*
  43. ***********************************************************************************/
  44.  
  45.     private {
  46.         constant dialog DIALOG = DialogCreate();
  47.         constant timer TIMER = CreateTimer();
  48.  
  49.         struct NoSaveGame [] { private static method onInit() {
  50.             trigger Stop = CreateTrigger();
  51.  
  52.             static if( LIBRARY_RegisterGameEvent ) {
  53.                 RegisterGameEvent(EVENT_GAME_SAVE, function() {
  54.                     player pl;
  55.  
  56.                     if( nsg ) {
  57.                         pl = GetLocalPlayer();
  58.                        
  59.                         DialogDisplay(pl, DIALOG, true);
  60.                         TimerStart(TIMER, 0, false, null);
  61.  
  62.                         static if( LIBRARY_SimError ) {
  63.                             SimError(pl, nsgErrMsg);
  64.                         } else {
  65.                             DisplayTimedTextToPlayer(pl, 0.52, 0.96, 2.00,
  66.                                 "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" +
  67.                                 "|cffffcc00" + nsgErrMsg + "|r"
  68.                             );
  69.                         }
  70.  
  71.                         pl = null;
  72.                     }
  73.                 });
  74.  
  75.                 TriggerRegisterTimerExpireEvent(Stop, TIMER);
  76.                 TriggerAddCondition(Stop, Condition(function() -> boolean {
  77.                     if( nsg ) {
  78.                         DialogDisplay(GetLocalPlayer(), DIALOG, false);
  79.                     }
  80.  
  81.                     return false;
  82.                 }));
  83.  
  84.                 Stop = null;
  85.             } else {
  86.                 trigger Save = CreateTrigger();
  87.  
  88.                 TriggerRegisterGameEvent(Save, EVENT_GAME_SAVE);
  89.                 TriggerAddCondition(Save, Condition(function() -> boolean {
  90.                     player pl;
  91.  
  92.                     if( nsg ) {
  93.                         pl = GetLocalPlayer();
  94.  
  95.                         DialogDisplay(pl, DIALOG, true);
  96.                         TimerStart(TIMER, 0, false, null);
  97.  
  98.                         if( nsgDisplayErrMsg ) {
  99.                             static if( LIBRARY_SimError ) {
  100.                                 SimError(pl, nsgErrMsg);
  101.                             } else {
  102.                                 DisplayTimedTextToPlayer(pl, 0.52, 0.96, 2.00,
  103.                                     "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" +
  104.                                     "|cffffcc00" + nsgErrMsg + "|r"
  105.                                 );
  106.                             }
  107.                         }
  108.  
  109.                         pl = null;
  110.                     }
  111.  
  112.                     return false;
  113.                 }));
  114.  
  115.                 TriggerRegisterTimerExpireEvent(Stop, TIMER);
  116.                 TriggerAddCondition(Stop, Condition(function() -> boolean {
  117.                     if( nsg ) {
  118.                         DialogDisplay(GetLocalPlayer(), DIALOG, false);
  119.                     }
  120.  
  121.                     return false;
  122.                 }));
  123.  
  124.                 Save = null;
  125.                 Stop = null;
  126.             }
  127.         }}
  128.     }
  129. }
  130. //! endzinc
« Last Edit: February 20, 2019, 05:12:06 PM by nel »



Re: [Snippet] NoSaveGame
Reply #1 on: November 30, 2018, 12:17:02 PM

Map updated? because I was going to suggest add a text that explain how to test the snippet. Anyways, nice code: simple and straight to the point.
« Last Edit: November 30, 2018, 01:13:45 PM by moyack »



Re: [Snippet] NoSaveGame
Reply #2 on: December 01, 2018, 03:08:42 AM

Map updated? because I was going to suggest add a text that explain how to test the snippet. Anyways, nice code: simple and straight to the point.

Ok, I'll update the demo map and the documentation. :)



 

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)