From 32686b90d387bfabbdaaf0395d4c2e32282e4b06 Mon Sep 17 00:00:00 2001 From: Resxt <55228336+Resxt@users.noreply.github.com> Date: Tue, 21 Mar 2023 01:10:44 +0100 Subject: [PATCH] chat_commands 1.3.1 Add support for arguments with spaces (for example names containing spaces such as "The Moonlight") --- chat_commands/README.md | 4 ++++ chat_commands/chat_commands.gsc | 21 ++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/chat_commands/README.md b/chat_commands/README.md index 5ca782f..028b8f3 100644 --- a/chat_commands/README.md +++ b/chat_commands/README.md @@ -58,6 +58,10 @@ set cc_permission_3 "" 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 The player affected by the command dies and swaps to the other team. diff --git a/chat_commands/chat_commands.gsc b/chat_commands/chat_commands.gsc index ee3556f..e9b9f0d 100644 --- a/chat_commands/chat_commands.gsc +++ b/chat_commands/chat_commands.gsc @@ -131,10 +131,29 @@ ChatListener() commandArray = StrTok(message, " "); // Separate the command by space character. Example: ["!map", "mp_dome"] command = commandArray[0]; // The command as text. Example: !map args = []; // The arguments passed to the command. Example: ["mp_dome"] + arg = ""; 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")]))