From f0c670be3c6cca5533b842d9b626711bc5d3bf05 Mon Sep 17 00:00:00 2001 From: Jesusaves Date: Sat, 10 Apr 2021 12:10:43 -0300 Subject: Add @exprate/@droprate - And drop the legacy stoneboard --- npc/commands/scheduled-broadcasts.txt | 227 ++++++++++++++++++++++++++++++++++ 1 file changed, 227 insertions(+) create mode 100644 npc/commands/scheduled-broadcasts.txt (limited to 'npc/commands/scheduled-broadcasts.txt') diff --git a/npc/commands/scheduled-broadcasts.txt b/npc/commands/scheduled-broadcasts.txt new file mode 100644 index 00000000..1801663a --- /dev/null +++ b/npc/commands/scheduled-broadcasts.txt @@ -0,0 +1,227 @@ +// Evol Script +// Authors: Gumi +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 @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; + +OnInit: + bindatcmd "sched", "@sched::OnCall", 80, 99, 1; +} + +function script StoneBoardRead { + if ($@SCHED_Opt[0] && $@SCHED_Msg$ != "") + { + announce $@SCHED_Msg$, bc_self; + } + return; +} -- cgit v1.2.3-60-g2f50