Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sourcemod>
- #include <sdktools>
- #include <sdkhooks>
- #pragma semicolon 1
- #pragma newdecls required
- public Plugin myinfo =
- {
- name = "Restrictor",
- author = "Tonki_Ton",
- version = "1.0.0",
- url = "https://hlmod.ru/"
- }
- StringMap g_hRestrictedWeapons;
- public void OnPluginStart()
- {
- g_hRestrictedWeapons = new StringMap();
- RegAdminCmd("sm_weapon_give", GiveWeapon, ADMFLAG_ROOT);
- RegAdminCmd("sm_weapon_remove", WeaponRemove, ADMFLAG_ROOT);
- RegAdminCmd("sm_weapon_restrict", RestrictWeapon, ADMFLAG_ROOT);
- HookEvent("round_start", RS, EventHookMode_PostNoCopy);
- for (int i = 1; i <= MaxClients; ++i) if (IsClientInGame(i) && !IsFakeClient(i) && !IsClientSourceTV(i))
- OnClientPutInServer(i);
- }
- public void OnClientPutInServer(int iClient)
- {
- SDKHook(iClient, SDKHook_WeaponCanUse, WeaponCanUseCB);
- }
- public Action WeaponCanUseCB(int iClient, int iWeapon)
- {
- char sWeapon[32];
- GetWeaponName(iWeapon, sWeapon, sizeof sWeapon);
- if (CheckWeaponInSM(iClient, sWeapon))
- return Plugin_Handled;
- return Plugin_Continue;
- }
- public void RS(Event hEvent, char[] sName, bool bDontBroadcast)
- {
- g_hRestrictedWeapons.Clear();
- }
- public Action GiveWeapon(int iClient, int iArgs)
- {
- if (iArgs != 2)
- {
- PrintToChat(iClient, "Указаны не все аргументы");
- return Plugin_Handled;
- }
- char sUserId[8], sWeapons[32];
- GetCmdArg(1, sUserId, sizeof(sUserId));
- GetCmdArg(2, sWeapons, sizeof(sWeapons));
- int iTarget = GetClientOfUserId(StringToInt(sUserId));
- if (iTarget < 1 || !IsPlayerAlive(iTarget))
- {
- PrintToChat(iClient, "Невалидный таргет");
- return Plugin_Handled;
- }
- if (FindCharInString(sWeapons, '|') == -1)
- {
- Format(sWeapons, sizeof(sWeapons), "weapon_%s", sWeapons);
- GivePlayerItem(iTarget, sWeapons);
- }
- else
- {
- char sExplodedStrings[8][32];
- int iMax = ExplodeString(sWeapons, "|", sExplodedStrings, 8, 32);
- for (int i; i < iMax; ++i)
- {
- Format(sWeapons, sizeof(sWeapons), "weapon_%s", sExplodedStrings[i]);
- GivePlayerItem(iTarget, sWeapons);
- }
- }
- return Plugin_Handled;
- }
- public Action RestrictWeapon(int iClient, int iArgs)
- {
- if (iArgs != 2)
- {
- PrintToChat(iClient, "Указаны не все аргументы");
- return Plugin_Handled;
- }
- char sUserId[8], sWeapons[32], sKey[32];
- GetCmdArg(1, sUserId, sizeof(sUserId));
- GetCmdArg(2, sWeapons, sizeof(sWeapons));
- int iTarget = GetClientOfUserId(StringToInt(sUserId));
- PrintToChatAll("Это %N", iTarget);
- if (iTarget < 1 || !IsClientInGame(iTarget) || !IsPlayerAlive(iTarget))
- {
- PrintToChat(iClient, "Невалидный таргет");
- return Plugin_Handled;
- }
- GetClientAuthId(iTarget, AuthId_Steam2, sKey, sizeof(sKey));
- g_hRestrictedWeapons.SetString(sKey, sWeapons);
- return Plugin_Handled;
- }
- public Action WeaponRemove(int iClient, int iArgs)
- {
- if (iArgs < 2)
- {
- PrintToChat(iClient, "Указаны не все аргументы");
- return Plugin_Handled;
- }
- char sUserId[8], sWeapons[32];
- GetCmdArg(1, sUserId, sizeof(sUserId));
- GetCmdArg(2, sWeapons, sizeof(sWeapons));
- PrintToChatAll("sad %s", sWeapons);
- return Plugin_Handled;
- }
- bool CheckWeaponInSM(int iClient, const char[] sBuffer)
- {
- char sExplodedStrings[12][32], sWeapon[32], sClientList[128], sKey[32];
- GetClientAuthId(iClient, AuthId_Steam2, sKey, sizeof(sKey));
- g_hRestrictedWeapons.GetString(sKey, sClientList, sizeof(sClientList));
- int iMax = ExplodeString(sClientList, "|", sExplodedStrings, 12, 32);
- for (int i; i < iMax; ++i)
- {
- Format(sWeapon, sizeof(sWeapon), "weapon_%s", sExplodedStrings[i]);
- if (StrEqual(sBuffer, sWeapon))
- {
- return true;
- }
- }
- return false;
- }
- void GetWeaponName(int iWeapon, char[] sWeapon, int iLength)
- {
- switch (GetEntProp(iWeapon, Prop_Send, "m_iItemDefinitionIndex"))
- {
- case 60: strcopy(sWeapon, iLength, "weapon_m4a1_silencer");
- case 61: strcopy(sWeapon, iLength, "weapon_usp_silencer");
- case 63: strcopy(sWeapon, iLength, "weapon_cz75a");
- case 64: strcopy(sWeapon, iLength, "weapon_revolver");
- default: GetEdictClassname(iWeapon, sWeapon, iLength);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement