Skip to content

Commit

Permalink
Prevent collecting Zombie Sandviches at short amount of time (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikusch authored Dec 14, 2023
1 parent c99d335 commit 2811603
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions addons/sourcemod/scripting/szf/sdkhook.sp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
static int g_iOffsetDisguiseCompleteTime;
static float g_flDisguiseCompleteTime;
static bool g_bLunchboxTouched[MAXPLAYERS + 1];

void SDKHook_OnEntityCreated(int iEntity, const char[] sClassname)
{
Expand Down Expand Up @@ -34,6 +35,8 @@ void SDKHook_HookClient(int iClient)
SDKHook(iClient, SDKHook_OnTakeDamage, Client_OnTakeDamage);
SDKHook(iClient, SDKHook_GetMaxHealth, Client_GetMaxHealth);
SDKHook(iClient, SDKHook_WeaponSwitchPost, Client_WeaponSwitchPost);

g_bLunchboxTouched[iClient] = false;
}

void SDKHook_UnhookClient(int iClient)
Expand Down Expand Up @@ -320,18 +323,35 @@ public Action Pickup_SandvichTouch(int iEntity, int iToucher)
if (iOwner == iToucher || g_nInfected[iToucher] == Infected_Tank)
return Plugin_Handled;

//Don't stack lunchbox damages
if (g_bLunchboxTouched[iToucher])
return Plugin_Handled;

if (IsSurvivor(iToucher))
{
//Kill it and deal damage
RemoveEntity(iEntity);
DealDamage(iOwner, iToucher, 55.0);

g_bLunchboxTouched[iToucher] = true;
CreateTimer(2.0, Timer_ResetLunchboxTouched, GetClientUserId(iToucher));

return Plugin_Handled;
}

return Plugin_Continue;
}

public Action Timer_ResetLunchboxTouched(Handle hTimer, int iUserId)
{
int iClient = GetClientOfUserId(iUserId);
if (iClient == 0)
return Plugin_Continue;

g_bLunchboxTouched[iClient] = false;
return Plugin_Continue;
}

public Action Pickup_BananaTouch(int iEntity, int iToucher)
{
//Check if toucher is valid client
Expand All @@ -342,6 +362,10 @@ public Action Pickup_BananaTouch(int iEntity, int iToucher)
if (g_nInfected[iToucher] == Infected_Tank)
return Plugin_Handled;

//Don't stack lunchbox damages
if (g_bLunchboxTouched[iToucher])
return Plugin_Handled;

if (IsSurvivor(iToucher))
{
int iOwner = GetEntPropEnt(iEntity, Prop_Send, "m_hOwnerEntity");
Expand All @@ -350,6 +374,9 @@ public Action Pickup_BananaTouch(int iEntity, int iToucher)
RemoveEntity(iEntity);
DealDamage(iOwner, iToucher, 30.0);

g_bLunchboxTouched[iToucher] = true;
CreateTimer(1.0, Timer_ResetLunchboxTouched, GetClientUserId(iToucher));

return Plugin_Handled;
}

Expand Down

0 comments on commit 2811603

Please sign in to comment.