From 8ee3ca5bc7c6159ea9d68c3c2d97ec4a5e506f55 Mon Sep 17 00:00:00 2001 From: Resxt <55228336+Resxt@users.noreply.github.com> Date: Mon, 6 Feb 2023 03:22:40 +0100 Subject: [PATCH] chat_commands 1.1.5 All commands that require a player name to be passed now work both with a player name or with "me" to target yourself [Dev] All commands that use FindPlayerByName will now work with "me" passed as the player out of the box since FindPlayerByName now returns self if the name param is "me" [Refactor] Fix undefined errors when calling a status command for the first time on a player --- small_scripts/chat_commands.gsc | 38 ++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/small_scripts/chat_commands.gsc b/small_scripts/chat_commands.gsc index 8f1eba8..56e7161 100644 --- a/small_scripts/chat_commands.gsc +++ b/small_scripts/chat_commands.gsc @@ -332,21 +332,14 @@ TeleportPlayer(teleportedPlayerName, destinationPlayerName) { name = names[i]; - if (name == "me") - { - players = AddElementToArray(players, self); - } - else - { - player = FindPlayerByName(name); + player = FindPlayerByName(name); - if (!IsDefined(player)) - { - return PlayerDoesNotExistError(name); - } - - players = AddElementToArray(players, player); + if (!IsDefined(player)) + { + return PlayerDoesNotExistError(name); } + + players = AddElementToArray(players, player); } players[0] SetOrigin(players[1].origin); @@ -404,6 +397,11 @@ PlayerDoesNotExistError(playerName) FindPlayerByName(name) { + if (name == "me") + { + return self; + } + foreach (player in level.players) { if (ToLower(player.name) == ToLower(name)) @@ -437,9 +435,19 @@ ToggleStatus(commandName, commandDisplayName, player) GetStatus(commandName, player) { - if (!IsDefined(player.chat_commands["status"][commandName])) + if (!IsDefined(player.chat_commands)) // avoid undefined errors in the console { - return false; + player.chat_commands = []; + } + + if (!IsDefined(player.chat_commands["status"])) // avoid undefined errors in the console + { + player.chat_commands["status"] = []; + } + + if (!IsDefined(player.chat_commands["status"][commandName])) // status is set to OFF/false by default + { + SetStatus(commandName, player, false); } return player.chat_commands["status"][commandName];