FlacoBey

Untitled

May 31st, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.27 KB | None | 0 0
  1. #pragma semicolon 1
  2.  
  3. #include <sourcemod>
  4. #include <sdktools>
  5. #include <sdkhooks>
  6. #include <l4d2_weapon_stocks>
  7.  
  8. int g_PlayerSecondaryWeapons[MAXPLAYERS + 1];
  9.  
  10. public OnPluginStart()
  11. {
  12.     HookEvent("round_start", vies_as<EventHook>(EventHookOnRoundStart), EventHookMode_PostNoCopy);
  13.     HookEvent("player_use", OnPlayerUse, EventHookMode_Post);
  14.     HookEvent("player_bot_replace", OnBotSwap);
  15.     HookEvent("bot_player_replace", OnBotSwap);
  16.     HookEvent("player_death", OnPlayerDeath, EventHookMode_Pre);
  17. }
  18.  
  19. public OnRoundStart()
  20. {
  21.     for (int i = 0; i <= MAXPLAYERS; i++)
  22.     {
  23.         g_PlayerSecondaryWeapons[i] = -1;
  24.     }
  25. }
  26.  
  27. public Action OnPlayerUse(Handle event, const char[] name, bool dontBroadcast)
  28. {
  29.     int client = GetClientOfUserId(GetEventInt(event, "userid"));
  30.     if (IsClientIndex(client))
  31.     {
  32.         int weapon = GetPlayerWeaponSlot(client, 1);
  33.         if (IsSecondary(weapon))
  34.         {
  35.             g_PlayerSecondaryWeapons[client] = (weapon == -1 ? weapon : EntIndexToEntRef(weapon));
  36.         }
  37.     }
  38.     return Plugin_Continue;
  39. }
  40.  
  41. public Action OnBotSwap(Handle event, const char[] name, bool dontBroadcast)
  42. {
  43.     int bot = GetClientOfUserId(GetEventInt(event, "bot"));
  44.     int player = GetClientOfUserId(GetEventInt(event, "player"));
  45.     if (IsClientIndex(bot) && IsClientIndex(player))
  46.     {
  47.         if (StrEqual(name, "player_bot_replace"))
  48.         {
  49.             g_PlayerSecondaryWeapons[bot] = g_PlayerSecondaryWeapons[player];
  50.             g_PlayerSecondaryWeapons[player] = -1;
  51.         }
  52.         else
  53.         {
  54.             g_PlayerSecondaryWeapons[player] = g_PlayerSecondaryWeapons[bot];
  55.             g_PlayerSecondaryWeapons[bot] = -1;
  56.         }
  57.     }
  58.     return Plugin_Continue;
  59. }
  60.  
  61. public Action OnPlayerDeath(Handle event, const char name, bool dontBroadcast)
  62. {
  63.     int client = GetClientOfUserId(GetEventInt(event, "userid"));
  64.     if (IsSurvivor(client))
  65.     {
  66.         int weapon = EntRefToEntIndex(g_PlayerSecondaryWeapons[client]);
  67.         if (IdentifyWeapon(weapon) != WEPID_NONE && client == GetWeaponOwner(weapon))
  68.         {
  69.             SDKHooks_DropWeapon(client, weapon);
  70.         }
  71.     }
  72.     return Plugin_Continue;
  73. }
  74.  
  75. GetWeaponOwner(weapon)
  76. {
  77.     return GetEntPropEnt(weapon, Prop_Data, "m_hOwner");
  78. }
  79.  
  80. bool IsClientIndex(client)
  81. {
  82.     return (client > 0 && client <= MaxClients);
  83. }
  84.  
  85. bool IsSurvivor(client)
  86. {
  87.     return (IsClientIndex(client) && IsClientInGame(client) && GetClientTeam(client) == 2);
  88. }
Advertisement
Add Comment
Please, Sign In to add comment