Skip to content

Commit

Permalink
feat(weapons): easier multi command logic (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rushaway authored Dec 2, 2024
1 parent b3040d0 commit 9c5f119
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 40 deletions.
2 changes: 1 addition & 1 deletion src/addons/sourcemod/scripting/zombiereloaded.sp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

#include <sdkhooks>

#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).
Expand Down
66 changes: 27 additions & 39 deletions src/addons/sourcemod/scripting/zr/weapons/zmarket.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
Expand All @@ -111,24 +113,22 @@ void ZMarketLoad()

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);
}
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);
}
}
}
}
Expand All @@ -142,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));

Expand All @@ -158,33 +160,19 @@ public Action ZMarketBuyCommand(int client, int argc)

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;

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;
}
}
}
count = ExplodeString(zmarketcommand, ",", commands, sizeof(commands), sizeof(commands[]));
}
else
{
if(strcmp(command, zmarketcommand, false) == 0)
count = 1;
strcopy(commands[0], sizeof(commands[]), zmarketcommand);
}

// Check each command
for (int i = 0; i < count; i++)
{
TrimString(commands[i]);
if (strlen(commands[i]) > 0 && strcmp(command, commands[i], false) == 0)
{
WeaponsGetName(weaponindex, weaponname, sizeof(weaponname));
ZMarketEquip(client, weaponname);
Expand Down

0 comments on commit 9c5f119

Please sign in to comment.