Skip to content

Commit

Permalink
Fixes the scenario of obtaining a secondary item through a weapon_spa…
Browse files Browse the repository at this point in the history
  • Loading branch information
altair-sossai authored and fantasylidong committed Jun 26, 2024
1 parent b2f79f1 commit efb2488
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Binary file modified addons/sourcemod/plugins/optional/l4d2_drop_secondary.smx
Binary file not shown.
14 changes: 10 additions & 4 deletions addons/sourcemod/scripting/l4d2_drop_secondary.sp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#pragma newdecls required
#include <sourcemod>
#include <sdktools>
#include <left4dhooks>

char sSecondary[MAXPLAYERS + 1][64];
char sMeleeScript[MAXPLAYERS + 1][64];
Expand Down Expand Up @@ -113,10 +114,15 @@ public void Event_OnPlayerUse(Event event, const char[] name, bool dontBroadcast
if (IsValidSurvivor(client) && IsValidEntity(targetid))
{
char sClassname[32];
GetEntityClassname(targetid, sClassname, sizeof(sClassname))
GetEntityClassname(targetid, sClassname, sizeof(sClassname));

if (StrContains(sClassname, "pistol") != -1 ||
StrContains(sClassname, "melee") != -1)
if (StrContains(sClassname, "weapon_spawn") != -1)
{
L4D2WeaponId weaponID = view_as<L4D2WeaponId>(GetEntProp(targetid, Prop_Send, "m_weaponID"));
L4D2_GetWeaponNameByWeaponId(weaponID, sClassname, sizeof(sClassname));
}

if (StrContains(sClassname, "pistol") != -1 || StrContains(sClassname, "melee") != -1)
{
// We do an actual check of what the client has here because we deal with limitations in certain configs.
// The limitation would cause the secondary to be set on the client while the client didn't even equip it.
Expand Down Expand Up @@ -166,7 +172,7 @@ bool IsValidSurvivor(int client)
void SpawnSecondary(int client)
{
int weapon;

if (StrEqual(sSecondary[client], SECONDARY_PISTOL)) weapon = CreateEntityByName("weapon_pistol");
else if (StrEqual(sSecondary[client], SECONDARY_PISTOL_MAGNUM)) weapon = CreateEntityByName("weapon_pistol_magnum");
else
Expand Down

0 comments on commit efb2488

Please sign in to comment.