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

Last change on this file since 245 was 238, checked in by alloc, 9 years ago

Server fixes for A12

File size: 2.6 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Reflection;
4
5namespace AllocsFixes.CustomCommands
6{
7 public class TeleportPlayer : ConsoleCmdAbstract
8 {
9 public override string GetDescription ()
10 {
11 return "teleport a player to a given location";
12 }
13
14 public override string GetHelp () {
15 return "Usage:\n" +
16 " 1. teleportplayer <steam id / player name / entity id> <x> <y> <z>\n" +
17 " 2. teleportplayer <steam id / player name / entity id> <target steam id / player name / entity id>\n" +
18 "1. Teleports the player given by his SteamID, player name or entity id (as given by e.g. \"lpi\")\n" +
19 " to the specified location\n" +
20 "2. As 1, but destination given by another player which has to be online";
21 }
22
23 public override string[] GetCommands ()
24 {
25 return new string[] { "teleportplayer", "tele" };
26 }
27
28 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo)
29 {
30 try {
31 if (_params.Count != 4 && _params.Count != 2) {
32 SdtdConsole.Instance.Output ("Usage: teleportplayer <entityid|playername|steamid> <x> <y> <z>");
33 SdtdConsole.Instance.Output (" or: teleportplayer <entityid|playername|steamid> <target entityid|playername|steamid>");
34 } else {
35 ClientInfo ci1 = ConsoleHelper.ParseParamIdOrName (_params [0]);
36 if (ci1 == null) {
37 SdtdConsole.Instance.Output ("Playername or entity/steamid id not found.");
38 return;
39 }
40 EntityPlayer ep1 = GameManager.Instance.World.Players.dict [ci1.entityId];
41
42 if (_params.Count == 4) {
43 int x = int.MinValue;
44 int y = int.MinValue;
45 int z = int.MinValue;
46
47 int.TryParse (_params [1], out x);
48 int.TryParse (_params [2], out y);
49 int.TryParse (_params [3], out z);
50
51 if (x == int.MinValue || y == int.MinValue || z == int.MinValue) {
52 SdtdConsole.Instance.Output ("At least one of the given coordinates is not a valid integer");
53 return;
54 }
55
56 ep1.position.x = x;
57 ep1.position.y = y;
58 ep1.position.z = z;
59 } else {
60 ClientInfo ci2 = ConsoleHelper.ParseParamIdOrName (_params [1]);
61 if (ci2 == null) {
62 SdtdConsole.Instance.Output ("Target playername or entity/steamid id not found.");
63 return;
64 }
65 EntityPlayer ep2 = GameManager.Instance.World.Players.dict [ci2.entityId];
66
67 ep1.position = ep2.GetPosition();
68 ep1.position.y += 1;
69 ep1.position.z += 1;
70 }
71
72 NetPackageEntityTeleport pkg = new NetPackageEntityTeleport (ep1);
73
74 ci1.SendPackage (pkg);
75 }
76 } catch (Exception e) {
77 Log.Out ("Error in TeleportPlayer.Run: " + e);
78 }
79 }
80
81 }
82}
Note: See TracBrowser for help on using the repository browser.