chat_commands 1.3.1

Add support for arguments with spaces (for example names containing spaces such as "The Moonlight")
This commit is contained in:
Resxt 2023-03-21 01:10:44 +01:00
parent 457416ad66
commit 32686b90d3
2 changed files with 24 additions and 1 deletions

View File

@ -58,6 +58,10 @@ set cc_permission_3 ""
set cc_permission_4 "" set cc_permission_4 ""
``` ```
### Notes
- To pass an argument with a space you need to put `'` around it. For example if a player name is `The Moonlight` then you would write `!teleport 'The Moonlight' Resxt`
## chat_command_change_team.gsc ## chat_command_change_team.gsc
The player affected by the command dies and swaps to the other team. The player affected by the command dies and swaps to the other team.

View File

@ -131,10 +131,29 @@ ChatListener()
commandArray = StrTok(message, " "); // Separate the command by space character. Example: ["!map", "mp_dome"] commandArray = StrTok(message, " "); // Separate the command by space character. Example: ["!map", "mp_dome"]
command = commandArray[0]; // The command as text. Example: !map command = commandArray[0]; // The command as text. Example: !map
args = []; // The arguments passed to the command. Example: ["mp_dome"] args = []; // The arguments passed to the command. Example: ["mp_dome"]
arg = "";
for (i = 1; i < commandArray.size; i++) for (i = 1; i < commandArray.size; i++)
{ {
args = AddElementToArray(args, commandArray[i]); checkedArg = commandArray[i];
if (checkedArg[0] != "'" && arg == "")
{
args = AddElementToArray(args, checkedArg);
}
else if (checkedArg[0] == "'")
{
arg = StrTok(checkedArg, "'")[0] + " ";
}
else if (checkedArg[checkedArg.size - 1] == "'")
{
args = AddElementToArray(args, (arg + StrTok(checkedArg, "'")[0]));
arg = "";
}
else
{
arg += (checkedArg + " ");
}
} }
if (IsDefined(level.commands[GetDvar("net_port")])) if (IsDefined(level.commands[GetDvar("net_port")]))