| 1 | using System;
|
|---|
| 2 | using System.Collections.Generic;
|
|---|
| 3 | using System.Reflection;
|
|---|
| 4 |
|
|---|
| 5 | namespace AllocsFixes.CustomCommands
|
|---|
| 6 | {
|
|---|
| 7 | public class TeleportPlayer : ConsoleCmdAbstract
|
|---|
| 8 | {
|
|---|
| 9 | public override string GetDescription ()
|
|---|
| 10 | {
|
|---|
| 11 | return "teleport a player to a given location";
|
|---|
| 12 | }
|
|---|
| 13 |
|
|---|
| 14 | public override string[] GetCommands ()
|
|---|
| 15 | {
|
|---|
| 16 | return new string[] { "teleportplayer", "tele" };
|
|---|
| 17 | }
|
|---|
| 18 |
|
|---|
| 19 | public override void Execute (List<string> _params, CommandSenderInfo _senderInfo)
|
|---|
| 20 | {
|
|---|
| 21 | try {
|
|---|
| 22 | if (_params.Count != 4 && _params.Count != 2) {
|
|---|
| 23 | SdtdConsole.Instance.Output ("Usage: teleportplayer <entityid|playername|steamid> <x> <y> <z>");
|
|---|
| 24 | SdtdConsole.Instance.Output (" or: teleportplayer <entityid|playername|steamid> <target entityid|playername|steamid>");
|
|---|
| 25 | } else {
|
|---|
| 26 | ClientInfo ci1 = ConsoleHelper.ParseParamIdOrName (_params [0]);
|
|---|
| 27 | if (ci1 == null) {
|
|---|
| 28 | SdtdConsole.Instance.Output ("Playername or entity/steamid id not found.");
|
|---|
| 29 | return;
|
|---|
| 30 | }
|
|---|
| 31 | EntityPlayer ep1 = GameManager.Instance.World.Players.dict [ci1.entityId];
|
|---|
| 32 |
|
|---|
| 33 | if (_params.Count == 4) {
|
|---|
| 34 | int x = int.MinValue;
|
|---|
| 35 | int y = int.MinValue;
|
|---|
| 36 | int z = int.MinValue;
|
|---|
| 37 |
|
|---|
| 38 | int.TryParse (_params [1], out x);
|
|---|
| 39 | int.TryParse (_params [2], out y);
|
|---|
| 40 | int.TryParse (_params [3], out z);
|
|---|
| 41 |
|
|---|
| 42 | if (x == int.MinValue || y == int.MinValue || z == int.MinValue) {
|
|---|
| 43 | SdtdConsole.Instance.Output ("At least one of the given coordinates is not a valid integer");
|
|---|
| 44 | return;
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | ep1.position.x = x;
|
|---|
| 48 | ep1.position.y = y;
|
|---|
| 49 | ep1.position.z = z;
|
|---|
| 50 | } else {
|
|---|
| 51 | ClientInfo ci2 = ConsoleHelper.ParseParamIdOrName (_params [1]);
|
|---|
| 52 | if (ci2 == null) {
|
|---|
| 53 | SdtdConsole.Instance.Output ("Target playername or entity/steamid id not found.");
|
|---|
| 54 | return;
|
|---|
| 55 | }
|
|---|
| 56 | EntityPlayer ep2 = GameManager.Instance.World.Players.dict [ci2.entityId];
|
|---|
| 57 |
|
|---|
| 58 | ep1.position = ep2.GetPosition();
|
|---|
| 59 | ep1.position.y += 1;
|
|---|
| 60 | ep1.position.z += 1;
|
|---|
| 61 | }
|
|---|
| 62 |
|
|---|
| 63 | NetPackage_EntityTeleport pkg = new NetPackage_EntityTeleport (ep1);
|
|---|
| 64 |
|
|---|
| 65 | ci1.SendPackage (pkg);
|
|---|
| 66 | }
|
|---|
| 67 | } catch (Exception e) {
|
|---|
| 68 | Log.Out ("Error in TeleportPlayer.Run: " + e);
|
|---|
| 69 | }
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | }
|
|---|
| 73 | }
|
|---|