Skip to content

Commit

Permalink
Fix is_str_num() not handling negative numbers
Browse files Browse the repository at this point in the history
Minor fix because most of the votes don't use negative numbers. This is useful for vote messages which relies on min-max values.
  • Loading branch information
rtxa committed Aug 7, 2024
1 parent 25c066d commit 08dc026
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
8 changes: 4 additions & 4 deletions valve/addons/amxmodx/scripting/agmodx.sma
Original file line number Diff line number Diff line change
Expand Up @@ -1837,7 +1837,7 @@ public OnVoteMaxSpeed(id, check, argc, arg1[], arg2[]) {
return false;
}

if (!is_str_num(arg2)) {
if (!is_str_num_ex(arg2)) {
console_print(id, "%l", "INVALID_NUMBER");
return false;
}
Expand Down Expand Up @@ -1899,7 +1899,7 @@ public OnVoteTimeLimit(id, check, argc, arg1[], arg2[]) {
return false;
}

if (!is_str_num(arg2)) {
if (!is_str_num_ex(arg2)) {
console_print(id, "%l", "INVALID_NUMBER");
return false;
}
Expand Down Expand Up @@ -2046,7 +2046,7 @@ public OnVoteFragLimit(id, check, argc, arg1[], arg2[]) {
return false;
}

if (!is_str_num(arg2)) {
if (!is_str_num_ex(arg2)) {
console_print(id, "%l", "INVALID_NUMBER");
return false;
}
Expand Down Expand Up @@ -2087,7 +2087,7 @@ public OnVoteSelfGauss(id, check, argc, arg1[], arg2[]) {
return false;
}

if (!is_str_num(arg2)) {
if (!is_str_num_ex(arg2)) {
console_print(id, "%l", "INVALID_NUMBER");
return false;
}
Expand Down
17 changes: 17 additions & 0 deletions valve/addons/amxmodx/scripting/include/agmodx_stocks.inc
Original file line number Diff line number Diff line change
Expand Up @@ -290,3 +290,20 @@ stock get_skill_cvar_num(const name[]) {
get_skill_cvar_string(name, value, charsmax(value));
return str_to_num(value);
}

// Alternative to is_str_num which supports both positive and negative numbers.
stock bool:is_str_num_ex(const sString[]) {
new i = 0;
new bool:is_negative = false;

if (sString[0] == '-') {
is_negative = true;
i++;
}

while (sString[i] && isdigit(sString[i])) {
i++;
}

return sString[i] == 0 && i != (is_negative ? 1 : 0);
}

0 comments on commit 08dc026

Please sign in to comment.