From 8f7a1641fca911edd0d5a21618da7fc1aa8f9bee Mon Sep 17 00:00:00 2001 From: ambaca Date: Thu, 29 Dec 2022 16:00:58 +0200 Subject: [PATCH] Friendly Fire support L4D(2) games. (#1530) Support L4D(2) Friendly Fire In Basetriggers.sp #1522 - Games have cvar mp_friendlyfire min. and max. bounds set to 1 - Removing mp_friendlyfire lower bound and set to 0, cvar have no purpose on friendly fire damage. - FF works from z_difficulty and each difficult level have FF damage ration cvars: survivor_friendly_fire_factor_easy survivor_friendly_fire_factor_normal survivor_friendly_fire_factor_hard survivor_friendly_fire_factor_expert Update added PRINT_TO_ things from previous update. Co-authored-by: Bacardi <> --- plugins/basetriggers.sp | 64 ++++++++++++++++++++++++++- translations/basetriggers.phrases.txt | 8 +++- 2 files changed, 69 insertions(+), 3 deletions(-) diff --git a/plugins/basetriggers.sp b/plugins/basetriggers.sp index f17bcfd5..1e1920ce 100644 --- a/plugins/basetriggers.sp +++ b/plugins/basetriggers.sp @@ -68,14 +68,28 @@ bool mapchooser; int g_TotalRounds; + +EngineVersion g_GameEngine = Engine_Unknown; + + public void OnPluginStart() { LoadTranslations("common.phrases"); LoadTranslations("basetriggers.phrases"); - + + g_GameEngine = GetEngineVersion(); + g_Cvar_TriggerShow = CreateConVar("sm_trigger_show", "0", "Display triggers message to all players? (0 off, 1 on, def. 0)", 0, true, 0.0, true, 1.0); g_Cvar_TimeleftInterval = CreateConVar("sm_timeleft_interval", "0.0", "Display timeleft every x seconds. Default 0.", 0, true, 0.0, true, 1800.0); - g_Cvar_FriendlyFire = FindConVar("mp_friendlyfire"); + + if (g_GameEngine == Engine_Left4Dead || g_GameEngine == Engine_Left4Dead2) + { + g_Cvar_FriendlyFire = FindConVar("z_difficulty"); + } + else + { + g_Cvar_FriendlyFire = FindConVar("mp_friendlyfire"); + } RegConsoleCmd("timeleft", Command_Timeleft); RegConsoleCmd("nextmap", Command_Nextmap); @@ -504,6 +518,52 @@ void ShowFriendlyFire(int client, int who) { if (g_Cvar_FriendlyFire) { + if (g_GameEngine == Engine_Left4Dead || g_GameEngine == Engine_Left4Dead2) + { + char buffer[50]; + g_Cvar_FriendlyFire.GetString(buffer, sizeof(buffer)); // z_difficulty + + // Easy, Normal, Hard, Impossible + if (StrEqual(buffer, "easy", false) + || StrEqual(buffer, "normal", false) + || StrEqual(buffer, "hard", false)) + { + Format(buffer, sizeof(buffer), "survivor_friendly_fire_factor_%s", buffer); + } + else if (StrEqual(buffer, "impossible", false)) + { + Format(buffer, sizeof(buffer), "survivor_friendly_fire_factor_expert"); + } + else // L4D2 game not fix cvar value to one of difficult levels, like L4D + { + Format(buffer, sizeof(buffer), "survivor_friendly_fire_factor_normal"); + } + + ConVar ff_factor = FindConVar(buffer); + + if(ff_factor) + { + float percent = ff_factor.FloatValue * 100.0; + + if (who == PRINT_TO_ALL_ALWAYS + || (who == PRINT_TO_ALL_MAYBE && g_Cvar_TriggerShow.IntValue)) + { + PrintToChatAll("[SM] %t", "Friendly Fire Percent", percent); + } + else if (client != 0 && IsClientInGame(client)) + { + PrintToChat(client,"[SM] %t", "Friendly Fire Percent", percent); + } + + if (client == 0) + { + PrintToServer("[SM] %T", "Friendly Fire Percent", client, percent); + } + } + + return; + } + char phrase[24]; if (g_Cvar_FriendlyFire.BoolValue) { diff --git a/translations/basetriggers.phrases.txt b/translations/basetriggers.phrases.txt index d1f13086..efbef1e4 100644 --- a/translations/basetriggers.phrases.txt +++ b/translations/basetriggers.phrases.txt @@ -20,7 +20,13 @@ { "en" "Friendly Fire is disabled." } - + + "Friendly Fire Percent" + { + "#format" "{1:0.0f}" + "en" "Friendly Fire is {1}%." + } + "Current Map" { "#format" "{1:s}"