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