Facebook
From orange, 5 Years ago, written in C++.
This paste is a reply to Untitled from Mustard Cat - view diff
Embed
Download Paste or View Raw
Hits: 428
  1. #include <sourcemod>
  2. #include <sdkhooks>
  3.  
  4. #pragma semicolon 1
  5. #pragma newdecls required
  6.  
  7. char g_sWeaponsCanUse [][] =
  8. {
  9.         "weapon_knife",
  10.         "weapon_decoy",
  11.         "weapon_flashbang",
  12.         "weapon_hegrenade",
  13.         "weapon_smokegrenade",
  14.         "weapon_molotov",
  15.         "weapon_incgrenade",
  16.         "weapon_awp"
  17. };
  18.  
  19. public void OnPluginStart()
  20. {
  21.         for(int i = 1; i <= MaxClients; i++)
  22.                 if(IsValidClient(i))
  23.                         OnClientPutInServer(i);
  24. }
  25.  
  26. public void OnClientPutInServer(int client)
  27. {
  28.         SDKHook(client, SDKHook_WeaponCanUse, WeaponCanUse);
  29. }
  30.  
  31. public void OnClientDisconnect(int client)
  32. {
  33.         SDKUnhook(client, SDKHook_WeaponCanUse, WeaponCanUse);
  34. }
  35.  
  36. public Action WeaponCanUse(int client, int weapon)
  37. {
  38.         if(!IsValidClient(client) || !IsPlayerAlive(client))
  39.                 return Plugin_Continue;
  40.  
  41.         char weapons[32];
  42.         GetEdictClassname(weapon, weapons, sizeof(weapons));
  43.        
  44.         for(int i = 0; i < sizeof(g_sWeaponsCanUse); i ++)
  45.         {
  46.                 if(StrEqual(g_sWeaponsCanUse[i], weapons))
  47.                         return Plugin_Continue;
  48.         }
  49.        
  50.         return Plugin_Handled;
  51. }
  52.  
  53. stock bool IsValidClient(int client)
  54. {
  55.         if(client <= 0 ) return false;
  56.         if(client > MaxClients) return false;
  57.         if(!IsClientConnected(client)) return false;
  58.         if(IsFakeClient(client)) return false;
  59.         return IsClientInGame(client);
  60. }