[Snippet] NoSaveGame

Scripts

7 years
edited 7 years
NoSaveGame

It prevents to use Save Game function to all players.

Code (jass) Select
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
  • NoSaveGame.w3x (20.75 KB)
7 years
edited 7 years
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.
7 years
Quote from: moyack 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.

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