summaryrefslogtreecommitdiff
path: root/npc/commands
diff options
context:
space:
mode:
authorgumi <mekolat@users.noreply.github.com>2016-08-14 16:23:55 -0400
committergumi <mekolat@users.noreply.github.com>2016-09-01 12:09:02 -0400
commit2fa3eebd17a78b617f767df46988ddefefb9f71e (patch)
tree9148f96d58c024c6a526fc7fd131304380935aec /npc/commands
parentae65394b74712943664aff19c880f6ede07a035b (diff)
downloadserverdata-2fa3eebd17a78b617f767df46988ddefefb9f71e.tar.gz
serverdata-2fa3eebd17a78b617f767df46988ddefefb9f71e.tar.bz2
serverdata-2fa3eebd17a78b617f767df46988ddefefb9f71e.tar.xz
serverdata-2fa3eebd17a78b617f767df46988ddefefb9f71e.zip
add scheduled broadcasts
Diffstat (limited to 'npc/commands')
-rw-r--r--npc/commands/numa.txt2
-rw-r--r--npc/commands/scheduled-broadcasts.txt212
2 files changed, 213 insertions, 1 deletions
diff --git a/npc/commands/numa.txt b/npc/commands/numa.txt
index cd28c580..f9fff699 100644
--- a/npc/commands/numa.txt
+++ b/npc/commands/numa.txt
@@ -17,7 +17,7 @@ function script SuperMenu {
switch (@menuret)
{
- //case 1: StoneBoard 1; break;
+ case 1: StoneBoard 1; break;
case 2: MOTDConfig 1; break;
case 3: GlobalEventMenu 1; break;
case 4: GlobalDebugMenu 1; break;
diff --git a/npc/commands/scheduled-broadcasts.txt b/npc/commands/scheduled-broadcasts.txt
new file mode 100644
index 00000000..e8c16d6e
--- /dev/null
+++ b/npc/commands/scheduled-broadcasts.txt
@@ -0,0 +1,212 @@
+function script StoneBoard {
+
+ function setMessage {
+ do
+ {
+ clear;
+ mes l("Please enter the message:");
+ next;
+ input .@msg$;
+ .@msg$ = strip(.@msg$);
+ if (.@msg$ != "")
+ {
+ return .@msg$;
+ }
+ mes l("The message cannot be empty");
+ next;
+ } while (1);
+ }
+
+ 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 max(0, @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 max(0, @menuret);
+ }
+
+ function setOnLogin {
+ if (getarg(0,0) == 0)
+ {
+ return 1;
+ }
+ clear;
+ mes l("Send this message also on login?");
+ next;
+ menuint
+ l("No"), 0,
+ l("Yes"), 1;
+
+ return max(0, @menuret);
+ }
+
+ 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;
+ menuint
+ menuimage("actions/cancel", l("Discard")), 1,
+ menuimage("actions/edit", l("Start over")), 2,
+ menuimage("actions/test", l("Start broadcasting")), 3,
+ menuimage("actions/test", l("Start broadcasting, and make an extra broadcast right now")), 4,
+ menuimage("actions/exit", l("Close")), 5;
+
+ switch (@menuret)
+ {
+ case 3:
+ case 4:
+ stopnpctimer "@sched";
+ $@SCHED_Opt[0] = .@login;
+ $@SCHED_Opt[1] = .@int;
+ $@SCHED_Opt[2] = 0;
+ $@SCHED_Opt[3] = .@max;
+ $@SCHED_Msg$ = .@msg$;
+ if (.@int)
+ {
+ initnpctimer "@sched";
+ }
+ if (@menuret == 4)
+ {
+ announce $@SCHED_Msg$, bc_all;
+ }
+ case 1: return;
+ case 5: closedialog; end;
+ }
+
+ } 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])
+ {
+ mes l("Interval: every @@ hour(s)", $@SCHED_Opt[1]);
+ //mes l("Next broadcast: "); // FIXME: (needs a HumanTime function)
+ }
+ 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;
+
+ menuint
+ menuimage("actions/abort", l("Abort")), 5,
+ rif(.@a, menuimage("actions/test", l("Manually trigger the current broadcast"))), 2,
+ rif(.@a, menuimage("actions/remove", l("Stop broadcasting"))), 3,
+ rif(!(.@a), menuimage("actions/add", l("Set a new broadcast"))), 4,
+ rif(getarg(0,0), menuimage("actions/home", l("Return to Super Menu"))), 5,
+ menuimage("actions/exit", l("Close")), 6;
+
+ switch (@menuret)
+ {
+ case 2: announce $@SCHED_Msg$, bc_all; break;
+ case 3: $@SCHED_Msg$ = ""; break;
+ case 4: newBroadcast; break;
+ case 6: closedialog; end;
+ default: return;
+ }
+ } while (1);
+}
+
+
+
+- script @sched 32767,{
+ end;
+
+OnTimer3600000:
+ stopnpctimer;
+ ++$@SCHED_Opt[2];
+ if ($@SCHED_Msg$ != "")
+ {
+ announce $@SCHED_Msg$, bc_all;
+ if ($@SCHED_Opt[2] < $@SCHED_Opt[3] && $@SCHED_Opt[3] > 0)
+ {
+ initnpctimer;
+ }
+ }
+ end;
+
+OnCall:
+ StoneBoard;
+ closedialog;
+ end;
+
+OnPCLoginEvent:
+ if ($@SCHED_Opt[0] && $@SCHED_Msg$ != "")
+ {
+ announce $@SCHED_Msg$, bc_self;
+ }
+ end;
+
+OnInit:
+ bindatcmd "sched", "@sched::OnCall", 3, 99, 0;
+}