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

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

Server fixes for A12

File size: 2.6 KB
RevLine 
[224]1using System;
2using System.Collections.Generic;
3using System.Reflection;
4
5namespace AllocsFixes.CustomCommands
6{
[230]7 public class TeleportPlayer : ConsoleCmdAbstract
[224]8 {
[230]9 public override string GetDescription ()
[224]10 {
11 return "teleport a player to a given location";
12 }
13
[238]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
[230]23 public override string[] GetCommands ()
[224]24 {
25 return new string[] { "teleportplayer", "tele" };
26 }
27
[230]28 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo)
[224]29 {
30 try {
[230]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>");
[224]34 } else {
[230]35 ClientInfo ci1 = ConsoleHelper.ParseParamIdOrName (_params [0]);
36 if (ci1 == null) {
37 SdtdConsole.Instance.Output ("Playername or entity/steamid id not found.");
[224]38 return;
39 }
[230]40 EntityPlayer ep1 = GameManager.Instance.World.Players.dict [ci1.entityId];
[224]41
[230]42 if (_params.Count == 4) {
[224]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) {
[230]52 SdtdConsole.Instance.Output ("At least one of the given coordinates is not a valid integer");
[224]53 return;
54 }
55
[230]56 ep1.position.x = x;
57 ep1.position.y = y;
58 ep1.position.z = z;
[224]59 } else {
[230]60 ClientInfo ci2 = ConsoleHelper.ParseParamIdOrName (_params [1]);
61 if (ci2 == null) {
62 SdtdConsole.Instance.Output ("Target playername or entity/steamid id not found.");
[224]63 return;
64 }
[230]65 EntityPlayer ep2 = GameManager.Instance.World.Players.dict [ci2.entityId];
[224]66
[230]67 ep1.position = ep2.GetPosition();
68 ep1.position.y += 1;
69 ep1.position.z += 1;
[224]70 }
71
[238]72 NetPackageEntityTeleport pkg = new NetPackageEntityTeleport (ep1);
[224]73
[235]74 ci1.SendPackage (pkg);
[224]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.