source: binary-improvements/AllocsCommands/Commands/TeleportPlayer.cs@ 281

Last change on this file since 281 was 254, checked in by alloc, 9 years ago

Fixes 6_8_11

File size: 3.7 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Reflection;
4
5namespace AllocsFixes.CustomCommands
6{
7 public class TeleportPlayer : ConsoleCmdAbstract {
8 public override string GetDescription () {
9 return "teleport a player to a given location";
10 }
11
12 public override string GetHelp () {
13 return "Usage:\n" +
14 " 1. teleportplayer <steam id / player name / entity id> <x> <y> <z>\n" +
15 " 2. teleportplayer <steam id / player name / entity id> <target steam id / player name / entity id>\n" +
16 " 3. teleportplayer <inc x> <inc y> <inc z>\n" +
17 "1. Teleports the player given by his SteamID, player name or entity id (as given by e.g. \"lpi\")\n" +
18 " to the specified location. Use y = -1 to spawn on ground.\n" +
19 "2. As 1, but destination given by another player which has to be online\n" +
20 "3. Teleport the local player to the position calculated by his current position and the given offsets";
21 }
22
23 public override string[] GetCommands () {
24 return new string[] { "teleportplayer", "tele" };
25 }
26
27 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo) {
28 try {
29 if (_params.Count < 2 || _params.Count > 4) {
30 SdtdConsole.Instance.Output ("Wrong number of arguments, expected 2 to 4, found " + _params.Count + ".");
31 return;
32 } else {
33 ClientInfo ci1 = null;
34 EntityPlayer ep1 = null;
35 UnityEngine.Vector3 destPos = new UnityEngine.Vector3 ();
36
37 if (_params.Count == 2 || _params.Count == 4) {
38 ci1 = ConsoleHelper.ParseParamIdOrName (_params [0]);
39 if (ci1 == null) {
40 SdtdConsole.Instance.Output ("Playername or entity/steamid id not found.");
41 return;
42 }
43 ep1 = GameManager.Instance.World.Players.dict [ci1.entityId];
44
45 if (_params.Count == 4) {
46 int x = int.MinValue;
47 int y = int.MinValue;
48 int z = int.MinValue;
49
50 int.TryParse (_params [1], out x);
51 int.TryParse (_params [2], out y);
52 int.TryParse (_params [3], out z);
53
54 if (x == int.MinValue || y == int.MinValue || z == int.MinValue) {
55 SdtdConsole.Instance.Output ("At least one of the given coordinates is not a valid integer");
56 return;
57 }
58
59 destPos.x = x;
60 destPos.y = y;
61 destPos.z = z;
62 } else if (_params.Count == 2) {
63 ClientInfo ci2 = ConsoleHelper.ParseParamIdOrName (_params [1]);
64 if (ci2 == null) {
65 SdtdConsole.Instance.Output ("Target playername or entity/steamid id not found.");
66 return;
67 }
68 EntityPlayer ep2 = GameManager.Instance.World.Players.dict [ci2.entityId];
69
70 destPos = ep2.GetPosition ();
71 destPos.y += 1;
72 destPos.z += 1;
73 }
74 } else if (_params.Count == 3) {
75 if (_senderInfo.RemoteClientInfo == null) {
76 SdtdConsole.Instance.Output ("This command can only be executed in variant 3 on the in-game console.");
77 return;
78 }
79
80 ci1 = _senderInfo.RemoteClientInfo;
81 ep1 = GameManager.Instance.World.Players.dict [ci1.entityId];
82
83 int x = int.MinValue;
84 int y = int.MinValue;
85 int z = int.MinValue;
86
87 int.TryParse (_params [0], out x);
88 int.TryParse (_params [1], out y);
89 int.TryParse (_params [2], out z);
90
91 if (x == int.MinValue || y == int.MinValue || z == int.MinValue) {
92 SdtdConsole.Instance.Output ("At least one of the given coordinates is not a valid integer");
93 return;
94 }
95
96 destPos.x = ep1.position.x + x;
97 destPos.y = ep1.position.y + y;
98 destPos.z = ep1.position.z + z;
99 }
100
101 NetPackageTeleportPlayer pkg = new NetPackageTeleportPlayer (destPos);
102
103 ci1.SendPackage (pkg);
104 }
105 } catch (Exception e) {
106 Log.Out ("Error in TeleportPlayer.Run: " + e);
107 }
108 }
109
110 }
111}
Note: See TracBrowser for help on using the repository browser.