diff --git a/l4d2_tank_draw/scripting/l4d2_tank_draw.sp b/l4d2_tank_draw/scripting/l4d2_tank_draw.sp index c3b49ba..cba978d 100644 --- a/l4d2_tank_draw/scripting/l4d2_tank_draw.sp +++ b/l4d2_tank_draw/scripting/l4d2_tank_draw.sp @@ -153,6 +153,7 @@ public void OnPluginStart() HookEvent("player_death", Event_PlayerDeath, EventHookMode_Pre); HookEvent("mission_lost", Event_Lost, EventHookMode_Pre); + HookEvent("player_bot_replace", Event_PlayerBotReplace, EventHookMode_Pre); HookEvent("molotov_thrown", Event_Molotov); @@ -312,6 +313,46 @@ public void OnClientDisconnect(int client) return; } +public Action Event_PlayerBotReplace(Event event, const char[] name, bool dontBroadcast) +{ + if (g_iTankDrawEnable == 0) { return Plugin_Continue; } + DebugPrint("Event_PlayerBotReplace triggered."); + + // Get the player who was replaced (the human player who went idle) + int player = GetClientOfUserId(event.GetInt("player")); + DebugPrint("player id : %d is replaced", player); + + if (!IsValidClient(player)) + { + DebugPrint("Invalid player in player_bot_replace event."); + return Plugin_Continue; + } + + // Check if player has a timer bomb + if (g_hTimeBombTimer[player] != null || g_hFreezeBombTimer[player] != null || g_hDrugTimers[player] != null) + { + char playerName[MAX_NAME_LENGTH]; + GetClientName(player, playerName, sizeof(playerName)); + + CPrintToChatAll("%t", "TankDraw_Avoid_Punish", playerName); + PrintHintTextToAll("%t", "TankDraw_Avoid_Punish_NoColor", playerName); + + int botId = GetClientOfUserId(event.GetInt("bot")); + DebugPrint("replace bot id: %d", botId); + + KillFreezeBombTimer(player); + KillFreezeBombTimer(botId); + + ForcePlayerSuicide(player); + ForcePlayerSuicide(botId); + + DebugPrint("Player %s (userid: %d) was killed for avoiding punishment.", playerName, event.GetInt("player")); + return Plugin_Continue; + } + + return Plugin_Continue; +} + public Action Event_Molotov(Event event, const char[] name, bool dontBroadcast) { DebugPrint("Event_Molotov triggered."); diff --git a/l4d2_tank_draw/translations/l4d2_tank_draw.phrases.txt b/l4d2_tank_draw/translations/l4d2_tank_draw.phrases.txt index f6ae0c4..aa19865 100644 --- a/l4d2_tank_draw/translations/l4d2_tank_draw.phrases.txt +++ b/l4d2_tank_draw/translations/l4d2_tank_draw.phrases.txt @@ -671,4 +671,16 @@ "en" "[Tank Draw] Player %s's lucky draw result: Drug all survivor for %d seconds." "chi" "[坦克抽奖] 玩家 %s 的幸运抽奖结果: 全体中毒 %d 秒" } + + "TankDraw_Avoid_Punish" + { + "en" "{yellow}[Tank Draw] {lightgreen}Player {olive}%s{lightgreen} attempted to avoid punishment. {olive} Executed." + "chi" "{yellow}[坦克抽奖] {lightgreen}玩家 {olive}%s{lightgreen} 试图躲避惩罚,已被{olive}处决" + } + + "TankDraw_Avoid_Punish_NoColor" + { + "en" "[Tank Draw] Player %s attempted to avoid punishment. Executed." + "chi" "[坦克抽奖] 玩家 %s 视图躲避惩罚,已被处决" + } } \ No newline at end of file