Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma semicolon 1
- #include <sourcemod>
- #include <sdktools>
- #include <sdkhooks>
- #include <l4d2_weapon_stocks>
- int g_PlayerSecondaryWeapons[MAXPLAYERS + 1];
- public OnPluginStart()
- {
- HookEvent("round_start", vies_as<EventHook>(EventHookOnRoundStart), EventHookMode_PostNoCopy);
- HookEvent("player_use", OnPlayerUse, EventHookMode_Post);
- HookEvent("player_bot_replace", OnBotSwap);
- HookEvent("bot_player_replace", OnBotSwap);
- HookEvent("player_death", OnPlayerDeath, EventHookMode_Pre);
- }
- public OnRoundStart()
- {
- for (int i = 0; i <= MAXPLAYERS; i++)
- {
- g_PlayerSecondaryWeapons[i] = -1;
- }
- }
- public Action OnPlayerUse(Handle event, const char[] name, bool dontBroadcast)
- {
- int client = GetClientOfUserId(GetEventInt(event, "userid"));
- if (IsClientIndex(client))
- {
- int weapon = GetPlayerWeaponSlot(client, 1);
- if (IsSecondary(weapon))
- {
- g_PlayerSecondaryWeapons[client] = (weapon == -1 ? weapon : EntIndexToEntRef(weapon));
- }
- }
- return Plugin_Continue;
- }
- public Action OnBotSwap(Handle event, const char[] name, bool dontBroadcast)
- {
- int bot = GetClientOfUserId(GetEventInt(event, "bot"));
- int player = GetClientOfUserId(GetEventInt(event, "player"));
- if (IsClientIndex(bot) && IsClientIndex(player))
- {
- if (StrEqual(name, "player_bot_replace"))
- {
- g_PlayerSecondaryWeapons[bot] = g_PlayerSecondaryWeapons[player];
- g_PlayerSecondaryWeapons[player] = -1;
- }
- else
- {
- g_PlayerSecondaryWeapons[player] = g_PlayerSecondaryWeapons[bot];
- g_PlayerSecondaryWeapons[bot] = -1;
- }
- }
- return Plugin_Continue;
- }
- public Action OnPlayerDeath(Handle event, const char name, bool dontBroadcast)
- {
- int client = GetClientOfUserId(GetEventInt(event, "userid"));
- if (IsSurvivor(client))
- {
- int weapon = EntRefToEntIndex(g_PlayerSecondaryWeapons[client]);
- if (IdentifyWeapon(weapon) != WEPID_NONE && client == GetWeaponOwner(weapon))
- {
- SDKHooks_DropWeapon(client, weapon);
- }
- }
- return Plugin_Continue;
- }
- GetWeaponOwner(weapon)
- {
- return GetEntPropEnt(weapon, Prop_Data, "m_hOwner");
- }
- bool IsClientIndex(client)
- {
- return (client > 0 && client <= MaxClients);
- }
- bool IsSurvivor(client)
- {
- return (IsClientIndex(client) && IsClientInGame(client) && GetClientTeam(client) == 2);
- }
Advertisement
Add Comment
Please, Sign In to add comment