Advertisement
Guest User

Untitled

a guest
Nov 21st, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.19 KB | None | 0 0
  1. #include <sourcemod>
  2. #include <sdktools>
  3. #include <sdkhooks>
  4.  
  5. #pragma semicolon 1
  6. #pragma newdecls required
  7.  
  8. public Plugin myinfo =
  9. {
  10.     name = "Restrictor",
  11.     author = "Tonki_Ton",
  12.     version = "1.0.0",
  13.     url = "https://hlmod.ru/"
  14. }
  15.  
  16. StringMap g_hRestrictedWeapons;
  17.  
  18. public void OnPluginStart()
  19. {
  20.     g_hRestrictedWeapons = new StringMap();
  21.  
  22.     RegAdminCmd("sm_weapon_give", GiveWeapon, ADMFLAG_ROOT);
  23.     RegAdminCmd("sm_weapon_remove", WeaponRemove, ADMFLAG_ROOT);
  24.     RegAdminCmd("sm_weapon_restrict", RestrictWeapon, ADMFLAG_ROOT);
  25.  
  26.     HookEvent("round_start", RS, EventHookMode_PostNoCopy);
  27.  
  28.     for (int i = 1; i <= MaxClients; ++i) if (IsClientInGame(i) && !IsFakeClient(i) && !IsClientSourceTV(i))
  29.         OnClientPutInServer(i);
  30. }
  31.  
  32. public void OnClientPutInServer(int iClient)
  33. {
  34.     SDKHook(iClient, SDKHook_WeaponCanUse, WeaponCanUseCB);
  35. }
  36.  
  37. public Action WeaponCanUseCB(int iClient, int iWeapon)
  38. {
  39.     char sWeapon[32];
  40.     GetWeaponName(iWeapon, sWeapon, sizeof sWeapon);
  41.  
  42.     if (CheckWeaponInSM(iClient, sWeapon))
  43.         return Plugin_Handled;
  44.  
  45.     return Plugin_Continue;
  46. }
  47.  
  48. public void RS(Event hEvent, char[] sName, bool bDontBroadcast)
  49. {
  50.     g_hRestrictedWeapons.Clear();
  51. }
  52.  
  53. public Action GiveWeapon(int iClient, int iArgs)
  54. {
  55.     if (iArgs != 2)
  56.     {
  57.         PrintToChat(iClient, "Указаны не все аргументы");
  58.         return Plugin_Handled;
  59.     }
  60.  
  61.     char sUserId[8], sWeapons[32];
  62.  
  63.     GetCmdArg(1, sUserId, sizeof(sUserId));
  64.     GetCmdArg(2, sWeapons, sizeof(sWeapons));
  65.  
  66.     int iTarget = GetClientOfUserId(StringToInt(sUserId));
  67.  
  68.     if (iTarget < 1 || !IsPlayerAlive(iTarget))
  69.     {
  70.         PrintToChat(iClient, "Невалидный таргет");
  71.         return Plugin_Handled;
  72.     }
  73.  
  74.     if (FindCharInString(sWeapons, '|') == -1)
  75.     {
  76.         Format(sWeapons, sizeof(sWeapons), "weapon_%s", sWeapons);
  77.         GivePlayerItem(iTarget, sWeapons);
  78.     }
  79.     else
  80.     {
  81.         char sExplodedStrings[8][32];
  82.         int iMax = ExplodeString(sWeapons, "|", sExplodedStrings, 8, 32);
  83.  
  84.         for (int i; i < iMax; ++i)
  85.         {
  86.             Format(sWeapons, sizeof(sWeapons), "weapon_%s", sExplodedStrings[i]);
  87.             GivePlayerItem(iTarget, sWeapons);
  88.         }
  89.     }
  90.  
  91.     return Plugin_Handled;
  92. }
  93.  
  94. public Action RestrictWeapon(int iClient, int iArgs)
  95. {
  96.     if (iArgs != 2)
  97.     {
  98.         PrintToChat(iClient, "Указаны не все аргументы");
  99.         return Plugin_Handled;
  100.     }
  101.  
  102.     char sUserId[8], sWeapons[32], sKey[32];
  103.  
  104.     GetCmdArg(1, sUserId, sizeof(sUserId));
  105.     GetCmdArg(2, sWeapons, sizeof(sWeapons));
  106.  
  107.     int iTarget = GetClientOfUserId(StringToInt(sUserId));
  108.  
  109.     PrintToChatAll("Это %N", iTarget);
  110.  
  111.     if (iTarget < 1 || !IsClientInGame(iTarget) || !IsPlayerAlive(iTarget))
  112.     {
  113.         PrintToChat(iClient, "Невалидный таргет");
  114.         return Plugin_Handled;
  115.     }
  116.  
  117.     GetClientAuthId(iTarget, AuthId_Steam2, sKey, sizeof(sKey));
  118.  
  119.     g_hRestrictedWeapons.SetString(sKey, sWeapons);
  120.  
  121.     return Plugin_Handled;
  122. }
  123.  
  124. public Action WeaponRemove(int iClient, int iArgs)
  125. {
  126.     if (iArgs < 2)
  127.     {
  128.         PrintToChat(iClient, "Указаны не все аргументы");
  129.         return Plugin_Handled;
  130.     }
  131.  
  132.     char sUserId[8], sWeapons[32];
  133.  
  134.     GetCmdArg(1, sUserId, sizeof(sUserId));
  135.     GetCmdArg(2, sWeapons, sizeof(sWeapons));
  136.  
  137.     PrintToChatAll("sad %s", sWeapons);
  138.  
  139.     return Plugin_Handled;
  140. }
  141.  
  142. bool CheckWeaponInSM(int iClient, const char[] sBuffer)
  143. {
  144.     char sExplodedStrings[12][32], sWeapon[32], sClientList[128], sKey[32];
  145.  
  146.     GetClientAuthId(iClient, AuthId_Steam2, sKey, sizeof(sKey));
  147.  
  148.     g_hRestrictedWeapons.GetString(sKey, sClientList, sizeof(sClientList));
  149.  
  150.     int iMax = ExplodeString(sClientList, "|", sExplodedStrings, 12, 32);
  151.     for (int i; i < iMax; ++i)
  152.     {
  153.         Format(sWeapon, sizeof(sWeapon), "weapon_%s", sExplodedStrings[i]);
  154.         if (StrEqual(sBuffer, sWeapon))
  155.         {
  156.             return true;
  157.         }
  158.     }
  159.  
  160.     return false;
  161. }
  162.  
  163. void GetWeaponName(int iWeapon, char[] sWeapon, int iLength)
  164. {
  165.     switch (GetEntProp(iWeapon, Prop_Send, "m_iItemDefinitionIndex"))
  166.     {
  167.         case 60: strcopy(sWeapon, iLength, "weapon_m4a1_silencer");
  168.         case 61: strcopy(sWeapon, iLength, "weapon_usp_silencer");
  169.         case 63: strcopy(sWeapon, iLength, "weapon_cz75a");
  170.         case 64: strcopy(sWeapon, iLength, "weapon_revolver");
  171.         default: GetEdictClassname(iWeapon, sWeapon, iLength);
  172.     }
  173. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement