Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TF2] Fix broken NoWeaponDrops (shavit-misc) #1160

Merged
merged 2 commits into from
Jul 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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