diff --git a/core/smn_console.cpp b/core/smn_console.cpp index 9ccc5214..aa27d180 100644 --- a/core/smn_console.cpp +++ b/core/smn_console.cpp @@ -391,6 +391,29 @@ static cell_t sm_RegAdminCmd(IPluginContext *pContext, const cell_t *params) return 1; } +static cell_t sm_GetCmdArgs(IPluginContext *pContext, const cell_t *params) +{ + return engine->Cmd_Argc() - 1; +} + +static cell_t sm_GetCmdArg(IPluginContext *pContext, const cell_t *params) +{ + const char *arg = engine->Cmd_Argv(params[1]); + + pContext->StringToLocalUTF8(params[2], params[3], arg, NULL); + + return 1; +} + +static cell_t sm_GetCmdArgString(IPluginContext *pContext, const cell_t *params) +{ + const char *args = engine->Cmd_Args(); + + pContext->StringToLocalUTF8(params[1], params[2], args, NULL); + + return 1; +} + REGISTER_NATIVES(convarNatives) { {"CreateConVar", sm_CreateConVar}, @@ -413,5 +436,8 @@ REGISTER_NATIVES(convarNatives) {"ResetConVar", sm_ResetConVar}, {"RegServerCmd", sm_RegServerCmd}, {"RegConsoleCmd", sm_RegConsoleCmd}, + {"GetCmdArgString", sm_GetCmdArgString}, + {"GetCmdArgs", sm_GetCmdArgs}, + {"GetCmdArg", sm_GetCmdArg}, {NULL, NULL} }; diff --git a/plugins/include/console.inc b/plugins/include/console.inc index fb74edd5..4bfb27b4 100644 --- a/plugins/include/console.inc +++ b/plugins/include/console.inc @@ -131,6 +131,36 @@ native RegAdminCmd(const String:cmd[], const String:description[]="", const String:group[]="", flags=0); + +/** + * Returns the number of arguments from the current console or server command. + * @note Unlike the HL2 engine call, this does not include the command itself. + * + * @return Number of arguments to the current command. + */ +native GetCmdArgs(); + +/** + * Retrieves a command argument given its index, from the current console or + * server command. + * @note Argument indexes start at 1; 0 retrieves the command name. + * + * @param argnum Argument number to retrieve. + * @param buffer Buffer to use for storing the string. + * @param maxlength Maximum length of the buffer. + * @noreturn + */ +native GetCmdArg(argnum, String:buffer[], maxlength); + +/** + * Retrieves the entire command argument string in one lump from the current + * console or server command. + * + * @param buffer Buffer to use for storing the string. + * @param maxlength Maximum length of the buffer. + * @noreturn + */ +native GetCmdArgString(String:buffer[], maxlength); /** * Creates a new console variable.