Skip to content

Commit

Permalink
Allow l4d2_slowdown_control to change crouch speed (#392)
Browse files Browse the repository at this point in the history
* Update l4d2_slowdown_control.sp

* Add files via upload

* Update l4d2_slowdown_control.sp

* Add files via upload

* Update shared_settings.cfg

* Update shared_settings.cfg

* Update shared_settings.cfg

* Update pmelite.cfg

* Update shared_settings.cfg

* Update shared_settings.cfg

* Update shared_settings.cfg

* Update shared_settings.cfg

* Update l4d2_slowdown_control.sp

* Add files via upload

* Update l4d2_slowdown_control.sp

* Add files via upload

* Update l4d2_slowdown_control.sp

* Add files via upload

* Update l4d2_slowdown_control.sp

* Add files via upload

* Update l4d2_slowdown_control.sp

* Add files via upload

* Update l4d2_slowdown_control.sp

* Add files via upload

* Update l4d2_slowdown_control.sp

* Add files via upload

* Update l4d2_slowdown_control.sp

* Add files via upload

* Update l4d2_slowdown_control.sp

* Add files via upload
  • Loading branch information
Derpduck authored Oct 30, 2021
1 parent 911f352 commit 3b49522
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 5 deletions.
Binary file modified addons/sourcemod/plugins/optional/l4d2_slowdown_control.smx
Binary file not shown.
83 changes: 78 additions & 5 deletions addons/sourcemod/scripting/l4d2_slowdown_control.sp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#pragma newdecls required

#include <sourcemod>
#include <sdktools>
#include <left4dhooks>
#include <l4d2util_stocks>

Expand Down Expand Up @@ -52,22 +53,26 @@ ConVar
hCvarSdInwaterSurvivor,
hCvarSdInwaterDuringTank,
hCvarSurvivorLimpspeed,
hCvarTankSpeedVS;
hCvarTankSpeedVS,
hCvarCrouchSpeedMod;

float
fTankWaterSpeed,
fSurvWaterSpeed,
fSurvWaterSpeedDuringTank,
fTankRunSpeed;
fTankRunSpeed,
fCrouchSpeedMod;

bool
tankInPlay = false;
tankInPlay = false,
bFoundCrouchTrigger = false,
bPlayerInCrouchTrigger[MAXPLAYERS + 1];

public Plugin myinfo =
{
name = "L4D2 Slowdown Control",
author = "Visor, Sir, darkid, Forgetest, A1m`",
version = "2.6.6",
author = "Visor, Sir, darkid, Forgetest, A1m`, Derpduck",
version = "2.6.7",
description = "Manages the water/gunfire slowdown for both teams",
url = "https://github.com/SirPlease/L4D2-Competitive-Rework"
};
Expand All @@ -79,6 +84,7 @@ public void OnPluginStart()
hCvarSdInwaterTank = CreateConVar("l4d2_slowdown_water_tank", "-1", "Maximum tank speed in the water (-1: ignore setting; 0: default; 210: default Tank Speed)", _, true, -1.0);
hCvarSdInwaterSurvivor = CreateConVar("l4d2_slowdown_water_survivors", "-1", "Maximum survivor speed in the water outside of Tank fights (-1: ignore setting; 0: default; 220: default Survivor speed)", _, true, -1.0);
hCvarSdInwaterDuringTank = CreateConVar("l4d2_slowdown_water_survivors_during_tank", "0", "Maximum survivor speed in the water during Tank fights (0: ignore setting; 220: default Survivor speed)", _, true, 0.0);
hCvarCrouchSpeedMod = CreateConVar("l4d2_slowdown_crouch_speed_mod", "1.0", "Modifier of player crouch speed when inside a designated trigger, 75 is the defualt for everyone (1: default speed)", _, true, 0.0);

hCvarSdPistolMod = CreateConVar("l4d2_slowdown_pistol_percent", "0.0", "Pistols cause this much slowdown * l4d2_slowdown_gunfire at maximum damage.");
hCvarSdDeagleMod = CreateConVar("l4d2_slowdown_deagle_percent", "0.1", "Deagles cause this much slowdown * l4d2_slowdown_gunfire at maximum damage.");
Expand All @@ -101,6 +107,7 @@ public void OnPluginStart()
hCvarSdInwaterSurvivor.AddChangeHook(OnConVarChanged);
hCvarSdInwaterDuringTank.AddChangeHook(OnConVarChanged);
hCvarTankSpeedVS.AddChangeHook(OnConVarChanged);
hCvarCrouchSpeedMod.AddChangeHook(OnConVarChanged);

HookEvent("tank_spawn", TankSpawn, EventHookMode_PostNoCopy);
HookEvent("round_start", RoundStart, EventHookMode_PostNoCopy);
Expand All @@ -124,6 +131,7 @@ void CvarsToType()
fSurvWaterSpeed = hCvarSdInwaterSurvivor.FloatValue;
fSurvWaterSpeedDuringTank = hCvarSdInwaterDuringTank.FloatValue;
fTankRunSpeed = hCvarTankSpeedVS.FloatValue;
fCrouchSpeedMod = hCvarCrouchSpeedMod.FloatValue;
}

