From 799d6ba65bf781c1caa56f439c281087b36335c6 Mon Sep 17 00:00:00 2001 From: shavit Date: Wed, 2 May 2018 10:30:44 +0300 Subject: [PATCH] Added replay deletion to admin menu. --- addons/sourcemod/scripting/shavit-replay.sp | 65 +++++++++++++++++++ addons/sourcemod/scripting/shavit-wr.sp | 1 - .../translations/shavit-replay.phrases.txt | 4 ++ 3 files changed, 69 insertions(+), 1 deletion(-) diff --git a/addons/sourcemod/scripting/shavit-replay.sp b/addons/sourcemod/scripting/shavit-replay.sp index 383ea57f..33a3c479 100644 --- a/addons/sourcemod/scripting/shavit-replay.sp +++ b/addons/sourcemod/scripting/shavit-replay.sp @@ -24,6 +24,7 @@ #undef REQUIRE_PLUGIN #include +#include #undef REQUIRE_EXTENSIONS #include @@ -129,6 +130,10 @@ char gS_ChatStrings[CHATSETTINGS_SIZE][128]; // replay settings char gS_ReplayStrings[REPLAYSTRINGS_SIZE][MAX_NAME_LENGTH]; +// admin menu +TopMenu gH_AdminMenu = null; +TopMenuObject gH_TimerCommands = INVALID_TOPMENUOBJECT; + // database related things Database gH_SQL = null; char gS_MySQLPrefix[32]; @@ -217,6 +222,12 @@ public void OnPluginStart() AutoExecConfig(); + // admin menu + if(LibraryExists("adminmenu") && ((gH_AdminMenu = GetAdminTopMenu()) != null)) + { + OnAdminMenuReady(gH_AdminMenu); + } + // hooks HookEvent("player_spawn", Player_Event, EventHookMode_Pre); HookEvent("player_death", Player_Event, EventHookMode_Pre); @@ -250,6 +261,60 @@ public void OnConVarChanged(ConVar convar, const char[] oldValue, const char[] n } } +public void OnAdminMenuCreated(Handle topmenu) +{ + if(gH_AdminMenu == null || (topmenu == gH_AdminMenu && gH_TimerCommands != INVALID_TOPMENUOBJECT)) + { + return; + } + + gH_TimerCommands = gH_AdminMenu.AddCategory("Timer Commands", CategoryHandler, "shavit_admin", ADMFLAG_RCON); +} + +public void CategoryHandler(Handle topmenu, TopMenuAction action, TopMenuObject object_id, int param, char[] buffer, int maxlength) +{ + if(action == TopMenuAction_DisplayTitle) + { + FormatEx(buffer, maxlength, "%T:", "TimerCommands", param); + } + + else if(action == TopMenuAction_DisplayOption) + { + FormatEx(buffer, maxlength, "%T", "TimerCommands", param); + } +} + +public void OnAdminMenuReady(Handle topmenu) +{ + if((gH_AdminMenu = GetAdminTopMenu()) != null) + { + if(gH_TimerCommands == INVALID_TOPMENUOBJECT) + { + gH_TimerCommands = gH_AdminMenu.FindCategory("Timer Commands"); + + if(gH_TimerCommands == INVALID_TOPMENUOBJECT) + { + OnAdminMenuCreated(topmenu); + } + } + + gH_AdminMenu.AddItem("sm_deletereplay", AdminMenu_DeleteReplay, gH_TimerCommands, "sm_deletereplay", ADMFLAG_RCON); + } +} + +public void AdminMenu_DeleteReplay(Handle topmenu, TopMenuAction action, TopMenuObject object_id, int param, char[] buffer, int maxlength) +{ + if(action == TopMenuAction_DisplayOption) + { + FormatEx(buffer, maxlength, "%t", "DeleteReplayAdminMenu"); + } + + else if(action == TopMenuAction_SelectOption) + { + Command_DeleteReplay(param, 0); + } +} + public int Native_GetReplayBotFirstFrame(Handle handler, int numParams) { SetNativeCellRef(2, gF_StartTick[GetNativeCell(1)]); diff --git a/addons/sourcemod/scripting/shavit-wr.sp b/addons/sourcemod/scripting/shavit-wr.sp index 0d7b01d0..8b9084b7 100644 --- a/addons/sourcemod/scripting/shavit-wr.sp +++ b/addons/sourcemod/scripting/shavit-wr.sp @@ -116,7 +116,6 @@ public void OnAllPluginsLoaded() { if(gH_SQL == null) { - Shavit_OnDatabaseLoaded(); } } diff --git a/addons/sourcemod/translations/shavit-replay.phrases.txt b/addons/sourcemod/translations/shavit-replay.phrases.txt index 8e3e8309..616c8bab 100644 --- a/addons/sourcemod/translations/shavit-replay.phrases.txt +++ b/addons/sourcemod/translations/shavit-replay.phrases.txt @@ -1,6 +1,10 @@ "Phrases" { // ---------- Menus ---------- // + "DeleteReplayAdminMenu" + { + "en" "Delete replay" + } "DeleteReplayMenuTitle" { "en" "Delete a replay:"