Raised This Month: $51 Target: $400
 12% 

Restrict weapons


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
El Abuelo Loco
Senior Member
Join Date: Jun 2020
Old 01-02-2021 , 04:47   Restrict weapons
Reply With Quote #1

hello I have this plugin to restrict weapons, the thing that I would like to make it work with ADMIN_LEVEL_

change the ADMIN_KICK to ADMIN_LEVEL_C and it doesn't work.

PHP Code:
/* AMX Mod X
*   Restrict Weapons Plugin
*
* by the AMX Mod X Development Team
*  originally developed by OLO
*
* This file is part of AMX Mod X.
*
*
*  This program is free software; you can redistribute it and/or modify it
*  under the terms of the GNU General Public License as published by the
*  Free Software Foundation; either version 2 of the License, or (at
*  your option) any later version.
*
*  This program is distributed in the hope that it will be useful, but
*  WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
*  General Public License for more details.
*
*  You should have received a copy of the GNU General Public License
*  along with this program; if not, write to the Free Software Foundation, 
*  Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*  In addition, as a special exception, the author gives permission to
*  link the code of this program with the Half-Life Game Engine ("HL
*  Engine") and Modified Game Libraries ("MODs") developed by Valve, 
*  L.L.C ("Valve"). You must obey the GNU General Public License in all
*  respects for all of the code used other than the HL Engine and MODs
*  from Valve. If you modify this file, you may extend this exception
*  to your version of the file, but you are not obligated to do so. If
*  you do not wish to do so, delete this exception statement from your
*  version.
*/

// Uncomment if you want to have seperate settings for each map
//#define MAPSETTINGS

#include <amxmodx>
#include <amxmisc>

#define MAXMENUPOS 34

new g_Position[33]
new 
g_Modified
new g_blockPos[112]
new 
g_saveFile[64]
new 
g_Restricted[] = "*Esta arma esta restringida.*"
new g_szWeapRestr[27] = "00000000000000000000000000"
new g_szEquipAmmoRestr[10] = "000000000"
new g_InBuyMenu[33]
new 
g_RegisteredMenus[10]

new 
g_menuStrings[6][] =
{
    
"BuyPistol",
    
"BuyShotgun",
    
"BuySubMachineGun",
    
"BuyRifle",
    
"BuyMachineGun",
    
"BuyItem"
}

new 
g_menusNames[7][] =
{
    
"pistol"
    
"shotgun"
    
"sub"
    
"rifle"
    
"machine"
    
"equip"
    
"ammo"
}

new 
g_MenuTitle[7][] =
{
    
"Handguns"
    
"Shotguns"
    
"Sub-Machine Guns"
    
"Assault & Sniper Rifles"
    
"Machine Guns"
    
"Equipment"
    
"Ammunition"
}

new 
g_menusSets[7][2] =
{
    {
06}, {68}, {813}, {1323}, {2324}, {2432}, {3234}
}

new 
g_AliasBlockNum
new g_AliasBlock[MAXMENUPOS]

// First position is a position of menu (0 for ammo, 1 for pistols, 6 for equipment etc.)
// Second is a key for TERRORIST (all is key are minus one, 1 is 0, 2 is 1 etc.)
// Third is a key for CT
// Position with -1 doesn't exist

