This commit is contained in:
Jackzie 2022-01-19 14:52:52 -06:00
parent 755c2f24f9
commit 3c88c010ad
No known key found for this signature in database
GPG key ID: 1E834FE36520537A
17 changed files with 503 additions and 232 deletions

View file

@ -4,9 +4,6 @@
//#define DEBUG
#define PLUGIN_VERSION "1.0"
#define FF_BAN_THRESHOLD 100.0
#define FF_BAN_JOIN_MINUTES_THRESHOLD 2
#define FF_BAN_MINUTES 60
#include <sourcemod>
#include <sdktools>
@ -14,17 +11,19 @@
#include <jutils>
#include <left4dhooks>
bool lateLoaded, IsFinaleEnding, isPlayerTroll[MAXPLAYERS+1], isImmune[MAXPLAYERS+1], isUnderAttack[MAXPLAYERS+1];
int iJoinTime[MAXPLAYERS+1], iIdleStartTime[MAXPLAYERS+1], iJumpAttempts[MAXPLAYERS+1];
float playerTotalDamageFF[MAXPLAYERS+1];
int lastFF[MAXPLAYERS+1];
bool lateLoaded, isFinaleEnding;
bool isPlayerTroll[MAXPLAYERS+1], isImmune[MAXPLAYERS+1], isUnderAttack[MAXPLAYERS+1];
int iJoinTime[MAXPLAYERS+1];
int iIdleStartTime[MAXPLAYERS+1];
int iLastFFTime[MAXPLAYERS+1];
int iJumpAttempts[MAXPLAYERS+1];
float playerTotalDamageFF[MAXPLAYERS+1];
float autoFFScaleFactor[MAXPLAYERS+1];
ConVar hForgivenessTime, hBanTime, hThreshold, hJoinTime, hTKAction, hSuicideAction, hSuicideLimit, hFFAutoScaleAmount, hFFAutoScaleForgivenessAmount, hFFAutoScaleMaxRatio, hFFAutoScaleIgnoreAdmins;
public Plugin myinfo =
{
public Plugin myinfo = {
name = "TK Stopper",
author = "jackzmc",
description = "",
@ -38,28 +37,26 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max
}
}
public void OnPluginStart()
{
public void OnPluginStart() {
EngineVersion g_Game = GetEngineVersion();
if(g_Game != Engine_Left4Dead && g_Game != Engine_Left4Dead2)
{
if(g_Game != Engine_Left4Dead && g_Game != Engine_Left4Dead2) {
SetFailState("This plugin is for L4D/L4D2 only.");
}
hForgivenessTime = CreateConVar("l4d2_tk_forgiveness_time", "15", "The minimum amount of time to pass (in seconds) where a player's previous accumulated FF is forgiven", FCVAR_NONE, true, 0.0);
hBanTime = CreateConVar("l4d2_tk_bantime", "60", "How long in minutes should a player be banned for? 0 for permanently", FCVAR_NONE, true, 0.0);
hBanTime = CreateConVar("l4d2_tk_bantime", "120", "How long in minutes should a player be banned for? 0 for permanently", FCVAR_NONE, true, 0.0);
hThreshold = CreateConVar("l4d2_tk_ban_ff_threshold", "75.0", "How much damage does a player need to do before being instantly banned", FCVAR_NONE, true, 0.0);
hJoinTime = CreateConVar("l4d2_tk_ban_join_time", "2", "Upto how many minutes should any new player be subjected to instant bans on any FF", FCVAR_NONE, true, 0.0);
hTKAction = CreateConVar("l4d2_tk_action", "3", "How should the TK be punished?\n0 = No action (No message), 1 = Kick, 2 = Instant Ban, 3 = Ban on disconnect", FCVAR_NONE, true, 0.0, true, 3.0);
hSuicideAction = CreateConVar("l4d2_suicide_action", "3", "How should a suicider be punished?\n0 = No action (No message), 1 = Kick, 2 = Instant Ban, 3 = Ban on disconnect", FCVAR_NONE, true, 0.0, true, 3.0);
hSuicideLimit = CreateConVar("l4d2_suicide_limit", "1", "How many attempts does a new joined player have until action is taken for suiciding?", FCVAR_NONE, true, 0.0);
hFFAutoScaleAmount = CreateConVar("l4d2_tk_auto_ff_rate", "0.04", "The rate at which auto reverse-ff is scaled by.", FCVAR_NONE, true, 0.0);
// Reverse FF Auto Scale
hFFAutoScaleAmount = CreateConVar("l4d2_tk_auto_ff_rate", "0.01", "The rate at which auto reverse-ff is scaled by.", FCVAR_NONE, true, 0.0);
hFFAutoScaleMaxRatio = CreateConVar("l4d2_tk_auto_ff_max_ratio", "5.0", "The maximum amount that the reverse ff can go. 0.0 for unlimited", FCVAR_NONE, true, 0.0);
hFFAutoScaleForgivenessAmount = CreateConVar("l4d2_tk_auto_ff_forgive_rate", "0.008", "This amount times amount of minutes since last ff is removed from ff rate", FCVAR_NONE, true, 0.0);
hFFAutoScaleForgivenessAmount = CreateConVar("l4d2_tk_auto_ff_forgive_rate", "0.02", "This amount times amount of minutes since last ff is removed from ff rate", FCVAR_NONE, true, 0.0);
hFFAutoScaleIgnoreAdmins = CreateConVar("l4d2_tk_auto_ff_ignore_admins", "1", "Should automatic reverse ff ignore admins? 0 = Admins are subjected\n1 = Admins are excempt", FCVAR_NONE, true, 0.0, true, 1.0);
//AutoExecConfig(true, "l4d2_tkstopper");
AutoExecConfig(true, "l4d2_tkstopper");
HookEvent("finale_vehicle_ready", Event_FinaleVehicleReady);
HookEvent("player_disconnect", Event_PlayerDisconnect);
@ -83,7 +80,6 @@ public void OnPluginStart()
RegAdminCmd("sm_ignore", Command_IgnorePlayer, ADMFLAG_KICK, "Makes a player immune for any anti trolling detection for a session");
RegAdminCmd("sm_tkinfo", Command_TKInfo, ADMFLAG_KICK, "Debug info for TKSTopper");
if(lateLoaded) {
@ -93,29 +89,14 @@ public void OnPluginStart()
}
}
}
// CreateTimer(60.0, Timer_Forgive, _, TIMER_REPEAT);
}
/*public Action Timer_Forgive(Handle h) {
for(int i = 1; i <= MaxClients; i++) {
if(IsClientConnected(i) && IsClientInGame(i) && GetClientTeam(i) == 2 && ) {
}
}
return Plugin_Continue;
}*/
///////////////////////////////////////////////////////////////////////////////
// Special Infected Events
///////////////////////////////////////////////////////////////////////////////
public Action Event_ChargerCarry(Event event, const char[] name, bool dontBroadcast) {
int victim = GetClientOfUserId(event.GetInt("victim"));
if(victim) {
if(StrEqual(name, "charger_carry_start")) {
isUnderAttack[victim] = true;
}else{
isUnderAttack[victim] = false;
}
isUnderAttack[victim] = StrEqual(name, "charger_carry_start");
}
return Plugin_Continue;
}
@ -123,11 +104,7 @@ public Action Event_ChargerCarry(Event event, const char[] name, bool dontBroadc
public Action Event_HunterPounce(Event event, const char[] name, bool dontBroadcast) {
int victim = GetClientOfUserId(event.GetInt("victim"));
if(victim) {
if(StrEqual(name, "lunge_pounce")) {
isUnderAttack[victim] = true;
}else{
isUnderAttack[victim] = false;
}
isUnderAttack[victim] = StrEqual(name, "lunge_pounce");
}
return Plugin_Continue;
}
@ -135,41 +112,35 @@ public Action Event_HunterPounce(Event event, const char[] name, bool dontBroadc
public Action Event_SmokerChoke(Event event, const char[] name, bool dontBroadcast) {
int victim = GetClientOfUserId(event.GetInt("victim"));
if(victim) {
if(StrEqual(name, "choke_start")) {
isUnderAttack[victim] = true;
}else{
isUnderAttack[victim] = false;
}
isUnderAttack[victim] = StrEqual(name, "choke_start");
}
return Plugin_Continue;
}
public Action Event_JockeyRide(Event event, const char[] name, bool dontBroadcast) {
int victim = GetClientOfUserId(event.GetInt("victim"));
if(victim) {
if(StrEqual(name, "jockey_ride")) {
isUnderAttack[victim] = true;
}else{
isUnderAttack[victim] = false;
}
isUnderAttack[victim] = StrEqual(name, "jockey_ride");
}
return Plugin_Continue;
}
///////////////////////////////////////////////////////////////////////////////
// IDLE
///////////////////////////////////////////////////////////////////////////////
public Action Event_BotToPlayer(Handle event, const char[] name, bool dontBroadcast) {
int player = GetClientOfUserId(GetEventInt(event, "player"));
public Action Event_BotToPlayer(Event event, const char[] name, bool dontBroadcast) {
int player = GetClientOfUserId(event.GetInt("player"));
if (!IsValidClient(player) || (GetClientTeam(player) != 2 && GetClientTeam(player) != 3) || IsFakeClient(player)) return Plugin_Continue; // ignore fake players (side product of creating bots)
// ignore fake players (side product of creating bots)
if (!IsValidClient(player) || (GetClientTeam(player) != 2 && GetClientTeam(player) != 3) || IsFakeClient(player)) return Plugin_Continue;
// If a player has been idle for over 600s (10 min), reset to them "first joining"
// If a player has been idle for over 600s (10 min), reset to them "just joined"
// Purpose: Some trolls idle till end and then attack @ escape, or "gain trust"
if(GetTime() - iIdleStartTime[player] >= 600) {
iJoinTime[player] = GetTime();
}
return Plugin_Continue;
}
public Action Event_PlayerToBot(Handle event, char[] name, bool dontBroadcast) {
int player = GetClientOfUserId(GetEventInt(event, "player"));
public Action Event_PlayerToBot(Event event, char[] name, bool dontBroadcast) {
int player = GetClientOfUserId(event.GetInt("player"));
iIdleStartTime[player] = GetTime();
return Plugin_Continue;
}
@ -177,7 +148,7 @@ public Action Event_PlayerToBot(Handle event, char[] name, bool dontBroadcast) {
// Misc events
///////////////////////////////////////////////////////////////////////////////
public void Event_FinaleVehicleReady(Event event, const char[] name, bool dontBroadcast) {
IsFinaleEnding = true;
isFinaleEnding = true;
for(int i = 1; i <= MaxClients; i++) {
if(isPlayerTroll[i] && IsClientConnected(i) && IsClientInGame(i)) {
PrintChatToAdmins("Note: %N is still marked as troll and will be banned after this game. Use /ignore to ignore them.", i);
@ -186,12 +157,12 @@ public void Event_FinaleVehicleReady(Event event, const char[] name, bool dontBr
}
public void OnMapEnd() {
IsFinaleEnding = false;
isFinaleEnding = false;
}
public void OnClientPutInServer(int client) {
iJoinTime[client] = GetTime();
lastFF[client] = GetTime();
iLastFFTime[client] = GetTime();
SDKHook(client, SDKHook_OnTakeDamage, Event_OnTakeDamage);
}
@ -200,7 +171,6 @@ public void OnClientDisconnect(int client) {
playerTotalDamageFF[client] = 0.0;
isUnderAttack[client] = false;
iJumpAttempts[client] = 0;
isUnderAttack[client] = false;
}
// Only clear things when they fully left on their own accord:
@ -214,20 +184,27 @@ public void Event_PlayerDisconnect(Event event, const char[] name, bool dontBroa
}
public Action Event_OnTakeDamage(int victim, int& attacker, int& inflictor, float& damage, int& damagetype, int& weapon, float damageForce[3], float damagePosition[3]) {
if(damage > 0.0 && victim <= MaxClients && attacker <= MaxClients && attacker > 0 && victim > 0) {
if(damagetype & DMG_BURN && IsFakeClient(attacker)) {
if(damage > 0.0 && victim <= MaxClients && attacker <= MaxClients && attacker > 0 && victim > 0 && attacker != victim) {
if(GetClientTeam(victim) != GetClientTeam(attacker) || attacker == victim) return Plugin_Continue;
else if(damagetype & DMG_BURN && IsFakeClient(attacker)) {
// Ignore damage from fire caused by bots (players who left after causing fire)
damage = 0.0;
return Plugin_Changed;
}
// Otherwise if attacker was ignored or is a bot, stop here and let vanilla handle it
else if(isImmune[attacker] || IsFakeClient(attacker)) return Plugin_Continue;
bool isAdmin = GetUserAdmin(attacker) != INVALID_ADMIN_ID;
bool ignore = hFFAutoScaleIgnoreAdmins.BoolValue && isAdmin;
if(isImmune[attacker] || IsFakeClient(attacker)) return Plugin_Continue;
if(GetClientTeam(victim) != 2 || GetClientTeam(attacker) != 2 || attacker == victim) return Plugin_Continue;
//Allow friendly firing BOTS that aren't idle players:
//if(IsFakeClient(victim) && !HasEntProp(attacker, Prop_Send, "m_humanSpectatorUserID") || GetEntProp(attacker, Prop_Send, "m_humanSpectatorUserID") == 0) return Plugin_Continue;
// Stop all damage early if already marked as troll
if(isPlayerTroll[attacker]) return Plugin_Stop;
if(isPlayerTroll[attacker]) {
SDKHooks_TakeDamage(attacker, attacker, attacker, autoFFScaleFactor[attacker] * damage);
return Plugin_Stop;
}
// Allow vanilla-damage if being attacked by special (example, charger carry)
if(isUnderAttack[victim]) return Plugin_Continue;
@ -258,33 +235,34 @@ public Action Event_OnTakeDamage(int victim, int& attacker, int& inflictor, flo
}
// Forgive player based on threshold, resetting accumlated damage
if(time - lastFF[attacker] > hForgivenessTime.IntValue) {
if(time - iLastFFTime[attacker] > hForgivenessTime.IntValue) {
playerTotalDamageFF[attacker] = 0.0;
}
playerTotalDamageFF[attacker] += damage;
// Auto reverse ff logic
lastFF[attacker] = time;
if(isDamageDirect && !ignore) {
// Decrement any recovered FF
float minutesSinceLastFF = (time - lastFF[attacker]) / 60.0;
autoFFScaleFactor[attacker] -= minutesSinceLastFF * hFFAutoScaleForgivenessAmount.FloatValue;
iLastFFTime[attacker] = time;
if(isDamageDirect && (!hFFAutoScaleIgnoreAdmins.BoolValue || !isAdmin)) {
// Decrement any forgiven ratio (computed on demand)
float minutesSinceiLastFFTime = (time - iLastFFTime[attacker]) / 60.0;
autoFFScaleFactor[attacker] -= minutesSinceiLastFFTime * hFFAutoScaleForgivenessAmount.FloatValue;
if(autoFFScaleFactor[attacker] < 0.0) {
autoFFScaleFactor[attacker] = 0.0;
}
// Then increment
// Then calculate a new reverse ff ratio
autoFFScaleFactor[attacker] += hFFAutoScaleAmount.FloatValue * damage;
if(hFFAutoScaleMaxRatio.FloatValue > 0.0 && autoFFScaleFactor[attacker] > hFFAutoScaleMaxRatio.FloatValue) {
autoFFScaleFactor[attacker] = hFFAutoScaleMaxRatio.FloatValue;
if(isPlayerTroll[attacker]) {
autoFFScaleFactor[attacker] *= 2;
}
if(minutesSinceLastFF > 3.0) {
PrintToConsoleAdmins("%N new reverse ratio: %f", attacker, autoFFScaleFactor[attacker]);
if(!isPlayerTroll[attacker] && hFFAutoScaleMaxRatio.FloatValue > 0.0 && autoFFScaleFactor[attacker] > hFFAutoScaleMaxRatio.FloatValue) {
autoFFScaleFactor[attacker] = hFFAutoScaleMaxRatio.FloatValue;
}
}
// Check for excessive friendly fire damage in short timespan
if(!isAdmin && playerTotalDamageFF[attacker] > hThreshold.IntValue && !IsFinaleEnding && isDamageDirect) {
LogAction(-1, attacker, "Excessive FF (%.2f HP)", playerTotalDamageFF[attacker]);
if(!isAdmin && playerTotalDamageFF[attacker] > hThreshold.IntValue && !isFinaleEnding && isDamageDirect) {
LogAction(-1, attacker, "Excessive FF (%.2f HP) (%.2f RFF Rate)", playerTotalDamageFF[attacker], autoFFScaleFactor[attacker]);
if(hTKAction.IntValue == 1) {
LogMessage("[NOTICE] Kicking %N for excessive FF (%.2f HP) for %d minutes.", attacker, playerTotalDamageFF[attacker], hBanTime.IntValue);
NotifyAllAdmins("[Notice] Kicking %N for excessive FF (%.2f HP) for %d minutes.", attacker, playerTotalDamageFF[attacker], hBanTime.IntValue);
@ -304,39 +282,51 @@ public Action Event_OnTakeDamage(int victim, int& attacker, int& inflictor, flo
// Modify damages based on criteria
if(iJumpAttempts[victim] > 0 || L4D_IsInFirstCheckpoint(victim) || L4D_IsInLastCheckpoint(victim) || time - iJoinTime[attacker] <= hJoinTime.IntValue * 60) {
// If the amount of MS is <= join time threshold * 60000 ms then cancel
// Or if the player is in a saferoom
// Or if the player tried to suicide jump
/*
If the amount of seconds since they joined is <= the minimum join time cvar (min) threshold
or if the player is in a saferoom
or if the player tried to suicide jump
Then cancel all damage:
*/
damage = 0.0;
return Plugin_Handled;
}else if(IsFinaleEnding) {
}else if(isFinaleEnding) {
// Keep admins immune if escape vehicle out
if(isAdmin) return Plugin_Continue;
SDKHooks_TakeDamage(attacker, attacker, attacker, damage * 2.0);
damage = 0.0;
return Plugin_Changed;
}else if(!isDamageDirect) { // Ignore fire and propane damage, mistakes can happen
SDKHooks_TakeDamage(attacker, attacker, attacker, float(RoundToCeil(autoFFScaleFactor[attacker] * damage)));
damage /= 2.1;
}else if(isDamageDirect) { // Ignore fire and propane damage, mistakes can happen
// Apply their reverse ff damage, and have victim take a decreasing amount
SDKHooks_TakeDamage(attacker, attacker, attacker, autoFFScaleFactor[attacker] * damage);
if(isPlayerTroll[attacker]) return Plugin_Stop;
if(autoFFScaleFactor[attacker] > 1.0)
damage /= autoFFScaleFactor[attacker];
else
damage /= 2.0;
return Plugin_Changed;
}
}
return Plugin_Continue;
}
/// COMMANDS
public Action Command_TKInfo(int client, int args) {
int time = GetTime();
for(int i = 1; i <= MaxClients; i++) {
if(IsClientConnected(i) && IsClientInGame(i) && !IsFakeClient(i)) {
float minutesSinceLastFF = (time - lastFF[i]) / 60.0;
float activeRate = autoFFScaleFactor[i] - (minutesSinceLastFF * hFFAutoScaleForgivenessAmount.FloatValue);
float minutesSinceiLastFFTime = (time - iLastFFTime[i]) / 60.0;
float activeRate = autoFFScaleFactor[i] - (minutesSinceiLastFFTime * hFFAutoScaleForgivenessAmount.FloatValue);
if(activeRate < 0.0) {
activeRate = 0.0;
}
ReplyToCommand(client, "%N: %f TK-FF buffer | %f (active: %f), reverse FF rate | %f ff min ago | %d suicide jumps", i, playerTotalDamageFF[i], autoFFScaleFactor[i], activeRate, minutesSinceLastFF, iJumpAttempts[i]);
ReplyToCommand(client, "%N: %f TK-FF buffer | %.3f (buf %f), reverse FF rate | last ff %.1f min ago | %d suicide jumps", i, playerTotalDamageFF[i], activeRate, autoFFScaleFactor[i], minutesSinceiLastFFTime, iJumpAttempts[i]);
}
}
return Plugin_Handled;
}
public Action Command_IgnorePlayer(int client, int args) {
char arg1[32];
GetCmdArg(1, arg1, sizeof(arg1));
@ -379,6 +369,9 @@ public Action Command_IgnorePlayer(int client, int args) {
return Plugin_Handled;
}
/// STOCKS
stock bool GetNearestPlayerPosition(int client, float pos[3]) {
static float targetPos[3], lowestDist;
int lowestID = -1;