using System; using System.Collections.Generic; using System.Reflection; namespace AllocsFixes.CustomCommands { public class TeleportPlayer : ConsoleCmdAbstract { public override string GetDescription () { return "teleport a player to a given location"; } public override string[] GetCommands () { return new string[] { "teleportplayer", "tele" }; } public override void Execute (List _params, CommandSenderInfo _senderInfo) { try { if (_params.Count != 4 && _params.Count != 2) { SdtdConsole.Instance.Output ("Usage: teleportplayer "); SdtdConsole.Instance.Output (" or: teleportplayer "); } else { ClientInfo ci1 = ConsoleHelper.ParseParamIdOrName (_params [0]); if (ci1 == null) { SdtdConsole.Instance.Output ("Playername or entity/steamid id not found."); return; } EntityPlayer ep1 = GameManager.Instance.World.Players.dict [ci1.entityId]; if (_params.Count == 4) { int x = int.MinValue; int y = int.MinValue; int z = int.MinValue; int.TryParse (_params [1], out x); int.TryParse (_params [2], out y); int.TryParse (_params [3], out z); if (x == int.MinValue || y == int.MinValue || z == int.MinValue) { SdtdConsole.Instance.Output ("At least one of the given coordinates is not a valid integer"); return; } ep1.position.x = x; ep1.position.y = y; ep1.position.z = z; } else { ClientInfo ci2 = ConsoleHelper.ParseParamIdOrName (_params [1]); if (ci2 == null) { SdtdConsole.Instance.Output ("Target playername or entity/steamid id not found."); return; } EntityPlayer ep2 = GameManager.Instance.World.Players.dict [ci2.entityId]; ep1.position = ep2.GetPosition(); ep1.position.y += 1; ep1.position.z += 1; } NetPackage_EntityTeleport pkg = new NetPackage_EntityTeleport (ep1); ci1.netConnection [0].AddToSendQueue (pkg); } } catch (Exception e) { Log.Out ("Error in TeleportPlayer.Run: " + e); } } } }