new g_Keys[MAXMENUPOS][3] =
{
    {
111},    // H&K USP .45 Tactical
    
{100},    // Glock18 Select Fire
    
{133},    // Desert Eagle .50AE
    
{122},    // SIG P228
    
{14, -1}, // Dual Beretta 96G Elite
    
{1, -14}, // FN Five-Seven
    
{200},    // Benelli M3 Super90
    
{211},    // Benelli XM1014
    
{311},    // H&K MP5-Navy
    
{3, -10}, // Steyr Tactical Machine Pistol
    
{333},    // FN P90
    
{30, -1}, // Ingram MAC-10
    
{322},    // H&K UMP45
    
{41, -1}, // AK-47
    
{40, -1}, // Gali
    
{4, -10}, // Famas
    
{43, -1}, // Sig SG-552 Commando
    
{4, -12}, // Colt M4A1 Carbine
    
{4, -13}, // Steyr Aug
    
{421},    // Steyr Scout
    
{445},    // AI Arctic Warfare/Magnum
    
{45, -1}, // H&K G3/SG-1 Sniper Rifle
    
{4, -14}, // Sig SG-550 Sniper
    
{500},    // FN M249 Para
    
{600},    // Kevlar Vest
    
{611},    // Kevlar Vest & Helmet
    
{622},    // Flashbang
    
{633},    // HE Grenade
    
{644},    // Smoke Grenade
    
{6, -16}, // Defuse Kit
    
{655},    // NightVision Goggles
    
{6, -17},    // Tactical Shield
    
{055},    // Primary weapon ammo
    
{066}    // Secondary weapon ammo
}

new 
g_WeaponNames[MAXMENUPOS][] =
{
    
"H&K USP .45 Tactical"
    
"Glock18 Select Fire"
    
"Desert Eagle .50AE"
    
"SIG P228"
    
"Dual Beretta 96G Elite"
    
"FN Five-Seven"
    
"Benelli M3 Super90"
    
"Benelli XM1014"
    
"H&K MP5-Navy"
    
"Steyr Tactical Machine Pistol"
    
"FN P90"
    
"Ingram MAC-10"
    
"H&K UMP45"
    
"AK-47"
    
"Gali"
    
"Famas"
    
"Sig SG-552 Commando"
    
"Colt M4A1 Carbine"
    
"Steyr Aug"
    
"Steyr Scout"
    
"AI Arctic Warfare/Magnum"
    
"H&K G3/SG-1 Sniper Rifle"
    
"Sig SG-550 Sniper"
    
"FN M249 Para"
    
"Kevlar Vest"
    
"Kevlar Vest & Helmet"
    
"Flashbang"
    
"HE Grenade"
    
"Smoke Grenade"
    
"Defuse Kit"
    
"NightVision Goggles"
    
"Tactical Shield"
    
"Primary weapon ammo"
    
"Secondary weapon ammo"
}

new 
g_MenuItem[MAXMENUPOS][] =
{
    
"\yHandguns^n\w^n%d. %s\y\R%L^n\w"
    
"%d. %s\y\R%L^n\w"
    
"%d. %s\y\R%L^n\w"
    
"%d. %s\y\R%L^n\w"
    
"%d. %s\y\R%L^n\w"
    
"%d. %s\y\R%L^n\w^n"

    
"\yShotguns^n\w^n%d. %s\y\R%L^n\w"
    
"%d. %s\y\R%L^n\w^n"

    
"\ySub-Machine Guns^n\w^n%d. %s\y\R%L^n\w"
    
"%d. %s\y\R%L^n\w"
    
"%d. %s\y\R%L^n\w"
    
"%d. %s\y\R%L^n\w"
    
"%d. %s\y\R%L^n\w^n"

    
"\yAssault Rifles^n\w^n%d. %s\y\R%L^n\w"
    
"%d. %s\y\R%L^n\w"
    
"%d. %s\y\R%L^n\w"
    
"%d. %s\y\R%L^n\w"
    
"%d. %s\y\R%L^n\w"
    
"%d. %s\y\R%L^n\w^n"

    
"\ySniper Rifles^n\w^n%d. %s\y\R%L^n\w"
    
"%d. %s\y\R%L^n\w"
    
"%d. %s\y\R%L^n\w"
    
"%d. %s\y\R%L^n\w^n"

    
"\yMachine Guns^n\w^n%d. %s\y\R%L^n\w^n"

    
"\yEquipment^n\w^n%d. %s\y\R%L^n\w"
    
"%d. %s\y\R%L^n\w"
    
"%d. %s\y\R%L^n\w"
    
"%d. %s\y\R%L^n\w"
    
"%d. %s\y\R%L^n\w"
    
"%d. %s\y\R%L^n\w"
    
"%d. %s\y\R%L^n\w"
    
"%d. %s\y\R%L^n\w^n"

    
"\yAmmunition^n\w^n%d. %s\y\R%L^n\w"
    
"%d. %s\y\R%L^n\w"
}

