1 | using AllocsFixes.PersistentData;
|
---|
2 | using System;
|
---|
3 | using System.Collections.Generic;
|
---|
4 | using UnityEngine;
|
---|
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();
|
---|
70 | }
|
---|
71 |
|
---|
72 | NetPackage_EntityPosAndRot pkg = new NetPackage_EntityPosAndRot (p1.Entity);
|
---|
73 |
|
---|
74 | p1.ClientInfo.netConnection [0].Send (pkg);
|
---|
75 | }
|
---|
76 | } catch (Exception e) {
|
---|
77 | Log.Out ("Error in TeleportPlayer.Run: " + e);
|
---|
78 | }
|
---|
79 | }
|
---|
80 |
|
---|
81 | }
|
---|
82 | }
|
---|