diff --git a/chat_commands/README.md b/chat_commands/README.md index 68b527b..0b326b9 100644 --- a/chat_commands/README.md +++ b/chat_commands/README.md @@ -52,6 +52,18 @@ The player who runs the command dies. Arguments expected: none. Example: `!suicide` +## chat_command_teleport.gsc + +Teleports a player to another + +Arguments expected: (1) the name of the player to teleport (2) the name of the player to teleport to. + +| Examples | +|---| +| `!teleport me Eldor` | +| `!teleport Eldor me` | +| `!teleport Eldor Rektinator` | + ## chat_command_text_rules.gsc Prints the server rules in the player's chat. diff --git a/chat_commands/chat_command_teleport.gsc b/chat_commands/chat_command_teleport.gsc new file mode 100644 index 0000000..fdf32a0 --- /dev/null +++ b/chat_commands/chat_command_teleport.gsc @@ -0,0 +1,51 @@ +#include scripts\chat_commands; + +Init() +{ + CreateCommand(level.commands_servers_ports, "teleport", "function", ::TeleportCommand, ["default_help_two_players"]); +} + + + +/* Command section */ + +TeleportCommand(args) +{ + if (args.size < 2) + { + return NotEnoughArgsError(2); + } + + error = TeleportPlayer(args[0], args[1]); + + if (IsDefined(error)) + { + return error; + } +} + + + +/* Logic section */ + +TeleportPlayer(teleportedPlayerName, destinationPlayerName) +{ + players = []; + names = [teleportedPlayerName, destinationPlayerName]; + + for (i = 0; i < names.size; i++) + { + name = names[i]; + + player = FindPlayerByName(name); + + if (!IsDefined(player)) + { + return PlayerDoesNotExistError(name); + } + + players = AddElementToArray(players, player); + } + + players[0] SetOrigin(players[1].origin); +} \ No newline at end of file