Skip to content

Commit

Permalink
Merge branch 'SirPlease:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
altair-sossai authored Nov 20, 2024
2 parents f66ebbb + 68c4d78 commit 9d7eeea
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 49 deletions.
Binary file modified addons/sourcemod/plugins/optional/l4d2_magnum_incap.smx
Binary file not shown.
68 changes: 19 additions & 49 deletions addons/sourcemod/scripting/l4d2_magnum_incap.sp
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,32 @@
#pragma newdecls required

#include <sourcemod>
#include <sdktools_functions>

#define L4D2UTIL_STOCKS_ONLY 1
#include <l4d2util>

#define DEBUG 0

int g_iOffs_m_hSecondaryWeaponRestore;
ConVar g_hReplaceMagnum = null;
bool g_bHasDeagle[MAXPLAYERS + 1];

public Plugin myinfo =
{
name = "Magnum incap remover",
author = "robex, Sir",
author = "robex, Sir, Forgetest",
description = "Replace magnum with regular pistols when incapped.",
version = "0.4.1",
version = "0.5.0",
url = "https://github.com/SirPlease/L4D2-Competitive-Rework"
};

public void OnPluginStart()
{
g_iOffs_m_hSecondaryWeaponRestore = FindSendPropInfo("CTerrorPlayer", "m_iVersusTeam") - 20;

g_hReplaceMagnum = CreateConVar("l4d2_replace_magnum_incap", "1.0", "Replace magnum with single (1) or double (2) pistols when incapacitated. 0 to disable.");

HookEvent("player_incapacitated", PlayerIncap_Event);
HookEvent("revive_success", ReviveSuccess_Event);
HookEvent("round_start", RoundStart_Event);
HookEvent("bot_player_replace", Replaced_Event);
HookEvent("player_bot_replace", Replaced_Event);
}

void RoundStart_Event(Event hEvent, char[] name, bool dontBroadcast)
{
for (int i = 1; i <= MaxClients; i++)
{
g_bHasDeagle[i] = false;
}
}

void Replaced_Event(Event hEvent, char[] name, bool dontBroadcast)
{
bool bBotReplaced = (!strncmp(name, "b", 1));
int replaced = bBotReplaced ? GetClientOfUserId(hEvent.GetInt("bot")) : GetClientOfUserId(hEvent.GetInt("player"));
int replacer = bBotReplaced ? GetClientOfUserId(hEvent.GetInt("player")) : GetClientOfUserId(hEvent.GetInt("bot"));

g_bHasDeagle[replacer] = g_bHasDeagle[replaced];
}

void PlayerIncap_Event(Event hEvent, char[] name, bool dontBroadcast)
Expand All @@ -57,46 +39,34 @@ void PlayerIncap_Event(Event hEvent, char[] name, bool dontBroadcast)
// This also fires on Tank Death, so check for client team to prevent issues down the line.
if (GetClientTeam(client) != 2) { return; }

char sWeaponName[ENTITY_MAX_NAME_LENGTH];
int secWeaponIndex = GetPlayerWeaponSlot(client, L4D2WeaponSlot_Secondary);
if (secWeaponIndex == -1)
return;

char sWeaponName[ENTITY_MAX_NAME_LENGTH];
GetEdictClassname(secWeaponIndex, sWeaponName, sizeof(sWeaponName));

#if DEBUG
PrintToChatAll("client %d -> weapon %s", client, sWeaponName);
#endif

int secWeapId = WeaponNameToId(sWeaponName);
if (secWeapId == WEPID_PISTOL_MAGNUM) {
if (!strcmp(sWeaponName, "weapon_pistol_magnum") && GetPlayerSecondaryWeaponRestore(client) == -1) {
RemovePlayerItem(client, secWeaponIndex);
RemoveEntity(secWeaponIndex);
SetPlayerSecondaryWeaponRestore(client, secWeaponIndex);

GivePlayerItem(client, "weapon_pistol");
if (GetConVarInt(g_hReplaceMagnum) > 1) {
GivePlayerItem(client, "weapon_pistol");
}
g_bHasDeagle[client] = true;
} else {
g_bHasDeagle[client] = false;
}
}

void ReviveSuccess_Event(Event hEvent, char[] name, bool dontBroadcast)
int GetPlayerSecondaryWeaponRestore(int client)
{
if (GetConVarInt(g_hReplaceMagnum) < 1) { return; }

int client = GetClientOfUserId(hEvent.GetInt("subject"));

#if DEBUG
PrintToChatAll("client %d revived, g_bHasDeagle: %s", client, g_bHasDeagle[client] ? "True" : "False");
#endif

if (g_bHasDeagle[client]) {
int secWeaponIndex = GetPlayerWeaponSlot(client, L4D2WeaponSlot_Secondary);

RemovePlayerItem(client, secWeaponIndex);
RemoveEntity(secWeaponIndex);

GivePlayerItem(client, "weapon_pistol_magnum");
g_bHasDeagle[client] = false; // Gets set on incap anywoo.
}
return GetEntDataEnt2(client, g_iOffs_m_hSecondaryWeaponRestore);
}

void SetPlayerSecondaryWeaponRestore(int client, int weapon)
{
SetEntDataEnt2(client, g_iOffs_m_hSecondaryWeaponRestore, weapon);
}

0 comments on commit 9d7eeea

Please sign in to comment.