Skip to content

Commit

Permalink
[TF2] Fix broken NoWeaponDrops (shavit-misc) (#1160)
Browse files Browse the repository at this point in the history
* Fix broken shavit_misc_noweapondrops for TF2

* Set dropped weapon lifetime OnConfigsExecuted
  • Loading branch information
jedso authored Jul 25, 2022
1 parent 68a57b9 commit 578636d
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions addons/sourcemod/scripting/shavit-misc.sp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ ConVar mp_humanteam = null;
ConVar hostname = null;
ConVar hostport = null;
ConVar sv_disable_radar = null;
ConVar tf_dropped_weapon_lifetime = null;

// forwards
Handle gH_Forwards_OnClanTagChangePre = null;
Expand Down Expand Up @@ -289,10 +290,12 @@ public void OnPluginStart()
}

gCV_HideRadar.AddChangeHook(OnConVarChanged);
gCV_NoWeaponDrops.AddChangeHook(OnConVarChanged);
Convar.AutoExecConfig();

mp_humanteam = FindConVar((gEV_Type == Engine_TF2) ? "mp_humans_must_join_team" : "mp_humanteam");
sv_disable_radar = FindConVar("sv_disable_radar");
tf_dropped_weapon_lifetime = FindConVar("tf_dropped_weapon_lifetime");

// crons
CreateTimer(10.0, Timer_Cron, 0, TIMER_REPEAT);
Expand Down Expand Up @@ -373,10 +376,21 @@ void LoadDHooks()

public void OnConVarChanged(ConVar convar, const char[] oldValue, const char[] newValue)
{
if (sv_disable_radar != null)
if (convar == gCV_HideRadar && sv_disable_radar != null)
{
sv_disable_radar.BoolValue = gCV_HideRadar.BoolValue;
}
else if (gEV_Type == Engine_TF2 && convar == gCV_NoWeaponDrops)
{
if (convar.BoolValue)
{
tf_dropped_weapon_lifetime.IntValue = 0;
TF2_KillDroppedWeapons();
} else
{
tf_dropped_weapon_lifetime.IntValue = 30; // default value
}
}
}

public MRESReturn Hook_IsSpawnPointValid(Handle hReturn, Handle hParams)
Expand Down Expand Up @@ -541,6 +555,11 @@ public void OnConfigsExecuted()
sv_disable_radar.BoolValue = true;
}

if (tf_dropped_weapon_lifetime != null && gCV_NoWeaponDrops.BoolValue)
{
tf_dropped_weapon_lifetime.IntValue = 0;
}

if(gCV_CreateSpawnPoints.IntValue > 0)
{
int info_player_terrorist = FindEntityByClassname(-1, "info_player_terrorist");
Expand Down Expand Up @@ -1201,6 +1220,16 @@ void RemoveRagdoll(int client)
}
}

void TF2_KillDroppedWeapons()
{
int ent = -1;

while ((ent = FindEntityByClassname(ent, "tf_dropped_weapon")) != -1)
{
AcceptEntityInput(ent, "Kill");
}
}

public void Shavit_OnPause(int client, int track)
{
if (gB_Eventqueuefix)
Expand Down Expand Up @@ -1365,8 +1394,11 @@ public Action Shavit_OnUserCmdPre(int client, int &buttons, int &impulse, float
public void OnClientPutInServer(int client)
{
SDKHook(client, SDKHook_SetTransmit, OnSetTransmit);
SDKHook(client, SDKHook_WeaponDrop, OnWeaponDrop);
SDKHook(client, SDKHook_OnTakeDamage, OnTakeDamage);
if(gEV_Type != Engine_TF2)
{
SDKHook(client, SDKHook_WeaponDrop, OnWeaponDrop);
}

gI_LastWeaponTick[client] = 0;
gI_LastNoclipTick[client] = 0;
Expand Down

0 comments on commit 578636d

Please sign in to comment.