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 GetHelp () { return "Usage:\n" + " 1. teleportplayer \n" + " 2. teleportplayer \n" + " 3. teleportplayer \n" + "1. Teleports the player given by his SteamID, player name or entity id (as given by e.g. \"lpi\")\n" + " to the specified location. Use y = -1 to spawn on ground.\n" + "2. As 1, but destination given by another player which has to be online\n" + "3. Teleport the local player to the position calculated by his current position and the given offsets"; } public override string[] GetCommands () { return new string[] { "teleportplayer", "tele" }; } public override void Execute (List _params, CommandSenderInfo _senderInfo) { try { if (_params.Count < 2 || _params.Count > 4) { SdtdConsole.Instance.Output ("Wrong number of arguments, expected 2 to 4, found " + _params.Count + "."); return; } else { ClientInfo ci1 = null; EntityPlayer ep1 = null; UnityEngine.Vector3 destPos = new UnityEngine.Vector3 (); if (_params.Count == 2 || _params.Count == 4) { ci1 = ConsoleHelper.ParseParamIdOrName (_params [0]); if (ci1 == null) { SdtdConsole.Instance.Output ("Playername or entity/steamid id not found."); return; } 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; } destPos.x = x; destPos.y = y; destPos.z = z; } else if (_params.Count == 2) { 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]; destPos = ep2.GetPosition (); destPos.y += 1; destPos.z += 1; } } else if (_params.Count == 3) { if (_senderInfo.RemoteClientInfo == null) { SdtdConsole.Instance.Output ("This command can only be executed in variant 3 on the in-game console."); return; } ci1 = _senderInfo.RemoteClientInfo; ep1 = GameManager.Instance.World.Players.dict [ci1.entityId]; int x = int.MinValue; int y = int.MinValue; int z = int.MinValue; int.TryParse (_params [0], out x); int.TryParse (_params [1], out y); int.TryParse (_params [2], 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; } destPos.x = ep1.position.x + x; destPos.y = ep1.position.y + y; destPos.z = ep1.position.z + z; } NetPackageTeleportPlayer pkg = new NetPackageTeleportPlayer (destPos); ci1.SendPackage (pkg); } } catch (Exception e) { Log.Out ("Error in TeleportPlayer.Run: " + e); } } } }