From f1f0ad289736a3b5aba8231fcd4d4cacfc319412 Mon Sep 17 00:00:00 2001 From: anzz1 Date: Wed, 10 Sep 2025 04:07:12 +0300 Subject: [PATCH] "nextmap" plugin fixes Revise the logic so the operation makes more sense and fixes ancient bugs - Remove the back-and-forth changing of the "mp_chattime" cvar, instead just deduct one second from it for the change task (with bounds checking, if mp_chattime is less than one including something stupid like a negative value, the map change will be immediate) - Add a list of mods known to not have a "mp_chattime" cvar but use a static time instead (Opposing Force, Ricochet, Gunman Chronicles each use 6 seconds) and set the chattime appropriately Also some QOL - Add "/nextmap", "/currentmap", "/ff" client say commands - Do not print the command itself to chat when someone uses it --- plugins/nextmap.sma | 47 ++++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/plugins/nextmap.sma b/plugins/nextmap.sma index b69ae06a3..1e546b55c 100755 --- a/plugins/nextmap.sma +++ b/plugins/nextmap.sma @@ -22,7 +22,7 @@ new g_nextMap[32] new g_mapCycle[32] new g_pos new g_currentMap[32] -new g_changeMapCalled; +new Float:g_chattime // pcvars new g_mp_friendlyfire, g_mp_chattime @@ -34,14 +34,18 @@ public plugin_init() register_dictionary("nextmap.txt") register_event("30", "changeMap", "a") register_clcmd("say nextmap", "sayNextMap", 0, "- displays nextmap") + register_clcmd("say /nextmap", "sayNextMap", 0, "- displays nextmap") register_clcmd("say currentmap", "sayCurrentMap", 0, "- display current map") + register_clcmd("say /currentmap", "sayCurrentMap", 0, "- display current map") g_amx_nextmap = register_cvar("amx_nextmap", "", FCVAR_SERVER|FCVAR_EXTDLL|FCVAR_SPONLY) g_mp_chattime = get_cvar_pointer("mp_chattime") g_mp_friendlyfire = get_cvar_pointer("mp_friendlyfire") + g_chattime = getModChatTime() if( g_mp_friendlyfire ) { register_clcmd("say ff", "sayFFStatus", 0, "- display friendly fire status") + register_clcmd("say /ff", "sayFFStatus", 0, "- display friendly fire status") } get_mapname(g_currentMap, charsmax(g_currentMap)) @@ -81,16 +85,22 @@ public sayNextMap() getNextMapName(name, charsmax(name)) client_print(0, print_chat, "%L %s", LANG_PLAYER, "NEXT_MAP", name) + + return PLUGIN_HANDLED } public sayCurrentMap() { client_print(0, print_chat, "%L: %s", LANG_PLAYER, "PLAYED_MAP", g_currentMap) + + return PLUGIN_HANDLED } public sayFFStatus() { client_print(0, print_chat, "%L: %L", LANG_PLAYER, "FRIEND_FIRE", LANG_PLAYER, get_pcvar_num(g_mp_friendlyfire) ? "ON" : "OFF") + + return PLUGIN_HANDLED } public delayedChange(param[]) @@ -98,24 +108,15 @@ public delayedChange(param[]) engine_changelevel(param) } -public plugin_end() -{ - if (g_mp_chattime && g_changeMapCalled) { - set_pcvar_float(g_mp_chattime, get_pcvar_float(g_mp_chattime) - 2.0) - } -} - public changeMap() { new string[32] - new Float:chattime = g_mp_chattime ? get_pcvar_float(g_mp_chattime) : 0.0; - - if (g_mp_chattime) { - set_pcvar_float(g_mp_chattime, chattime + 2.0) // make sure mp_chattime is long - g_changeMapCalled = true; - } + new Float:chattime = floatmax(0.0, (g_mp_chattime ? get_pcvar_float(g_mp_chattime) : g_chattime) - 1.0) + new len = getNextMapName(string, charsmax(string)) + 1 - set_task(chattime, "delayedChange", 0, string, len) // change with 1.5 sec. delay + client_print(0, print_chat, "%L %s", LANG_PLAYER, "NEXT_MAP", string) + + set_task(chattime, "delayedChange", 0, string, len) } new g_warning[] = "WARNING: Couldn't find a valid map or the file doesn't exist (file ^"%s^")" @@ -235,3 +236,19 @@ readMapCycle(szFileName[], szNext[], iNext) g_pos = 0 } #endif + +// Mods that do not have a mp_chattime cvar +stock Float:getModChatTime() +{ + new mod_name[32] + get_modname(mod_name, charsmax(mod_name)) + + if (equal(mod_name, "gearbox")) + return 6.0 + else if (equal(mod_name, "ricochet")) + return 6.0 + else if (equal(mod_name, "rewolf")) + return 6.0 + + return 0.0 +}