public Action TankSpawn(Event event, const char[] name, bool dontBroadcast)
Expand Down Expand Up @@ -158,6 +166,48 @@ public Action Timer_CheckTank(Handle timer)
public Action RoundStart(Event event, const char[] name, bool dontBroadcast)
{
tankInPlay = false;
HookCrouchTriggers();
}

public void HookCrouchTriggers()
{
bFoundCrouchTrigger = false;

// Hook trigger_multiple entities that are named "l4d2_slowdown_crouch_speed"
if (fCrouchSpeedMod != 1.0) {
// Reset array
for (int i = 1; i <= MaxClients; i++) {
bPlayerInCrouchTrigger[i] = false;
}

int iEntity = -1;
char targetname[128];

while ((iEntity = FindEntityByClassname(iEntity, "trigger_multiple")) != -1) {
GetEntPropString(iEntity, Prop_Data, "m_iName", targetname, sizeof(targetname));

if (StrEqual(targetname, "l4d2_slowdown_crouch_speed", false)) {
HookSingleEntityOutput(iEntity, "OnStartTouch", CrouchSpeedStartTouch);
HookSingleEntityOutput(iEntity, "OnEndTouch", CrouchSpeedEndTouch);

bFoundCrouchTrigger = true;
}
}
}
}

public void CrouchSpeedStartTouch(const char[] output, int caller, int activator, float delay)
{
if (0 < activator <= MaxClients && IsClientInGame(activator)) {
bPlayerInCrouchTrigger[activator] = true;
}
}

public void CrouchSpeedEndTouch(const char[] output, int caller, int activator, float delay)
{
if (0 < activator <= MaxClients && IsClientInGame(activator)) {
bPlayerInCrouchTrigger[activator] = false;
}
}

/**
Expand Down Expand Up @@ -250,6 +300,29 @@ public Action L4D_OnGetRunTopSpeed(int client, float &retVal)
return Plugin_Continue;
}

/**
*
* Slowdown from crouching: All players
*
**/
public Action L4D_OnGetCrouchTopSpeed(int client, float &retVal)
{
if (fCrouchSpeedMod == 1.0 || !bFoundCrouchTrigger || !IsClientInGame(client)) {
return Plugin_Continue;
}

if (bPlayerInCrouchTrigger[client]) {
bool bGrounded = (GetEntityFlags(client) & FL_ONGROUND) ? true : false;

if (bGrounded) {
retVal = retVal * fCrouchSpeedMod; // 75 * modifier
return Plugin_Handled;
}
}

return Plugin_Continue;
}

