Couch/EventNotifier changes

This commit is contained in:
2026-10-08 16:28:13 +01:00
parent 54a921c1a5
commit 82d16c163a
3 changed files with 53 additions and 12 deletions
@@ -45,7 +45,7 @@ public void OnPluginStart()
AutoExecConfig(true, "EventNotifierAnnouncements");
RegAdminCmd("sm_event_announce", Command_Announce, ADMFLAG_GENERIC, "Posts the next event announcement in chat now");
RegAdminCmd("sm_event_announce", Command_Announce, ADMFLAG_GENERIC, "sm_event_announce [event number] - Posts an event announcement in chat now (next in rotation if no number given)");
}
public void OnConfigsExecuted()
@@ -80,10 +80,38 @@ public Action Timer_Announce(Handle timer)
public Action Command_Announce(int client, int args)
{
if (PostAnnouncement())
ReplyToCommand(client, "[Events] Announcement posted.");
if (args < 1)
{
if (PostAnnouncement())
ReplyToCommand(client, "[Events] Announcement posted.");
else
ReplyToCommand(client, "[Events] No upcoming events to announce.");
return Plugin_Handled;
}
char arg[16];
GetCmdArg(1, arg, sizeof(arg));
int number;
if (StringToIntEx(arg, number) != strlen(arg) || number <= 0)
{
ReplyToCommand(client, "[Events] Usage: sm_event_announce [event number]");
return Plugin_Handled;
}
int index = EventNotifier_FindEventByNumber(number);
if (index == -1)
{
ReplyToCommand(client, "[Events] Event #%d is not in the upcoming list.", number);
return Plugin_Handled;
}
// Explicitly requested events are posted outside the rotation so the
// automatic announcements carry on where they left off.
if (AnnounceEvent(index))
ReplyToCommand(client, "[Events] Announcement for event #%d posted.", number);
else
ReplyToCommand(client, "[Events] No upcoming events to announce.");
ReplyToCommand(client, "[Events] Event #%d could not be announced.", number);
return Plugin_Handled;
}
@@ -91,7 +119,8 @@ public Action Command_Announce(int client, int args)
// Announcement
// ---------------------------------------------------------------------------
// Posts one event from the rotation window. Returns false when there is nothing to post.
// Posts the next event from the rotation window and advances the rotation.
// Returns false when there is nothing to post.
bool PostAnnouncement()
{
int count = EventNotifier_GetEventCount();
@@ -105,6 +134,13 @@ bool PostAnnouncement()
int index = g_iRotation % window;
g_iRotation = (index + 1) % window;
return AnnounceEvent(index);
}
// Posts the event at the given list index to everyone. Returns false if the
// index is out of range.
bool AnnounceEvent(int index)
{
EventInfo ev;
if (!EventNotifier_GetEvent(index, ev))
return false;