[224] | 1 | using AllocsFixes.PersistentData;
|
---|
| 2 | using System;
|
---|
| 3 | using System.Collections.Generic;
|
---|
| 4 | using System.Reflection;
|
---|
| 5 |
|
---|
| 6 | namespace AllocsFixes.CustomCommands
|
---|
| 7 | {
|
---|
| 8 | public class TeleportPlayer : ConsoleCommand
|
---|
| 9 | {
|
---|
| 10 | public TeleportPlayer (ConsoleSdtd cons) : base(cons)
|
---|
| 11 | {
|
---|
| 12 | }
|
---|
| 13 |
|
---|
| 14 | public override string Description ()
|
---|
| 15 | {
|
---|
| 16 | return "teleport a player to a given location";
|
---|
| 17 | }
|
---|
| 18 |
|
---|
| 19 | public override string[] Names ()
|
---|
| 20 | {
|
---|
| 21 | return new string[] { "teleportplayer", "tele" };
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | public override void Run (string[] _params)
|
---|
| 25 | {
|
---|
| 26 | try {
|
---|
| 27 | if (_params.Length != 4 && _params.Length != 2) {
|
---|
| 28 | m_Console.SendResult ("Usage: teleportplayer <entityid|playername|steamid> <x> <y> <z>");
|
---|
| 29 | m_Console.SendResult (" or: teleportplayer <entityid|playername|steamid> <target entityid|playername|steamid>");
|
---|
| 30 | } else {
|
---|
| 31 | Player p1 = PersistentContainer.Instance.Players.GetPlayerByNameOrId (_params [0], true);
|
---|
| 32 | if (p1 == null) {
|
---|
| 33 | m_Console.SendResult ("Playername or entity/steamid id not found.");
|
---|
| 34 | return;
|
---|
| 35 | }
|
---|
| 36 | if (!p1.IsOnline) {
|
---|
| 37 | m_Console.SendResult ("Player not online.");
|
---|
| 38 | return;
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | if (_params.Length == 4) {
|
---|
| 42 | int x = int.MinValue;
|
---|
| 43 | int y = int.MinValue;
|
---|
| 44 | int z = int.MinValue;
|
---|
| 45 |
|
---|
| 46 | int.TryParse (_params [1], out x);
|
---|
| 47 | int.TryParse (_params [2], out y);
|
---|
| 48 | int.TryParse (_params [3], out z);
|
---|
| 49 |
|
---|
| 50 | if (x == int.MinValue || y == int.MinValue || z == int.MinValue) {
|
---|
| 51 | m_Console.SendResult ("At least one of the given coordinates is not a valid integer");
|
---|
| 52 | return;
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | p1.Entity.position.x = x;
|
---|
| 56 | p1.Entity.position.y = y;
|
---|
| 57 | p1.Entity.position.z = z;
|
---|
| 58 | } else {
|
---|
| 59 | Player p2 = PersistentContainer.Instance.Players.GetPlayerByNameOrId (_params [1], true);
|
---|
| 60 | if (p2 == null) {
|
---|
| 61 | m_Console.SendResult ("Target playername or entity/steamid id not found.");
|
---|
| 62 | return;
|
---|
| 63 | }
|
---|
| 64 | if (!p2.IsOnline) {
|
---|
| 65 | m_Console.SendResult ("Target player not online.");
|
---|
| 66 | return;
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | p1.Entity.position = p2.Entity.GetPosition();
|
---|
[228] | 70 | p1.Entity.position.y += 1;
|
---|
| 71 | p1.Entity.position.z += 1;
|
---|
[224] | 72 | }
|
---|
| 73 |
|
---|
[227] | 74 | NetPackage_EntityTeleport pkg = new NetPackage_EntityTeleport (p1.Entity);
|
---|
[224] | 75 |
|
---|
[228] | 76 | ConnectionManager.Instance.SendPackage (pkg, new PackageDestinationSingleEntityID (p1.ClientInfo.entityId));
|
---|
[224] | 77 | }
|
---|
| 78 | } catch (Exception e) {
|
---|
| 79 | Log.Out ("Error in TeleportPlayer.Run: " + e);
|
---|
| 80 | }
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | }
|
---|
| 84 | }
|
---|