summaryrefslogtreecommitdiff
path: root/npc/commands/scheduled-broadcasts.txt
blob: 74a182a233dd9be0a3e296e491ad84110f2f36c2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
function	script	StoneBoard	{

    function setMessage {
        .@msg$="";
        do
        {
            clear;
            mes l("Please enter the message:");
            next;
            input .@msg$;
            debugmes "setMessage, received from input: "+.@msg$;
            .@msg$ = strip(.@msg$);
            debugmes "setMessage, stripped: "+.@msg$;
            if (.@msg$ != "") {
                return .@msg$;
            }
            debugmes "setMessage ------ FAILURE";
            mes l("The message cannot be empty");
            next;
        } while (.@msg$ == "");
        return .@msg$;
    }

    function setInterval {
        clear;
        mes l("Please select the interval:");
        next;
        menuint
            l("Every 1 hour"), 1,
            l("Every 3 hours"), 3,
            l("Every 5 hours"), 5,
            l("Every 6 hours"), 6,
            l("Every 12 hours"), 12,
            l("Every 24 hours"), 24,
            l("Never (only on login)"), 0;

        return @menuret;
    }

    function setMaxRep {
        if (getarg(0,0) == 0) {
            return 0;
        }
        clear;
        mes l("Repeat how many times?");
        next;
        menuint
            l("Send only once"), 1,
            l("Send 2 times"), 2,
            l("Send 3 times"), 3,
            l("Send 5 times"), 5,
            l("Send 10 times"), 10,
            l("Send 20 times"), 20,
            l("Send indefinitely"), 0;

        return @menuret;
    }

    function setOnLogin {
        if (getarg(0,0) == 0)
        {
            return 1;
        }
        clear;
        mes l("Send this message also on login?");
        next;
        select
            l("No"),
            l("Yes");

        return (@menu - 1);
    }

    function newBroadcast {
        do
        {
            setnpcdialogtitle l("Scheduled broadcasts - Create new");

            // go through all steps
            .@msg$ = setMessage();
            .@int = setInterval();
            .@max = setMaxRep(.@int);
            .@login = setOnLogin(.@int);

            // recap
            clear;
            mes l("Message:");
            mes "---";
            mes .@msg$;
            mes "---";
            if (.@int)
            {
                mes l("Interval: every @@ hour(s)", .@int);
                mes l("Repeat: @@ times", .@max ? .@max : "∞");
                mes l("Sent on login: @@", .@login ? l("yes") : l("no"));
            }
            else
            {
                mes l("Interval: (none, only sent on login)");
                mes l("Sent on login: yes");
            }

            next;
            select
                menuimage("actions/cancel", l("Discard")),
                menuimage("actions/edit", l("Start over")),
                menuimage("actions/test", l("Start broadcasting")),
                menuimage("actions/test", l("Start broadcasting, and make an extra broadcast right now"));

            switch (@menu)
            {
                case 3:
                case 4:
                        stopnpctimer "@sched";
                        $@SCHED_Opt[0] = .@login;
                        $@SCHED_Opt[1] = .@int;
                        $@SCHED_Opt[2] = 0;
                        $@SCHED_Opt[3] = .@max;
                        $@SCHED_Opt[4] = 0;
                        $@SCHED_Msg$ = .@msg$;
                        if (.@int)
                        {
                            initnpctimer "@sched";
                        }
                        if (@menu == 4)
                        {
                            announce $@SCHED_Msg$, bc_all;
                        }
                        logmes "Scheduled Broadcast: A new broadcast was added", LOGMES_ATCOMMAND;
                case 1: return;
            }

        } while(1);
    }

    do
    {
        clear;
        setnpcdialogtitle l("Scheduled broadcasts");
        mes l("This menu allows you to set the scheduled broadcast that is sent to all players at a specific interval.");
        mes "";

        .@a = $@SCHED_Msg$ != ""; // any active broadcast?
        mes "---";
        mes .@a ? $@SCHED_Msg$ : "(" + l("no active broadcast") +")";
        mes "---";
        if (.@a)
        {
            mes l("Sent on login: @@", ($@SCHED_Opt[0] ? l("yes") : l("no")));
            if ($@SCHED_Opt[1])
            {
                .@next = max(1, ((3600000 * ($@SCHED_Opt[1] - $@SCHED_Opt[4])) - getnpctimer(0, "@sched")));
                mes l("Interval: every @@ hour(s)", $@SCHED_Opt[1]);
                mes l("Next broadcast: @@", FuzzyTime(time_from_ms(.@next)));
            }
            else
            {
                mes l("Interval: (none, only sent on login)");
                mes l("Next broadcast: (never)");
            }
            mes l("Sent: @@ times out of @@", $@SCHED_Opt[2], ($@SCHED_Opt[3] ? $@SCHED_Opt[3] : "∞"));
        }
        next;

        select
            menuimage("actions/abort", l("Abort")),
            rif(.@a, menuimage("actions/test", l("Manually trigger the current broadcast"))),
            rif(.@a, menuimage("actions/remove", l("Stop broadcasting"))),
            rif(!(.@a), menuimage("actions/add", l("Set a new broadcast"))),
            rif(getarg(0,0), menuimage("actions/home", l("Return to Super Menu")));

        switch (@menu)
        {
            case 2: announce $@SCHED_Msg$, bc_all; break;
            case 3: $@SCHED_Msg$ = ""; break;
            case 4: newBroadcast; break;
            default: return;
        }
    } while (1);
}



-	script	@sched	32767,{
    end;

OnTimer3600000:
    if ($@SCHED_Msg$ == "")
    {
        stopnpctimer;
        end;
    }

    ++$@SCHED_Opt[4]; // increase hours counter
    if ($@SCHED_Opt[4] == $@SCHED_Opt[1])
    {
        stopnpctimer;
        ++$@SCHED_Opt[2]; // increase total counter
        announce $@SCHED_Msg$, bc_all;
        $@SCHED_Opt[4] = 0; // reset hours counter
        if ($@SCHED_Opt[2] >= $@SCHED_Opt[3] && $@SCHED_Opt[3] > 0)
        {
            $@SCHED_Msg$ = ""; // reset message
            end;
        }
    }
    initnpctimer;
    end;

OnCall:
    if (!is_gm())
    {
        end;
    }

    StoneBoard;
    closedialog;
    end;

OnPCLoginEvent:
    if ($@SCHED_Opt[0] && $@SCHED_Msg$ != "")
    {
        announce $@SCHED_Msg$, bc_self;
    }
    end;

OnInit:
    bindatcmd "sched", "@sched::OnCall", 80, 99, 1;
}