[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 | private MethodInfo NetConnection_SendPackage = null;
|
---|
| 11 |
|
---|
| 12 | public TeleportPlayer (ConsoleSdtd cons) : base(cons)
|
---|
| 13 | {
|
---|
| 14 | Type typeClientInfo = Assembly.GetAssembly (typeof(ClientInfo)).GetType ("ClientInfo");
|
---|
| 15 | Type typeNetConnection = typeClientInfo.GetField ("netConnection").FieldType.GetElementType ();
|
---|
| 16 | MethodInfo[] mis = typeNetConnection.GetMethods ();
|
---|
| 17 | foreach (MethodInfo mi in mis) {
|
---|
| 18 | ParameterInfo[] pis = mi.GetParameters ();
|
---|
| 19 | if (pis.Length == 1) {
|
---|
| 20 | if (typeof (Package).Equals (pis[0].ParameterType)) {
|
---|
| 21 | NetConnection_SendPackage = mi;
|
---|
| 22 | }
|
---|
| 23 | }
|
---|
| 24 | }
|
---|
| 25 | }
|
---|
| 26 |
|
---|
| 27 | public override string Description ()
|
---|
| 28 | {
|
---|
| 29 | return "teleport a player to a given location";
|
---|
| 30 | }
|
---|
| 31 |
|
---|
| 32 | public override string[] Names ()
|
---|
| 33 | {
|
---|
| 34 | return new string[] { "teleportplayer", "tele" };
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | public override void Run (string[] _params)
|
---|
| 38 | {
|
---|
| 39 | try {
|
---|
| 40 | if (_params.Length != 4 && _params.Length != 2) {
|
---|
| 41 | m_Console.SendResult ("Usage: teleportplayer <entityid|playername|steamid> <x> <y> <z>");
|
---|
| 42 | m_Console.SendResult (" or: teleportplayer <entityid|playername|steamid> <target entityid|playername|steamid>");
|
---|
| 43 | } else {
|
---|
| 44 | Player p1 = PersistentContainer.Instance.Players.GetPlayerByNameOrId (_params [0], true);
|
---|
| 45 | if (p1 == null) {
|
---|
| 46 | m_Console.SendResult ("Playername or entity/steamid id not found.");
|
---|
| 47 | return;
|
---|
| 48 | }
|
---|
| 49 | if (!p1.IsOnline) {
|
---|
| 50 | m_Console.SendResult ("Player not online.");
|
---|
| 51 | return;
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | if (_params.Length == 4) {
|
---|
| 55 | int x = int.MinValue;
|
---|
| 56 | int y = int.MinValue;
|
---|
| 57 | int z = int.MinValue;
|
---|
| 58 |
|
---|
| 59 | int.TryParse (_params [1], out x);
|
---|
| 60 | int.TryParse (_params [2], out y);
|
---|
| 61 | int.TryParse (_params [3], out z);
|
---|
| 62 |
|
---|
| 63 | if (x == int.MinValue || y == int.MinValue || z == int.MinValue) {
|
---|
| 64 | m_Console.SendResult ("At least one of the given coordinates is not a valid integer");
|
---|
| 65 | return;
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | p1.Entity.position.x = x;
|
---|
| 69 | p1.Entity.position.y = y;
|
---|
| 70 | p1.Entity.position.z = z;
|
---|
| 71 | } else {
|
---|
| 72 | Player p2 = PersistentContainer.Instance.Players.GetPlayerByNameOrId (_params [1], true);
|
---|
| 73 | if (p2 == null) {
|
---|
| 74 | m_Console.SendResult ("Target playername or entity/steamid id not found.");
|
---|
| 75 | return;
|
---|
| 76 | }
|
---|
| 77 | if (!p2.IsOnline) {
|
---|
| 78 | m_Console.SendResult ("Target player not online.");
|
---|
| 79 | return;
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | p1.Entity.position = p2.Entity.GetPosition();
|
---|
| 83 | }
|
---|
| 84 |
|
---|
[227] | 85 | NetPackage_EntityTeleport pkg = new NetPackage_EntityTeleport (p1.Entity);
|
---|
[224] | 86 |
|
---|
| 87 | if (NetConnection_SendPackage != null) {
|
---|
| 88 | NetConnection_SendPackage.Invoke (p1.ClientInfo.netConnection [0], new object[] {pkg});
|
---|
[227] | 89 | } else {
|
---|
| 90 | m_Console.SendResult ("SendPackage method not found");
|
---|
[224] | 91 | }
|
---|
| 92 | }
|
---|
| 93 | } catch (Exception e) {
|
---|
| 94 | Log.Out ("Error in TeleportPlayer.Run: " + e);
|
---|
| 95 | }
|
---|
| 96 | }
|
---|
| 97 |
|
---|
| 98 | }
|
---|
| 99 | }
|
---|