diff --git a/plugins/l4d2_TKStopper.smx b/plugins/l4d2_TKStopper.smx index 982a037..585aa9f 100644 Binary files a/plugins/l4d2_TKStopper.smx and b/plugins/l4d2_TKStopper.smx differ diff --git a/scripting/include/feedthetrolls/timers.inc b/scripting/include/feedthetrolls/timers.inc index a8b9d35..97863aa 100644 --- a/scripting/include/feedthetrolls/timers.inc +++ b/scripting/include/feedthetrolls/timers.inc @@ -161,4 +161,47 @@ public Action Timer_CheckIsInSpit(Handle h, int userid) { return Plugin_Stop; } return Plugin_Continue; +} + +float CHARGER_CHECK_MIN[3] = { -15.0, -15.0, 2.0}; +float CHARGER_CHECK_MAX[3] = { 15.0, 15.0, 20.0 }; + +public Action Timer_CheckForChargerOpportunity(Handle h, int userid) { + int client = GetClientOfUserId(userid); + if(client) { + int activator = GetClientOfUserId(g_iSmartChargeActivator[client]); + if(!activator) { + g_iSmartChargeActivator[client] = 0; + } + float pos[3], ang[3], endPos[3], spawnPos[3]; + GetClientAbsOrigin(client, pos); + GetClientEyeAngles(client, ang); + + GetHorizontalPositionFromOrigin(pos, ang, -150.0, endPos); + TR_TraceHullFilter(endPos, pos, CHARGER_CHECK_MIN, CHARGER_CHECK_MAX, MASK_SOLID, Filter_CheckChargerValid, client); + if(!TR_DidHit()) { + spawnPos = endPos; + GetHorizontalPositionFromOrigin(pos, ang, 500.0, endPos); + TR_TraceHullFilter(endPos, pos, CHARGER_CHECK_MIN, CHARGER_CHECK_MAX, MASK_SOLID, Filter_CheckChargerValid, client); + if(!TR_DidHit()) { + SpawnSpecialAtPosition(Special_Charger, spawnPos, ang, client); + if(activator) PrintToChat(activator, "Auto charge %N successfully after %d tries", client, g_iSmartChargeAttempts[client]); + g_iSmartChargeAttempts[client] = 0; + g_iSmartChargeActivator[client] = 0; + return Plugin_Stop; + } + } + if(++g_iSmartChargeAttempts[client] > g_iSmartChargeMaxAttempts[client]) { + if(activator) PrintToChat(activator, "Auto charge timed out after %d attempts", g_iSmartChargeAttempts[client]); + g_iSmartChargeAttempts[client] = 0; + g_iSmartChargeActivator[client] = 0; + return Plugin_Stop; + } + return Plugin_Continue; + } + return Plugin_Stop; +} + +public bool Filter_CheckChargerValid(int entity, int contentsMask, any data) { + return entity <= 0 || entity >= MaxClients || (entity != data && GetClientTeam(entity) == 2); } \ No newline at end of file diff --git a/scripting/l4d2_TKStopper.sp b/scripting/l4d2_TKStopper.sp index 5bdabac..1ede30a 100644 --- a/scripting/l4d2_TKStopper.sp +++ b/scripting/l4d2_TKStopper.sp @@ -49,6 +49,8 @@ enum struct PlayerData { PlayerData pData[MAXPLAYERS+1]; ConVar hForgivenessTime, hBanTime, hThreshold, hJoinTime, hTKAction, hSuicideAction, hSuicideLimit, hFFAutoScaleAmount, hFFAutoScaleForgivenessAmount, hFFAutoScaleMaxRatio, hFFAutoScaleIgnoreAdmins; +char gamemode[64]; +bool isEnabled = true; public Plugin myinfo = { name = "TK Stopper", @@ -83,6 +85,10 @@ public void OnPluginStart() { hFFAutoScaleForgivenessAmount = CreateConVar("l4d2_tk_auto_ff_forgive_rate", "0.05", "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); + ConVar hGamemode = FindConVar("mp_gamemode"); + hGamemode.AddChangeHook(Event_GamemodeChange); + Event_GamemodeChange(hGamemode, gamemode, gamemode); + AutoExecConfig(true, "l4d2_tkstopper"); HookEvent("finale_vehicle_ready", Event_FinaleVehicleReady); @@ -119,6 +125,14 @@ public void OnPluginStart() { } LoadTranslations("common.phrases"); } +public void Event_GamemodeChange(ConVar cvar, const char[] oldValue, const char[] newValue) { + cvar.GetString(gamemode, sizeof(gamemode)); + if(StrEqual(gamemode, "coop")) { + isEnabled = true; + } else { + isEnabled = false; + } +} /////////////////////////////////////////////////////////////////////////////// // Special Infected Events /////////////////////////////////////////////////////////////////////////////// @@ -210,7 +224,7 @@ public void OnClientDisconnect(int client) { // Only clear things when they fully left on their own accord: public void Event_PlayerDisconnect(Event event, const char[] name, bool dontBroadcast) { - if(!event.GetBool("disconnect")) return; + if(!event.GetBool("disconnect") || !isEnabled) return; int client = GetClientOfUserId(event.GetInt("userid")); if(client > 0 && event.GetInt("team") <= 2) { @@ -243,7 +257,7 @@ 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(isEnabled && damage > 0.0 && victim <= MaxClients && attacker <= MaxClients && attacker > 0 && victim > 0) { if(GetClientTeam(victim) != GetClientTeam(attacker) || attacker == victim) return Plugin_Continue; else if(damagetype & DMG_BURN && IsFakeClient(attacker) && GetClientTeam(attacker) == 2) { @@ -406,6 +420,9 @@ public Action Event_OnTakeDamage(int victim, int& attacker, int& inflictor, flo public Action Command_TKInfo(int client, int args) { int time = GetTime(); + if(!isEnabled) { + ReplyToCommand(client, "Warn: Plugin is disabled in current gamemode (%s)", gamemode); + } if(args > 0) { static char arg1[32]; GetCmdArg(1, arg1, sizeof(arg1));