From 9734839e5f6bb4a4dd42ef97e62ca74065dab23b Mon Sep 17 00:00:00 2001 From: Rushaway Date: Mon, 2 Dec 2024 11:08:58 +0100 Subject: [PATCH 1/3] feat(weapons): Make logic easier --- .../scripting/zr/weapons/zmarket.inc | 62 +++++++------------ 1 file changed, 23 insertions(+), 39 deletions(-) diff --git a/src/addons/sourcemod/scripting/zr/weapons/zmarket.inc b/src/addons/sourcemod/scripting/zr/weapons/zmarket.inc index 77a351d..75205ba 100644 --- a/src/addons/sourcemod/scripting/zr/weapons/zmarket.inc +++ b/src/addons/sourcemod/scripting/zr/weapons/zmarket.inc @@ -111,19 +111,16 @@ void ZMarketLoad() if (FindCharInString(zmarketcommand, ',') != -1) { - int idx; - int lastidx; - while ((idx = FindCharInString(zmarketcommand[lastidx], ',')) != -1) + char commands[8][32]; + int count = ExplodeString(zmarketcommand, ",", commands, sizeof(commands), sizeof(commands[])); + + for (int i = 0; i < count; i++) { - 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); + TrimString(commands[i]); + if (strlen(commands[i]) > 0) + { + RegConsoleCmd(commands[i], ZMarketBuyCommand, weaponname); + } } } else @@ -156,41 +153,28 @@ public Action ZMarketBuyCommand(int client, int argc) { WeaponsGetZMarketCommand(weaponindex, zmarketcommand, sizeof(zmarketcommand)); - if (FindCharInString(zmarketcommand, ',') != -1) - { - 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; + // Split the commands and check each one + char commands[8][32]; + int count = ExplodeString(zmarketcommand, ",", commands, sizeof(commands), sizeof(commands[])); - 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 + for (int i = 0; i < count; i++) { - if(strcmp(command, zmarketcommand, false) == 0) + TrimString(commands[i]); + if (strcmp(command, commands[i], false) == 0) { WeaponsGetName(weaponindex, weaponname, sizeof(weaponname)); ZMarketEquip(client, weaponname); return Plugin_Handled; } } + + // Also check for single command case + if (strcmp(command, zmarketcommand, false) == 0) + { + WeaponsGetName(weaponindex, weaponname, sizeof(weaponname)); + ZMarketEquip(client, weaponname); + return Plugin_Handled; + } } return Plugin_Handled; From ff3008ed38aa4a38e339d4578709bd537b494c81 Mon Sep 17 00:00:00 2001 From: Rushaway Date: Mon, 2 Dec 2024 11:22:04 +0100 Subject: [PATCH 2/3] Bump version --- src/addons/sourcemod/scripting/zombiereloaded.sp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/addons/sourcemod/scripting/zombiereloaded.sp b/src/addons/sourcemod/scripting/zombiereloaded.sp index 5b413c3..fcd8c18 100644 --- a/src/addons/sourcemod/scripting/zombiereloaded.sp +++ b/src/addons/sourcemod/scripting/zombiereloaded.sp @@ -45,7 +45,7 @@ #include -#define VERSION "3.10.13" +#define VERSION "3.10.14" // Comment this line to exclude version info command. Enable this if you have // the repository and HG installed (Mercurial or TortoiseHG). From 70237080d9542e5511353830425a78c498a16498 Mon Sep 17 00:00:00 2001 From: Rushaway Date: Mon, 2 Dec 2024 14:56:44 +0100 Subject: [PATCH 3/3] Reviewed changes --- .../scripting/zr/weapons/zmarket.inc | 52 ++++++++++--------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/src/addons/sourcemod/scripting/zr/weapons/zmarket.inc b/src/addons/sourcemod/scripting/zr/weapons/zmarket.inc index 75205ba..88656e4 100644 --- a/src/addons/sourcemod/scripting/zr/weapons/zmarket.inc +++ b/src/addons/sourcemod/scripting/zr/weapons/zmarket.inc @@ -100,6 +100,8 @@ void ZMarketLoad() char zmarketcommand[CONFIG_MAX_LENGTH]; char weaponname[WEAPONS_MAX_LENGTH]; + char commands[8][32]; + int count; int size = GetArraySize(arrayWeapons); for (int weaponindex = 0; weaponindex < size; weaponindex++) @@ -111,21 +113,22 @@ void ZMarketLoad() if (FindCharInString(zmarketcommand, ',') != -1) { - char commands[8][32]; - int count = ExplodeString(zmarketcommand, ",", commands, sizeof(commands), sizeof(commands[])); - - for (int i = 0; i < count; i++) - { - TrimString(commands[i]); - if (strlen(commands[i]) > 0) - { - RegConsoleCmd(commands[i], ZMarketBuyCommand, weaponname); - } - } + count = ExplodeString(zmarketcommand, ",", commands, sizeof(commands), sizeof(commands[])); } else { - RegConsoleCmd(zmarketcommand, ZMarketBuyCommand, weaponname); + count = 1; + strcopy(commands[0], sizeof(commands[]), zmarketcommand); + } + + // Register each command + for (int i = 0; i < count; i++) + { + TrimString(commands[i]); + if (strlen(commands[i]) > 0) + { + RegConsoleCmd(commands[i], ZMarketBuyCommand, weaponname); + } } } } @@ -139,6 +142,8 @@ public Action ZMarketBuyCommand(int client, int argc) char command[CONFIG_MAX_LENGTH]; char zmarketcommand[CONFIG_MAX_LENGTH]; char weaponname[WEAPONS_MAX_LENGTH]; + char commands[8][32]; + int count; GetCmdArg(0, command, sizeof(command)); @@ -153,28 +158,27 @@ public Action ZMarketBuyCommand(int client, int argc) { WeaponsGetZMarketCommand(weaponindex, zmarketcommand, sizeof(zmarketcommand)); - // Split the commands and check each one - char commands[8][32]; - int count = ExplodeString(zmarketcommand, ",", commands, sizeof(commands), sizeof(commands[])); + if (FindCharInString(zmarketcommand, ',') != -1) + { + count = ExplodeString(zmarketcommand, ",", commands, sizeof(commands), sizeof(commands[])); + } + else + { + count = 1; + strcopy(commands[0], sizeof(commands[]), zmarketcommand); + } + // Check each command for (int i = 0; i < count; i++) { TrimString(commands[i]); - if (strcmp(command, commands[i], false) == 0) + if (strlen(commands[i]) > 0 && strcmp(command, commands[i], false) == 0) { WeaponsGetName(weaponindex, weaponname, sizeof(weaponname)); ZMarketEquip(client, weaponname); return Plugin_Handled; } } - - // Also check for single command case - if (strcmp(command, zmarketcommand, false) == 0) - { - WeaponsGetName(weaponindex, weaponname, sizeof(weaponname)); - ZMarketEquip(client, weaponname); - return Plugin_Handled; - } } return Plugin_Handled;