// The old slowdown plugin's cvars weren't quite intuitive, so I'll try to fix it this time
float GetActualValue(ConVar cvar)
{
Expand Down
1 change: 1 addition & 0 deletions cfg/cfgogl/apex/shared_settings.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ confogl_addcvar l4d2_slowdown_gunfire_tank 0.23
confogl_addcvar l4d2_slowdown_water_tank 0
confogl_addcvar l4d2_slowdown_water_survivors -1
confogl_addcvar l4d2_slowdown_water_survivors_during_tank 220
confogl_addcvar l4d2_slowdown_crouch_speed_mod 1
confogl_addcvar l4d2_slowdown_pistol_percent 0.5
confogl_addcvar l4d2_slowdown_deagle_percent 0.8
confogl_addcvar l4d2_slowdown_uzi_percent 0.7
Expand Down
1 change: 1 addition & 0 deletions cfg/cfgogl/eq/shared_settings.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ confogl_addcvar l4d2_slowdown_gunfire_tank 0
confogl_addcvar l4d2_slowdown_water_tank 0
confogl_addcvar l4d2_slowdown_water_survivors 220
confogl_addcvar l4d2_slowdown_water_survivors_during_tank 0
confogl_addcvar l4d2_slowdown_crouch_speed_mod 1

// [l4d_tank_damage_announce.smx]
confogl_addcvar l4d_tankdamage_enabled 1
Expand Down
1 change: 1 addition & 0 deletions cfg/cfgogl/nextmod/shared_settings.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ confogl_addcvar l4d2_slowdown_gunfire_tank 0
confogl_addcvar l4d2_slowdown_water_tank 0
confogl_addcvar l4d2_slowdown_water_survivors -1
confogl_addcvar l4d2_slowdown_water_survivors_during_tank 220
confogl_addcvar l4d2_slowdown_crouch_speed_mod 1

// [l4d2_horde_equaliser.smx]
confogl_addcvar l4d2_heq_checkpoint_sound 1
Expand Down
1 change: 1 addition & 0 deletions cfg/cfgogl/pmelite/pmelite.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ confogl_addcvar l4d2_slowdown_gunfire_tank 0.24
confogl_addcvar l4d2_slowdown_water_tank 0
confogl_addcvar l4d2_slowdown_water_survivors -1
confogl_addcvar l4d2_slowdown_water_survivors_during_tank 220
confogl_addcvar l4d2_slowdown_crouch_speed_mod 1
confogl_addcvar l4d2_slowdown_pistol_percent 0.5
confogl_addcvar l4d2_slowdown_deagle_percent 0.8
confogl_addcvar l4d2_slowdown_uzi_percent 0.7
Expand Down
1 change: 1 addition & 0 deletions cfg/cfgogl/zonehunters/shared_settings.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ confogl_addcvar l4d2_slowdown_gunfire_tank 0
confogl_addcvar l4d2_slowdown_water_tank 0
confogl_addcvar l4d2_slowdown_water_survivors -1
confogl_addcvar l4d2_slowdown_water_survivors_during_tank 220
confogl_addcvar l4d2_slowdown_crouch_speed_mod 1.4

// [l4d_tank_damage_announce.smx]
confogl_addcvar l4d_tankdamage_enabled 1
Expand Down
1 change: 1 addition & 0 deletions cfg/cfgogl/zonemod/shared_settings.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ confogl_addcvar l4d2_slowdown_gunfire_tank 0
confogl_addcvar l4d2_slowdown_water_tank 0
confogl_addcvar l4d2_slowdown_water_survivors -1
confogl_addcvar l4d2_slowdown_water_survivors_during_tank 220
confogl_addcvar l4d2_slowdown_crouch_speed_mod 1.4

// [l4d_tank_damage_announce.smx]
confogl_addcvar l4d_tankdamage_enabled 1
Expand Down
1 change: 1 addition & 0 deletions cfg/cfgogl/zonemodold/shared_settings.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ confogl_addcvar l4d2_slowdown_gunfire_tank 0
confogl_addcvar l4d2_slowdown_water_tank 0
confogl_addcvar l4d2_slowdown_water_survivors -1
confogl_addcvar l4d2_slowdown_water_survivors_during_tank 220
confogl_addcvar l4d2_slowdown_crouch_speed_mod 1

// [l4d2_horde_equaliser.smx]
confogl_addcvar l4d2_heq_checkpoint_sound 1
Expand Down
1 change: 1 addition & 0 deletions cfg/cfgogl/zoneretro/shared_settings.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ confogl_addcvar l4d2_slowdown_gunfire_tank 0
confogl_addcvar l4d2_slowdown_water_tank 0
confogl_addcvar l4d2_slowdown_water_survivors -1
confogl_addcvar l4d2_slowdown_water_survivors_during_tank 220
confogl_addcvar l4d2_slowdown_crouch_speed_mod 1.4

// [l4d_tank_damage_announce.smx]
confogl_addcvar l4d_tankdamage_enabled 1
Expand Down

0 comments on commit 3b49522

Please sign in to comment.