From 4f7e711af55b69208ce25fcfbb531078becb016b Mon Sep 17 00:00:00 2001 From: Obuss Date: Sat, 10 Feb 2018 13:40:22 -0600 Subject: [PATCH] Allow multiple weapon commands (comma delimited) --- src/zr/config.inc | 2 +- src/zr/weapons/zmarket.inc | 61 ++++++++++++++++++++++++++++++++++---- 2 files changed, 57 insertions(+), 6 deletions(-) diff --git a/src/zr/config.inc b/src/zr/config.inc index f950257..6939dbc 100644 --- a/src/zr/config.inc +++ b/src/zr/config.inc @@ -116,7 +116,7 @@ /** * The max length of any config string value. */ -#define CONFIG_MAX_LENGTH 32 +#define CONFIG_MAX_LENGTH 64 /** * @section Config file reference aliases. diff --git a/src/zr/weapons/zmarket.inc b/src/zr/weapons/zmarket.inc index f9371d1..ed07f4d 100644 --- a/src/zr/weapons/zmarket.inc +++ b/src/zr/weapons/zmarket.inc @@ -113,7 +113,28 @@ ZMarketLoad() if(zmarketcommand[0]) { WeaponsGetName(weaponindex, weaponname, sizeof(weaponname)); - RegConsoleCmd(zmarketcommand, ZMarketBuyCommand, weaponname); + + if (FindCharInString(zmarketcommand, ',') != -1) + { + int idx; + int lastidx; + while ((idx = FindCharInString(zmarketcommand[lastidx], ',')) != -1) + { + char out[16]; + char fmt[8]; + Format(fmt, sizeof(fmt), "%%.%ds", idx); + Format(out, sizeof(out), fmt, zmarketcommand[lastidx]); + RegConsoleCmd(out, ZMarketBuyCommand, weaponname); + lastidx += ++idx; + + if (FindCharInString(zmarketcommand[lastidx], ',') == -1 && zmarketcommand[lastidx+1] != '\0') + RegConsoleCmd(zmarketcommand[lastidx], ZMarketBuyCommand, weaponname); + } + } + else + { + RegConsoleCmd(zmarketcommand, ZMarketBuyCommand, weaponname); + } } } @@ -132,11 +153,41 @@ public Action:ZMarketBuyCommand(client, argc) for (new weaponindex = 0; weaponindex < size; weaponindex++) { WeaponsGetZMarketCommand(weaponindex, zmarketcommand, sizeof(zmarketcommand)); - if(StrEqual(command, zmarketcommand)) + + if (FindCharInString(zmarketcommand, ',') != -1) { - WeaponsGetName(weaponindex, weaponname, sizeof(weaponname)); - ZMarketEquip(client, weaponname); - return Plugin_Handled; + int idx; + int lastidx; + while ((idx = FindCharInString(zmarketcommand[lastidx], ',')) != -1) + { + if (!strncmp(command, zmarketcommand[lastidx], idx)) + { + WeaponsGetName(weaponindex, weaponname, sizeof(weaponname)); + ZMarketEquip(client, weaponname); + return Plugin_Handled; + } + + lastidx += ++idx; + + if (FindCharInString(zmarketcommand[lastidx], ',') == -1 && zmarketcommand[lastidx+1] != '\0') + { + if (!strncmp(command, zmarketcommand[lastidx], idx)) + { + WeaponsGetName(weaponindex, weaponname, sizeof(weaponname)); + ZMarketEquip(client, weaponname); + return Plugin_Handled; + } + } + } + } + else + { + if(StrEqual(command, zmarketcommand)) + { + WeaponsGetName(weaponindex, weaponname, sizeof(weaponname)); + ZMarketEquip(client, weaponname); + return Plugin_Handled; + } } }