#include #include #pragma semicolon 1 #pragma newdecls required #define PLUGIN_VERSION "1.1" #define CHAT_PREFIX "\x04[Events]\x01" #define PANEL_LINE_WIDTH 60 #define KEY_BACK 8 #define KEY_EXIT 10 public Plugin myinfo = { name = "EventNotifier Menu", author = "marisakirisame.net", description = "Shows upcoming Unloze events in-game via sm_event", version = PLUGIN_VERSION, url = "https://marisakirisame.net" }; public void OnPluginStart() { RegConsoleCmd("sm_event", Command_EventMenu, "Shows upcoming Unloze events. Usage: sm_event [event number]"); RegConsoleCmd("sm_events", Command_EventMenu, "Shows upcoming Unloze events. Usage: sm_events [event number]"); } // --------------------------------------------------------------------------- // Commands // --------------------------------------------------------------------------- public Action Command_EventMenu(int client, int args) { if (client <= 0 || !IsClientInGame(client)) { ReplyToCommand(client, "This command can only be used in-game."); return Plugin_Handled; } if (EventNotifier_GetEventCount() == 0) { if (EventNotifier_HasFetched()) PrintToChat(client, "%s There are no upcoming events.", CHAT_PREFIX); else PrintToChat(client, "%s The event list is not available right now, try again later.", CHAT_PREFIX); return Plugin_Handled; } if (args >= 1) { char arg[16]; GetCmdArg(1, arg, sizeof(arg)); int number = StringToInt(arg); int index = EventNotifier_FindEventByNumber(number); if (index == -1) { PrintToChat(client, "%s Event #%d is not in the upcoming list.", CHAT_PREFIX, number); return Plugin_Handled; } ShowEventDetails(client, index); return Plugin_Handled; } ShowEventList(client); return Plugin_Handled; } // --------------------------------------------------------------------------- // Menus // --------------------------------------------------------------------------- void ShowEventList(int client) { Menu menu = new Menu(EventList_Handler); menu.SetTitle("Upcoming Unloze events"); int count = EventNotifier_GetEventCount(); for (int i = 0; i < count; i++) { EventInfo ev; if (!EventNotifier_GetEvent(i, ev)) continue; char info[16], display[EVENT_STR_LEN + 16]; IntToString(ev.number, info, sizeof(info)); Format(display, sizeof(display), "%d: %s", ev.number, ev.name); menu.AddItem(info, display); } menu.ExitButton = true; menu.Display(client, MENU_TIME_FOREVER); } public int EventList_Handler(Menu menu, MenuAction action, int param1, int param2) { switch (action) { case MenuAction_Select: { char info[16]; menu.GetItem(param2, info, sizeof(info)); int index = EventNotifier_FindEventByNumber(StringToInt(info)); if (index == -1) { PrintToChat(param1, "%s That event is no longer in the upcoming list.", CHAT_PREFIX); ShowEventList(param1); } else { ShowEventDetails(param1, index); } } case MenuAction_End: { delete menu; } } return 0; } void ShowEventDetails(int client, int index) { EventInfo ev; if (!EventNotifier_GetEvent(index, ev)) { PrintToChat(client, "%s That event is no longer in the upcoming list.", CHAT_PREFIX); return; } char line[EVENT_STR_LEN + 32]; Panel panel = new Panel(); Format(line, sizeof(line), "Event #%d: %s", ev.number, ev.name); panel.SetTitle(line); panel.DrawText(" "); if (ev.start > 0) { char when[64]; FormatTime(when, sizeof(when), "%a %d %b %Y, %H:%M %Z", ev.start); Format(line, sizeof(line), "Date: %s", when); panel.DrawText(line); EventNotifier_FormatRelativeTime(ev.start, ev.end, line, sizeof(line)); panel.DrawText(line); } else { panel.DrawText("Date: unknown"); } Format(line, sizeof(line), "Server: %s", ev.server[0] ? ev.server : "unknown"); panel.DrawText(line); if (ev.maps[0]) DrawWrappedList(panel, "Maps: ", ev.maps); else panel.DrawText("Maps: none listed"); Format(line, sizeof(line), "Rewards: %s", ev.rewards[0] ? ev.rewards : "none"); panel.DrawText(line); Format(line, sizeof(line), "Leader: %s", ev.leader[0] ? ev.leader : "none"); panel.DrawText(line); Format(line, sizeof(line), "Kickers: %s", ev.kickers[0] ? ev.kickers : "none"); panel.DrawText(line); panel.DrawText(" "); panel.CurrentKey = KEY_BACK; panel.DrawItem("Back"); panel.CurrentKey = KEY_EXIT; panel.DrawItem("Exit"); panel.Send(client, EventDetails_Handler, MENU_TIME_FOREVER); delete panel; } public int EventDetails_Handler(Menu menu, MenuAction action, int param1, int param2) { if (action == MenuAction_Select && param2 == KEY_BACK) { if (IsClientInGame(param1)) Command_EventMenu(param1, 0); } return 0; } // Draws "prefix a, b, c" and continues onto new indented lines when a line // would exceed PANEL_LINE_WIDTH characters, splitting only at the commas. void DrawWrappedList(Panel panel, const char[] prefix, const char[] list) { char parts[32][128]; int count = ExplodeString(list, ", ", parts, sizeof(parts), sizeof(parts[])); char line[PANEL_LINE_WIDTH + 160]; strcopy(line, sizeof(line), prefix); bool lineHasItems = false; for (int i = 0; i < count; i++) { char item[132]; strcopy(item, sizeof(item), parts[i]); if (i < count - 1) StrCat(item, sizeof(item), ","); if (lineHasItems && strlen(line) + 1 + strlen(item) > PANEL_LINE_WIDTH) { panel.DrawText(line); strcopy(line, sizeof(line), " "); lineHasItems = false; } else if (lineHasItems) { StrCat(line, sizeof(line), " "); } StrCat(line, sizeof(line), item); lineHasItems = true; } if (lineHasItems) panel.DrawText(line); }