new 
g_Aliases[MAXMENUPOS][] =
{
    
"usp",        //Pistols
    
"glock"
    
"deagle"
    
"p228"
    
"elites"
    
"fn57"

    
"m3",        //Shotguns
    
"xm1014"

    
"mp5",        //SMG
    
"tmp"
    
"p90"
    
"mac10"
    
"ump45"

    
"ak47",        //Rifles
    
"galil"
    
"famas"
    
"sg552"
    
"m4a1"
    
"aug"
    
"scout"
    
"awp"
    
"g3sg1"
    
"sg550"

    
"m249",        //Machine Gun

    
"vest",        //Equipment
    
"vesthelm"
    
"flash"
    
"hegren"
    
"sgren"
    
"defuser"
    
"nvgs"
    
"shield"

    
"primammo"//Ammo
    
"secammo"
}

new 
g_Aliases2[MAXMENUPOS][] =
{
    
"km45",        //Pistols
    
"9x19mm"
    
"nighthawk"
    
"228compact"
    
"elites"
    
"fiveseven"

    
"12gauge",    //Shotguns
    
"autoshotgun"

    
"smg",        //SMG
    
"mp"
    
"c90"
    
"mac10"
    
"ump45"

    
"cv47",        //Rifles
    
"defender"
    
"clarion"
    
"krieg552"
    
"m4a1"
    
"bullpup"
    
"scout"
    
"magnum"
    
"d3au1"
    
"krieg550"

    
"m249",        //Machine Gun

    
"vest",        //Equipment
    
"vesthelm"
    
"flash"
    
"hegren"
    
"sgren"
    
"defuser"
    
"nvgs"
    
"shield"
    
"primammo"//Ammo
    
"secammo"
}

#define AUTOBUYLENGTH 511
new g_Autobuy[33][AUTOBUYLENGTH 1]
//new g_Rebuy[33][AUTOBUYLENGTH + 1]

bool:IsOurMenuID(id)
{
    for (new 
i=1i<=g_RegisteredMenus[0]; i++)
    {
        if (
g_RegisteredMenus[i] == id)
        {
            return 
true
        
}
    }
    
    return 
false
}

setWeapon(aaction)
{
    new 
bg_Keys[a][0] * 8
    
    
if (g_Keys[a][1] != -1)
    {
        
g_Keys[a][1]
        
        if (
action == 2)
            
g_blockPos[b] = g_blockPos[b]
        else
            
g_blockPos[b] = action
    
}

    if (
g_Keys[a][2] != -1)
    {
        
g_Keys[a][2] + 56
        
        
if (action == 2)
            
g_blockPos[b] = g_blockPos[b]
        else
            
g_blockPos[b] = action
    
}

    for (new 
0g_AliasBlockNum; ++i)
        if (
g_AliasBlock[i] == a)
        {
            if (!
action || action == 2)
            {
                --
g_AliasBlockNum
                
                
for (new ig_AliasBlockNum; ++j)
                    
g_AliasBlock[j] = g_AliasBlock[1]
            }
            
            return
        }

    if (
action && g_AliasBlockNum MAXMENUPOS)
        
g_AliasBlock[g_AliasBlockNum++] = a
}

findMenuId(name[])
{
    for (new 
0; ++i)
        if (
equali(nameg_menusNames[i]))
            return 
i
    
    
return -1
}

findAliasId(name[])
{
    for (new 
0MAXMENUPOS ; ++i)
        if (
equali(nameg_Aliases[i]))
            return 
i
    
    
return -1
}

