diff --git a/plugins/funcommands/fire.sp b/plugins/funcommands/fire.sp index 0be9b791..0d9da55e 100644 --- a/plugins/funcommands/fire.sp +++ b/plugins/funcommands/fire.sp @@ -383,9 +383,7 @@ public Action Command_Burn(int client, int args) if (args > 1) { - char time[20]; - GetCmdArg(2, time, sizeof(time)); - if (StringToFloatEx(time, seconds) == 0) + if (!GetCmdArgFloatEx(2, seconds)) { ReplyToCommand(client, "[SM] %t", "Invalid Amount"); return Plugin_Handled; diff --git a/plugins/funcommands/gravity.sp b/plugins/funcommands/gravity.sp index aa79f799..bad52cce 100644 --- a/plugins/funcommands/gravity.sp +++ b/plugins/funcommands/gravity.sp @@ -197,9 +197,7 @@ public Action Command_Gravity(int client, int args) float amount = 1.0; if (args > 1) { - char arg2[20]; - GetCmdArg(2, arg2, sizeof(arg2)); - if (StringToFloatEx(arg2, amount) == 0) + if (!GetCmdArgFloatEx(2, amount)) { ReplyToCommand(client, "[SM] %t", "Invalid Amount"); return Plugin_Handled; diff --git a/plugins/include/console.inc b/plugins/include/console.inc index c08738ca..ee2db555 100644 --- a/plugins/include/console.inc +++ b/plugins/include/console.inc @@ -428,10 +428,11 @@ native int GetCmdArg(int argnum, char[] buffer, int maxlength); * console or server command. Will return 0 if the argument can not be * parsed as a number. Use GetCmdArgIntEx to handle that explicitly. * - * @param argnum Argument number to retrieve. - * @return Value of the command argument. + * @param argnum Argument number to retrieve. + * @return Value of the command argument. */ -stock int GetCmdArgInt(int argnum) { +stock int GetCmdArgInt(int argnum) +{ char str[12]; GetCmdArg(argnum, str, sizeof(str)); @@ -443,17 +444,51 @@ stock int GetCmdArgInt(int argnum) { * console or server command. Returns false if the argument can not be * completely parsed as an integer. * - * @param argnum Argument number to retrieve. - * @param value Populated with the value of the command argument. - * @return Whether the argument was entirely a numeric value. + * @param argnum Argument number to retrieve. + * @param value Populated with the value of the command argument. + * @return Whether the argument was entirely a numeric value. */ -stock bool GetCmdArgIntEx(int argnum, int &value) { +stock bool GetCmdArgIntEx(int argnum, int &value) +{ char str[12]; int len = GetCmdArg(argnum, str, sizeof(str)); return StringToIntEx(str, value) == len && len > 0; } +/** + * Retrieves a float command argument given its index, from the current + * console or server command. Will return 0.0 if the argument can not be + * parsed as a number. Use GetCmdArgFloatEx to handle that explicitly. + * + * @param argnum Argument number to retrieve. + * @return Value of the command argument. + */ +stock float GetCmdArgFloat(int argnum) +{ + char str[18]; + GetCmdArg(argnum, str, sizeof(str)); + + return StringToFloat(str); +} + +/** + * Retrieves a float command argument given its index, from the current + * console or server command. Returns false if the argument can not be + * completely parsed as a floating point. + * + * @param argnum Argument number to retrieve. + * @param value Populated with the value of the command argument. + * @return Whether the argument was entirely a floating point value. + */ +stock bool GetCmdArgFloatEx(int argnum, float &value) +{ + char str[18]; + int len = GetCmdArg(argnum, str, sizeof(str)); + + return StringToFloatEx(str, value) == len && len > 0; +} + /** * Retrieves the entire command argument string in one lump from the current * console or server command.