FlacoBey

Untitled

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