switchCommand(idaction)
{
    new 
read_argc()

    if (
3)
    {
        for (new 
0MAXMENUPOSx++)
            
setWeapon(xaction)        

        
console_print(id"%L"idaction "EQ_WE_RES" "EQ_WE_UNRES")
        
g_Modified true
    
} else {
        new 
arg[32], a
        
new bool:found false
        
        
for (new 2c; ++b)
        {
            
read_argv(barg31)
            
            if ((
findMenuId(arg)) != -1)
            {
                
g_menusSets[a][1]
                
                for (new 
g_menusSets[a][0]; c; ++i)
                    
setWeapon(iaction)
                
                
console_print(id"%s %L %L"g_MenuTitle[a], id, (5) ? "HAVE_BEEN" "HAS_BEEN"idaction "RESTRICTED" "UNRESTRICTED")
                
g_Modified found true
            
}
            else if ((
findAliasId(arg)) != -1)
            {
                
g_Modified found true
                setWeapon
(aaction)
                
console_print(id"%s %L %L"g_WeaponNames[a], id"HAS_BEEN"idaction "RESTRICTED" "UNRESTRICTED")
            }
        }

        if (!
found)
            
console_print(id"%L"id"NO_EQ_WE")
    }
}

positionBlocked(a)
{
    new 
g_Keys[a][0] * 8
    
new = (g_Keys[a][1] == -1) ? g_blockPos[g_Keys[a][1]]
    
    
+= (g_Keys[a][2] == -1) ? g_blockPos[g_Keys[a][2] + 56]
    
    return 
d
}

public 
cmdRest(idlevelcid)
{
    if (!
cmd_access(idlevelcid1))
        return 
PLUGIN_HANDLED

    
new cmd[8]
    
    
read_argv(1cmd7)
    
    if (
equali("on"cmd))
        
switchCommand(id1)
    else if (
equali("off"cmd))
        
switchCommand(id0)
    else if (
equali("list"cmd))
    {
        new 
arg1[8]
        new    
start read_argv(2arg17) ? str_to_num(arg1) : 1
        
        
if (--start 0)
            
start 0
        
        
if (start >= MAXMENUPOS)
            
start MAXMENUPOS 1
        
        
new end start 10
        
        
if (end MAXMENUPOS)
            
end MAXMENUPOS
        
        
new lName[16], lValue[16], lStatus[16], lOnOff[16]
        
        
format(lName15"%L"id"NAME")
        
format(lValue15"%L"id"VALUE")
        
format(lStatus15"%L"id"STATUS")
        
        
console_print(id"^n----- %L: -----"id"WEAP_RES")
        
console_print(id"     %-32.31s   %-10.9s   %-9.8s"lNamelValuelStatus)
        
        if (
start != -1)
        {
            for (new 
startend; ++a)
            {
                
format(lOnOff15"%L"idpositionBlocked(a) ? "ON" "OFF")
                
console_print(id"%3d: %-32.31s   %-10.9s   %-9.8s"1g_WeaponNames[a], g_Aliases[a], lOnOff)
            }
        }
        
        
console_print(id"----- %L -----"id"REST_ENTRIES_OF"start 1endMAXMENUPOS)
        
        if (
end MAXMENUPOS)
            
console_print(id"----- %L -----"id"REST_USE_MORE"end 1)
        else
            
console_print(id"----- %L -----"id"REST_USE_BEGIN")
    }
    else if (
equali("save"cmd))
    {
        if (
saveSettings(g_saveFile))
        {
            
console_print(id"%L"id"REST_CONF_SAVED"g_saveFile)
            
g_Modified false
        
}
        else
            
console_print(id"%L"id"REST_COULDNT_SAVE"g_saveFile)
    }
    else if (
equali("load"cmd))
    {
        
setc(g_blockPos1120)    // Clear current settings
        
new arg1[64]

        if (
read_argv(2arg163))
        {
            new 
configsdir[32]
            
get_configsdir(configsdir31)

            
format(arg163"%s/%s"configsdirarg1)
        }
        
        if (
loadSettings(arg1))
        {
            
console_print(id"%L"id"REST_CONF_LOADED"arg1)
            
g_Modified true
        
}
        else
            
console_print(id"%L"id"REST_COULDNT_LOAD"arg1)
    } else {
        
console_print(id"%L"id"COM_REST_USAGE")
        
console_print(id"%L"id"COM_REST_COMMANDS")
        
console_print(id"%L"id"COM_REST_ON")
        
console_print(id"%L"id"COM_REST_OFF")
        
console_print(id"%L"id"COM_REST_ONV")
        
console_print(id"%L"id"COM_REST_OFFV")
        
console_print(id"%L"id"COM_REST_LIST")
        
console_print(id"%L"id"COM_REST_SAVE")
        
console_print(id"%L"id"COM_REST_LOAD")
        
console_print(id"%L"id"COM_REST_VALUES")
        
console_print(id"%L"id"COM_REST_TYPE")
    }

    return 
PLUGIN_HANDLED
}

