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

Last change on this file since 251 was 250, checked in by alloc, 9 years ago

Fixes 5_7_9

File size: 3.6 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\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
36 if (_params.Count == 2 || _params.Count == 4) {
37 ci1 = ConsoleHelper.ParseParamIdOrName (_params [0]);
38 if (ci1 == null) {
39 SdtdConsole.Instance.Output ("Playername or entity/steamid id not found.");
40 return;
41 }
42 ep1 = GameManager.Instance.World.Players.dict [ci1.entityId];
43
44 if (_params.Count == 4) {
45 int x = int.MinValue;
46 int y = int.MinValue;
47 int z = int.MinValue;
48
49 int.TryParse (_params [1], out x);
50 int.TryParse (_params [2], out y);
51 int.TryParse (_params [3], out z);
52
53 if (x == int.MinValue || y == int.MinValue || z == int.MinValue) {
54 SdtdConsole.Instance.Output ("At least one of the given coordinates is not a valid integer");
55 return;
56 }
57
58 ep1.position.x = x;
59 ep1.position.y = y;
60 ep1.position.z = z;
61 } else if (_params.Count == 2) {
62 ClientInfo ci2 = ConsoleHelper.ParseParamIdOrName (_params [1]);
63 if (ci2 == null) {
64 SdtdConsole.Instance.Output ("Target playername or entity/steamid id not found.");
65 return;
66 }
67 EntityPlayer ep2 = GameManager.Instance.World.Players.dict [ci2.entityId];
68
69 ep1.position = ep2.GetPosition ();
70 ep1.position.y += 1;
71 ep1.position.z += 1;
72 }
73 } else if (_params.Count == 3) {
74 if (_senderInfo.RemoteClientInfo == null) {
75 SdtdConsole.Instance.Output ("This command can only be executed on the in-game console.");
76 return;
77 }
78
79 ci1 = _senderInfo.RemoteClientInfo;
80 ep1 = GameManager.Instance.World.Players.dict [ci1.entityId];
81
82 int x = int.MinValue;
83 int y = int.MinValue;
84 int z = int.MinValue;
85
86 int.TryParse (_params [0], out x);
87 int.TryParse (_params [1], out y);
88 int.TryParse (_params [2], out z);
89
90 if (x == int.MinValue || y == int.MinValue || z == int.MinValue) {
91 SdtdConsole.Instance.Output ("At least one of the given coordinates is not a valid integer");
92 return;
93 }
94
95 ep1.position.x = ep1.position.x + x;
96 ep1.position.y = ep1.position.y + y;
97 ep1.position.z = ep1.position.z + z;
98 }
99
100 NetPackageEntityTeleport pkg = new NetPackageEntityTeleport (ep1);
101
102 ci1.SendPackage (pkg);
103 }
104 } catch (Exception e) {
105 Log.Out ("Error in TeleportPlayer.Run: " + e);
106 }
107 }
108
109 }
110}
Note: See TracBrowser for help on using the repository browser.