mirror of
https://github.com/alliedmodders/amxmodx.git
synced 2024-12-25 06:15:37 +03:00
Removed block from Autobuy and rebuy. Blocked items are stripped from autobuy calls.
This commit is contained in:
parent
aaf8bd7af9
commit
4d01d5625c
@ -334,46 +334,11 @@ new g_Aliases2[MAXMENUPOS][] = {
|
|||||||
"secammo"
|
"secammo"
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
public plugin_init(){
|
|
||||||
register_plugin("Restrict Weapons","0.16","AMXX Dev Team")
|
|
||||||
register_clcmd("buyammo1","ammoRest1")
|
|
||||||
register_clcmd("buyammo2","ammoRest2")
|
|
||||||
#if !defined NO_STEAM
|
#if !defined NO_STEAM
|
||||||
register_clcmd("cl_setautobuy","blockcommand")
|
#define AUTOBUYLENGTH 511
|
||||||
register_clcmd("cl_autobuy","blockcommand")
|
new g_Autobuy[33][AUTOBUYLENGTH + 1]
|
||||||
register_clcmd("cl_setrebuy","blockcommand")
|
//new g_Rebuy[33][AUTOBUYLENGTH + 1]
|
||||||
register_clcmd("cl_rebuy","blockcommand")
|
|
||||||
#endif
|
#endif
|
||||||
register_clcmd("amx_restmenu","cmdMenu",ADMIN_CFG,"- displays weapons restriction menu")
|
|
||||||
register_menucmd(register_menuid("#Buy", 1 ),511,"menuBuy")
|
|
||||||
register_menucmd(register_menuid("\yRestrict Weapons"),1023,"actionMenu")
|
|
||||||
register_menucmd(register_menuid("BuyPistol", 1 ),511,"menuPistol")
|
|
||||||
register_menucmd(register_menuid("BuyShotgun", 1 ),511,"menuShotgun")
|
|
||||||
register_menucmd(register_menuid("BuySub", 1 ),511,"menuSub")
|
|
||||||
register_menucmd(register_menuid("BuyRifle", 1 ),511,"menuRifle")
|
|
||||||
register_menucmd(register_menuid("BuyMachine", 1 ),511,"menuMachine")
|
|
||||||
register_menucmd(register_menuid("BuyItem", 1 ),511,"menuItem")
|
|
||||||
register_menucmd(-28,511,"menuBuy" )
|
|
||||||
register_menucmd(-29,511,"menuPistol" )
|
|
||||||
register_menucmd(-30,511,"menuShotgun")
|
|
||||||
register_menucmd(-32,511,"menuSub")
|
|
||||||
register_menucmd(-31,511,"menuRifle")
|
|
||||||
register_menucmd(-33,511,"menuMachine")
|
|
||||||
register_menucmd(-34,511,"menuItem")
|
|
||||||
register_concmd("amx_restrict","cmdRest",ADMIN_CFG,"- displays help for weapons restriction")
|
|
||||||
|
|
||||||
new configsDir[64];
|
|
||||||
get_configsdir(configsDir, 63);
|
|
||||||
#if defined MAPSETTINGS
|
|
||||||
new mapname[32]
|
|
||||||
get_mapname(mapname,31)
|
|
||||||
format(g_saveFile,63,"%s/weaprest_%s.ini",configsDir,mapname)
|
|
||||||
#else
|
|
||||||
format(g_saveFile,63,"%s/weaprest.ini",configsDir)
|
|
||||||
#endif
|
|
||||||
loadSettings(g_saveFile)
|
|
||||||
}
|
|
||||||
|
|
||||||
setWeapon( a , action ){
|
setWeapon( a , action ){
|
||||||
new b, m = g_Keys[a][0] * 8
|
new b, m = g_Keys[a][0] * 8
|
||||||
@ -571,9 +536,12 @@ public actionMenu(id,key){
|
|||||||
public client_command( id ){
|
public client_command( id ){
|
||||||
if ( g_AliasBlockNum ) {
|
if ( g_AliasBlockNum ) {
|
||||||
new arg[13]
|
new arg[13]
|
||||||
|
|
||||||
if ( read_argv( 0, arg , 12 ) > 11 ) /* Longest buy command has 11 chars so if command is longer then don't care */
|
if ( read_argv( 0, arg , 12 ) > 11 ) /* Longest buy command has 11 chars so if command is longer then don't care */
|
||||||
return PLUGIN_CONTINUE
|
return PLUGIN_CONTINUE
|
||||||
|
|
||||||
new a = 0
|
new a = 0
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if ( equal( g_Aliases[g_AliasBlock[ a ]] , arg ) ||
|
if ( equal( g_Aliases[g_AliasBlock[ a ]] , arg ) ||
|
||||||
equal( g_Aliases2[g_AliasBlock[ a ]] , arg ) ) {
|
equal( g_Aliases2[g_AliasBlock[ a ]] , arg ) ) {
|
||||||
@ -584,6 +552,23 @@ public client_command( id ){
|
|||||||
}
|
}
|
||||||
return PLUGIN_CONTINUE
|
return PLUGIN_CONTINUE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// JGHG: Send weapon string to this function and it returns true if weapon is blocked or false if not blocked...
|
||||||
|
stock WeaponIsBlocked(weapon[]) {
|
||||||
|
for (new a = 0; a < g_AliasBlockNum; a++) {
|
||||||
|
server_print("%d", a)
|
||||||
|
server_print(weapon)
|
||||||
|
server_print(g_Aliases[g_AliasBlock[ a ]])
|
||||||
|
server_print(g_Aliases2[g_AliasBlock[ a ]])
|
||||||
|
|
||||||
|
if ( equal( g_Aliases[g_AliasBlock[ a ]] , weapon ) ||
|
||||||
|
equal( g_Aliases2[g_AliasBlock[ a ]] , weapon ) ) {
|
||||||
|
return true // blocked
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false // not blocked
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined NO_STEAM
|
#if !defined NO_STEAM
|
||||||
@ -646,3 +631,162 @@ loadSettings(filename[]){
|
|||||||
}
|
}
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// JGHG
|
||||||
|
public fn_setautobuy(id) {
|
||||||
|
// Don't do anything if no items are blocked.
|
||||||
|
if (!g_AliasBlockNum)
|
||||||
|
return PLUGIN_CONTINUE
|
||||||
|
|
||||||
|
// Empty user's autobuy prefs. (unnecessary?)
|
||||||
|
g_Autobuy[id][0] = '^0'
|
||||||
|
|
||||||
|
new argCount = read_argc()
|
||||||
|
|
||||||
|
new arg[128]
|
||||||
|
new autobuyLen = 0
|
||||||
|
for (new i = 1; i < argCount; i++) { // Start at parameter 1; parameter 0 is just "cl_setautobuy"
|
||||||
|
read_argv(i, arg, 127)
|
||||||
|
|
||||||
|
// 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 (i + 1 < argCount)
|
||||||
|
autobuyLen += format(g_Autobuy[id][autobuyLen], AUTOBUYLENGTH - autobuyLen, " ")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
|
||||||
|
/*
|
||||||
|
// Check g_Autobuy[id] for blocked items.
|
||||||
|
if (g_AliasBlockNum > 0) {
|
||||||
|
new blockedItem[AUTOBUYLENGTH + 1]
|
||||||
|
if (CheckBlockedItems(g_Autobuy[id], blockedItem)) {
|
||||||
|
client_print(id, print_center, "%c%s is blocked!", blockedItem[0] < 'a' || blockedItem[0] > 'z' ? blockedItem[0] : blockedItem[0] - 32, blockedItem[1]) // Tell what item is blocked (if first char is a letter it will be capital)
|
||||||
|
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(outString, AUTOBUYLENGTH, inString)
|
||||||
|
|
||||||
|
// Then strip those that are blocked.
|
||||||
|
for (new i = 0; i < g_AliasBlockNum; i++) {
|
||||||
|
while (contain(outString, g_Aliases[g_AliasBlock[i]]) != -1)
|
||||||
|
replace(outString, AUTOBUYLENGTH, g_Aliases[g_AliasBlock[i]], "")
|
||||||
|
while (contain(outString, g_Aliases2[g_AliasBlock[i]]) != -1)
|
||||||
|
replace(outString, AUTOBUYLENGTH, g_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
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns true if any of the items in items[] are blocked, else false.
|
||||||
|
stock CheckBlockedItems(items[], blockedItem[AUTOBUYLENGTH + 1]) {
|
||||||
|
if (g_AliasBlockNum <= 0)
|
||||||
|
return false
|
||||||
|
|
||||||
|
new l_items[AUTOBUYLENGTH + 1]
|
||||||
|
format(l_items, AUTOBUYLENGTH, items)
|
||||||
|
|
||||||
|
new aValueWasParsed, parsedItem[128]
|
||||||
|
do {
|
||||||
|
aValueWasParsed = parse(l_items, parsedItem, 127)
|
||||||
|
if (strlen(parsedItem) == 0)
|
||||||
|
return false // no more items
|
||||||
|
|
||||||
|
if (aValueWasParsed) {
|
||||||
|
replace(l_items, AUTOBUYLENGTH, parsedItem, "") // Remove first parameter
|
||||||
|
|
||||||
|
if (WeaponIsBlocked(parsedItem)) {
|
||||||
|
format(blockedItem, AUTOBUYLENGTH, parsedItem)
|
||||||
|
return true // item is blocked, return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
break
|
||||||
|
}
|
||||||
|
while (aValueWasParsed)
|
||||||
|
|
||||||
|
return false // no blocked items found
|
||||||
|
}
|
||||||
|
|
||||||
|
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...
|
||||||
|
|
||||||
|
//server_print("Stripped items: ^"%s^"", strippedItems)
|
||||||
|
engclient_cmd(id, "cl_setautobuy", strippedItems)
|
||||||
|
return PLUGIN_HANDLED
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
public fn_setrebuy(id) {
|
||||||
|
}
|
||||||
|
public fn_rebuy(id) {
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
public plugin_init() {
|
||||||
|
register_plugin("Restrict Weapons","0.16","AMXX Dev Team")
|
||||||
|
register_clcmd("buyammo1","ammoRest1")
|
||||||
|
register_clcmd("buyammo2","ammoRest2")
|
||||||
|
#if !defined NO_STEAM
|
||||||
|
register_clcmd("cl_setautobuy", "fn_setautobuy")
|
||||||
|
register_clcmd("cl_autobuy", "fn_autobuy")
|
||||||
|
//register_clcmd("cl_setrebuy", "fn_setrebuy")
|
||||||
|
//register_clcmd("cl_rebuy", "fn_rebuy")
|
||||||
|
#endif
|
||||||
|
register_clcmd("amx_restmenu","cmdMenu",ADMIN_CFG,"- displays weapons restriction menu")
|
||||||
|
register_menucmd(register_menuid("#Buy", 1 ),511,"menuBuy")
|
||||||
|
register_menucmd(register_menuid("\yRestrict Weapons"),1023,"actionMenu")
|
||||||
|
register_menucmd(register_menuid("BuyPistol", 1 ),511,"menuPistol")
|
||||||
|
register_menucmd(register_menuid("BuyShotgun", 1 ),511,"menuShotgun")
|
||||||
|
register_menucmd(register_menuid("BuySub", 1 ),511,"menuSub")
|
||||||
|
register_menucmd(register_menuid("BuyRifle", 1 ),511,"menuRifle")
|
||||||
|
register_menucmd(register_menuid("BuyMachine", 1 ),511,"menuMachine")
|
||||||
|
register_menucmd(register_menuid("BuyItem", 1 ),511,"menuItem")
|
||||||
|
register_menucmd(-28,511,"menuBuy" )
|
||||||
|
register_menucmd(-29,511,"menuPistol" )
|
||||||
|
register_menucmd(-30,511,"menuShotgun")
|
||||||
|
register_menucmd(-32,511,"menuSub")
|
||||||
|
register_menucmd(-31,511,"menuRifle")
|
||||||
|
register_menucmd(-33,511,"menuMachine")
|
||||||
|
register_menucmd(-34,511,"menuItem")
|
||||||
|
register_concmd("amx_restrict","cmdRest",ADMIN_CFG,"- displays help for weapons restriction")
|
||||||
|
|
||||||
|
new configsDir[64];
|
||||||
|
get_configsdir(configsDir, 63);
|
||||||
|
#if defined MAPSETTINGS
|
||||||
|
new mapname[32]
|
||||||
|
get_mapname(mapname,31)
|
||||||
|
format(g_saveFile,63,"%s/weaprest_%s.ini",configsDir,mapname)
|
||||||
|
#else
|
||||||
|
format(g_saveFile,63,"%s/weaprest.ini",configsDir)
|
||||||
|
#endif
|
||||||
|
loadSettings(g_saveFile)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user