displayMenu(idpos)
{
    if (
pos 0)
        return

    new 
menubody[512], start pos 7

    
if (start >= MAXMENUPOS)
        
start pos g_Position[id] = 0

    
new len format(menubody511"\y%L\R%d/5^n^n\w"id"REST_WEAP"pos 1)
    new 
end start 7keys MENU_KEY_0|MENU_KEY_80

    
if (end MAXMENUPOS)
        
end MAXMENUPOS

    
for (new startend; ++a)
    {
        
keys |= (1<<k)
        
len += format(menubody[len], 511 leng_MenuItem[a], ++kg_WeaponNames[a], idpositionBlocked(a) ? "ON" "OFF")
    }

    
len += format(menubody[len], 511 len"^n8. %L \y\R%s^n\w"id"SAVE_SET"g_Modified "*" "")

    if (
end != MAXMENUPOS)
    {
        
format(menubody[len], 511-len"^n9. %L...^n0. %L"id"MORE"idpos "BACK" "EXIT")
        
keys |= MENU_KEY_9
    
}
    else
        
format(menubody[len], 511-len"^n0. %L"idpos "BACK" "EXIT")

    
show_menu(idkeysmenubody, -1"Restrict Weapons")
}

public 
actionMenu(idkey)
{
    switch (
key)
    {
        case 
7:
        {
            if (
saveSettings(g_saveFile))
            {
                
g_Modified false
                client_print
(idprint_chat"* %L"id"CONF_SAV_SUC")
            }
            else
                
client_print(idprint_chat"* %L"id"CONF_SAV_FAIL")

            
displayMenu(idg_Position[id])
        }
        case 
8displayMenu(id, ++g_Position[id])
        case 
9displayMenu(id, --g_Position[id])
        default:
        {
            
setWeapon(g_Position[id] * key2)
            
g_Modified true
            displayMenu
(idg_Position[id])

            new 
g_Position[id] * key
            
new sz[1]

            if (
24)
            {
                
sz[0] = g_szWeapRestr[1]
                
g_szWeapRestr[1] = (sz[0] == '0') ? '1' '0'  // primary and secondary weapons
            
}
            else if ((
>= 24) && (31))
            {
                
sz[0] = g_szEquipAmmoRestr[24]
                
g_szEquipAmmoRestr[24] = (sz[0] == '0') ? '1' '0'  // equipments
            
}
            else if (
== 31)
            {
                
sz[0] = g_szWeapRestr[25]
                
g_szWeapRestr[25] = (sz[0] == '0') ? '1' '0'  // shield
            
}
            else if ((
31) && (34))
            {
                
sz[0] = g_szEquipAmmoRestr[25]
                
g_szEquipAmmoRestr[25] = (sz[0] == '0') ? '1' '0'   // primary and secondary ammo
            
}
            
set_cvar_string("amx_restrweapons"g_szWeapRestr)
            
set_cvar_string("amx_restrequipammo"g_szEquipAmmoRestr)
        }
    }

    return 
PLUGIN_HANDLED
}

