From caeacbf3d45435c73bbdf6d3cd22e0ca73672add Mon Sep 17 00:00:00 2001 From: Resxt <55228336+Resxt@users.noreply.github.com> Date: Thu, 19 Jan 2023 22:07:25 +0100 Subject: [PATCH] chat_commands 1.1.2 Added changeteam command to swap a player to the other team !changeteam Resxt --- small_scripts/chat_commands.gsc | 55 +++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/small_scripts/chat_commands.gsc b/small_scripts/chat_commands.gsc index b439d81..d88605d 100644 --- a/small_scripts/chat_commands.gsc +++ b/small_scripts/chat_commands.gsc @@ -37,6 +37,7 @@ InitCommands() CreateCommand(level.commands_servers_ports, "map", "function", ::ChangeMapCommand, ["Example: " + level.commands_prefix + "map mp_dome"]); CreateCommand(level.commands_servers_ports, "mode", "function", ::ChangeModeCommand, ["Example: " + level.commands_prefix + "mode FFA_default"]); CreateCommand(level.commands_servers_ports, "mapmode", "function", ::ChangeMapAndModeCommand, ["Example: " + level.commands_prefix + "mapmode mp_seatown TDM_default"]); + CreateCommand(level.commands_servers_ports, "changeteam", "function", ::ChangeTeamCommand, ["Example: " + level.commands_prefix + "changeteam Resxt"]); // Specific server(s) text commands CreateCommand(["27016", "27017"], "rules", "text", ["Do not camp", "Do not spawnkill", "Do not disrespect other players"]); @@ -237,6 +238,21 @@ ChangeMapAndModeCommand(args) ChangeMap(args[0]); } +ChangeTeamCommand(args) +{ + if (args.size < 1) + { + return NotEnoughArgsError(1); + } + + error = ChangeTeam(args[0]); + + if (IsDefined(error)) + { + return error; + } +} + /* Logic functions section */ @@ -256,6 +272,25 @@ ChangeMode(modeName, restart) } } +ChangeTeam(playerName) +{ + player = FindPlayerByName(playerName); + + if (!IsDefined(player)) + { + return PlayerDoesNotExistError(playerName); + } + + if (player.team == "axis") + { + player [[level.allies]](); + } + else if (player.team == "allies") + { + player [[level.axis]](); + } +} + /* Error functions section */ @@ -274,3 +309,23 @@ NotEnoughArgsError(minimumArgs) { return ["Not enough arguments supplied", "At least " + minimumArgs + " argument expected"]; } + +PlayerDoesNotExistError(playerName) +{ + return ["Player " + playerName + " was not found"]; +} + + + +/* Utils section */ + +FindPlayerByName(name) +{ + foreach (player in level.players) + { + if (ToLower(player.name) == ToLower(name)) + { + return player; + } + } +}