public 
CS_InternalCommand(id, const cmd[])
{
    new 
0

    
do
    {
        if (
equali(g_Aliases[g_AliasBlock[a]], cmd) || equali(g_Aliases2[g_AliasBlock[a]], cmd))
        {
            
client_print(idprint_center"%s"g_Restricted)
            return 
PLUGIN_HANDLED
        
}
    } while (++
g_AliasBlockNum)
    
    return 
PLUGIN_CONTINUE
}

public 
client_command(id)
{
    if (
g_AliasBlockNum)
    {
        new 
arg[13]

        if (
read_argv(0arg12) > 11)        /* Longest buy command has 11 chars so if command is longer then don't care */
        
{
            return 
PLUGIN_CONTINUE
        
}
        
        if (
equali(arg"menuselect") && is_user_connected(id))
        {
            new 
menunewmenu
            
new inMenu player_menu_info(idmenunewmenu)
            
            if (!
inMenu && g_InBuyMenu[id])
            {
                new 
key[12], num
                
                read_argv
(1key11)
                
num str_to_num(key) - 1
                
                
return checkRest(idg_InBuyMenu[id], num)
            } else if ((!
menu || newmenu != -1
                     || !
IsOurMenuID(menu)) {
                
g_InBuyMenu[id] = 0
            
}

            return 
PLUGIN_CONTINUE
        
}

        new 
0

        
do
        {
            if (
equali(g_Aliases[g_AliasBlock[a]], arg) || equali(g_Aliases2[g_AliasBlock[a]], arg))
            {
                
client_print(idprint_center"%s"g_Restricted)
                return 
PLUGIN_HANDLED
            
}
        } while (++
g_AliasBlockNum)
    }
    
    return 
PLUGIN_CONTINUE
}

public 
blockcommand(id)
{
    
client_print(idprint_center"%s"g_Restricted)
    return 
PLUGIN_HANDLED
}

public 
cmdMenu(idlevelcid)
{
    if (
cmd_access(idlevelcid1))
    {
        
displayMenu(idg_Position[id] = 0)
    }
    
    return 
PLUGIN_HANDLED
}

checkRest(idmenukey)
{
    new 
team get_user_team(id)
    
    if (
team != && team != 2)
    {
        return 
PLUGIN_HANDLED
    
}
        
    new 
pos = (menu key) + (get_user_team(id) - 1) * 56
    
    
if (pos || pos >= 112)
    {
        return 
PLUGIN_CONTINUE
    
}
    
    if (
g_blockPos[pos])
    {
        
engclient_cmd(id"menuselect""10")
        
client_print(idprint_center"%s"g_Restricted)
        
        return 
PLUGIN_HANDLED
    
}
    
    return 
PLUGIN_CONTINUE
}

public 
ammoRest1(id)        return checkRest(id05)
public 
ammoRest2(id)        return checkRest(id06)
public 
menuBuy(idkey)     return checkRest(id0key)
public 
menuPistol(idkey)  return checkRest(id1key)
public 
menuShotgun(idkey) return checkRest(id2key)
public 
menuSub(idkey)     return checkRest(id3key)
public 
menuRifle(idkey)   return checkRest(id4key)
public 
menuMachine(idkey) return checkRest(id5key)
public 
menuItem(idkey)    return checkRest(id6key)

saveSettings(filename[])
{
    if (
file_exists(filename))
        
delete_file(filename)

    if (!
write_file(filename"; Generated by Restrict Weapons Plugin. Do not modify!^n; value name"))
        return 
0

    
new text[64]

    for (new 
0MAXMENUPOS; ++a)
    {
        if (
positionBlocked(a))
        {
            
format(text63"%-16.15s ; %s"g_Aliases[a], g_WeaponNames[a])
            
write_file(filenametext)
        }
    }

    return 
1
}

loadSettings(filename[])
{
    if (!
file_exists(filename))
        return 
0

    
new text[16]
    new 
apos 0

    format
(g_szEquipAmmoRestr9"000000000")
    
format(g_szWeapRestr26"00000000000000000000000000")

    while (
read_file(filenamepos++, text15a))
    {
        if (
text[0] == ';' || !a)
            continue    
// line is a comment
        
        
parse(texttext15)
        
        if ((
findAliasId(text)) != -1)
        {
            
setWeapon(a1)
            if (
24g_szWeapRestr[1] = '1' // primary and secondary weapons
            
else if ((>= 24) && (31)) g_szEquipAmmoRestr[24] = '1'  // equipments
            
else if (== 31g_szWeapRestr[25] = '1'  // shield
            
else if ((31) && (34)) g_szEquipAmmoRestr[25] = '1'  // primary and secondary ammo
        
}
    }
    
set_cvar_string("amx_restrweapons"g_szWeapRestr)
    
set_cvar_string("amx_restrequipammo"g_szEquipAmmoRestr)

    return 
1
}

// JGHG
public fn_setautobuy(id)
{
    
// Empty user's autobuy prefs. (unnecessary?)
    
g_Autobuy[id][0] = '^0'

    
new argCount read_argc()
    new 
arg[128]
    new 
autobuyLen 0
    
    
for (new 1argCounti++)        // Start at parameter 1; parameter 0 is just "cl_setautobuy"
    
{
        
read_argv(iarg127)
        
// Add this parameter to user's autobuy prefs
        
autobuyLen += format(g_Autobuy[id][autobuyLen], AUTOBUYLENGTH autobuyLen"%s"arg)
        
        
// If we detect more parameters, add a space
        
if (argCount)
            
autobuyLen += format(g_Autobuy[id][autobuyLen], AUTOBUYLENGTH autobuyLen" ")
    }

    if (
g_AliasBlockNum)
    {
        
// Strip any blocked items
        
new strippedItems[AUTOBUYLENGTH 1]
    
        if (!
StripBlockedItems(g_Autobuy[id], strippedItems))
            return 
PLUGIN_CONTINUE                // don't touch anything if we didn't strip anything...

        //server_print("Stripped items: ^"%s^"", strippedItems)
        
engclient_cmd(id"cl_setautobuy"strippedItems)

        return 
PLUGIN_HANDLED
    
}
    
    return 
PLUGIN_CONTINUE
}

// Returns true if this strips any items, else false.
StripBlockedItems(inString[AUTOBUYLENGTH 1], outString[AUTOBUYLENGTH 1])
{
    
// First copy string
    
format(outStringAUTOBUYLENGTHinString)

    
// After that convert all chars in string to lower case (fix by VEN)
    
strtolower(outString)

    
// Then strip those that are blocked.
    
for (new 0g_AliasBlockNumi++)
    {
        while (
containi(outStringg_Aliases[g_AliasBlock[i]]) != -1)
            
replace(outStringAUTOBUYLENGTHg_Aliases[g_AliasBlock[i]], "")
        while (
containi(outStringg_Aliases2[g_AliasBlock[i]]) != -1)
            
replace(outStringAUTOBUYLENGTHg_Aliases2[g_AliasBlock[i]], "")
    }

    
// We COULD trim white space from outString here, but I don't think it really is necessary currently...
    
if (strlen(outString) < strlen(inString))
        return 
true                            // outstring is shorter: we stripped items, return true

    
return false                            // else end here, return false, no items were stripped
}

public 
fn_autobuy(id)
{
    
// Don't do anything if no items are blocked.
    
if (!g_AliasBlockNum)
        return 
PLUGIN_CONTINUE

    
// Strip any blocked items
    
new strippedItems[AUTOBUYLENGTH 1]
    
    if (!
StripBlockedItems(g_Autobuy[id], strippedItems))
        return 
PLUGIN_CONTINUE                // don't touch anything if we didn't strip anything...

    
engclient_cmd(id"cl_setautobuy"strippedItems)
    
    return 
PLUGIN_HANDLED
}

public 
HookEvent_ShowMenu(id)
{
    new 
menustring[24]
    
    
read_data(4menustring23)
    
    
/* Early breakouts */
    
new curidx
    
if (menustring[curidx++] != '#')
    {
        
g_InBuyMenu[id] = 0
        
return
    }
    
    
/* Strip D */
    
if (menustring[curidx] == 'D')
    {
        
curidx++
    }
    
    
/* Strip AS_ */
    
if (menustring[curidx] == 'A'
        
&& menustring[curidx+1] == 'S'
        
&& menustring[curidx+2] == '_')
    {
        
curidx += 3
    
}
    
    
/* Strip any team tags */
    
if (menustring[curidx] == 'C'
        
&& menustring[curidx+1] == 'T'
        
&& menustring[curidx+2] == '_')
    {
        
curidx += 3
    
} else if (menustring[curidx] == 'T'
             
&& menustring[curidx+1] == '_') {
        
curidx += 2
    
}
    
    if (
menustring[curidx] != 'B')
    {
        
g_InBuyMenu[id] = 0
        
return
    }
    
    for (new 
i=0i<6i++)
    {
        if (
equali(menustring[curidx], g_menuStrings[i]))
        {
            
g_InBuyMenu[id] = i+1
            
return
        }
    }
    
    
g_InBuyMenu[id] = 0
}

RegisterMenuID(const menuname[])
{
    new 
id register_menuid(menuname1)
    
g_RegisteredMenus[++g_RegisteredMenus[0]] = id
    
return id
}

public 
plugin_init()
{
    
register_plugin("Restrict Weapons"AMXX_VERSION_STR"www.4evergaming.com.ar")
    
register_dictionary("restmenu.txt")
    
register_dictionary("common.txt")
    
register_clcmd("buyammo1""ammoRest1")
    
register_clcmd("buyammo2""ammoRest2")
    
register_clcmd("cl_setautobuy""fn_setautobuy")
    
register_clcmd("cl_autobuy""fn_autobuy")
    
register_clcmd("amx_restmenu""cmdMenu"ADMIN_KICK"- displays weapons restriction menu")
    
register_menucmd(register_menuid("#Buy"1), 511"menuBuy")
    
register_menucmd(register_menuid("Restrict Weapons"), 1023"actionMenu")
    
register_menucmd(RegisterMenuID("BuyPistol"), 511"menuPistol")
    
register_menucmd(RegisterMenuID("BuyShotgun"), 511"menuShotgun")
    
register_menucmd(RegisterMenuID("BuySub"), 511"menuSub")
    
register_menucmd(RegisterMenuID("BuyRifle"), 511"menuRifle")
    
register_menucmd(RegisterMenuID("BuyMachine"), 511"menuMachine")
    
register_menucmd(RegisterMenuID("BuyItem"), 511"menuItem")
    
register_menucmd(-28511"menuBuy")
    
register_menucmd(-29511"menuPistol")
    
register_menucmd(-30511"menuShotgun")
    
register_menucmd(-32511"menuSub")
    
register_menucmd(-31511"menuRifle")
    
register_menucmd(-33511"menuMachine")
    
register_menucmd(-34511"menuItem")
    
register_concmd("amx_restrict""cmdRest"ADMIN_KICK"- displays help for weapons restriction")

    
register_cvar("amx_restrweapons""00000000000000000000000000")
    
register_cvar("amx_restrequipammo""000000000")
    
    
register_event("ShowMenu""HookEvent_ShowMenu""b")

    new 
configsDir[64];
    
get_configsdir(configsDir63);
#if defined MAPSETTINGS
    
new mapname[32]
    
get_mapname(mapname31)
    
format(g_saveFile63"%s/weaprest_%s.ini"configsDirmapname)
#else
    
format(g_saveFile63"%s/weaprest.ini"configsDir)
#endif
    
loadSettings(g_saveFile)
}
public 
plugin_cfg()
{
    if(
is_plugin_loaded("Pause Plugins") > -1)
        
server_cmd("amx_pausecfg add ^"Restrict Weapons^"");

El Abuelo Loco is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 01-02-2021 , 07:31   Re: Restrict weapons
Reply With Quote #2

configs/cmdaccess.ini
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 06:39.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode