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

Last change on this file since 236 was 235, checked in by alloc, 9 years ago

Rev 87 + fixes

File size: 2.1 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
[230]14 public override string[] GetCommands ()
[224]15 {
16 return new string[] { "teleportplayer", "tele" };
17 }
18
[230]19 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo)
[224]20 {
21 try {
[230]22 if (_params.Count != 4 && _params.Count != 2) {
23 SdtdConsole.Instance.Output ("Usage: teleportplayer <entityid|playername|steamid> <x> <y> <z>");
24 SdtdConsole.Instance.Output (" or: teleportplayer <entityid|playername|steamid> <target entityid|playername|steamid>");
[224]25 } else {
[230]26 ClientInfo ci1 = ConsoleHelper.ParseParamIdOrName (_params [0]);
27 if (ci1 == null) {
28 SdtdConsole.Instance.Output ("Playername or entity/steamid id not found.");
[224]29 return;
30 }
[230]31 EntityPlayer ep1 = GameManager.Instance.World.Players.dict [ci1.entityId];
[224]32
[230]33 if (_params.Count == 4) {
[224]34 int x = int.MinValue;
35 int y = int.MinValue;
36 int z = int.MinValue;
37
38 int.TryParse (_params [1], out x);
39 int.TryParse (_params [2], out y);
40 int.TryParse (_params [3], out z);
41
42 if (x == int.MinValue || y == int.MinValue || z == int.MinValue) {
[230]43 SdtdConsole.Instance.Output ("At least one of the given coordinates is not a valid integer");
[224]44 return;
45 }
46
[230]47 ep1.position.x = x;
48 ep1.position.y = y;
49 ep1.position.z = z;
[224]50 } else {
[230]51 ClientInfo ci2 = ConsoleHelper.ParseParamIdOrName (_params [1]);
52 if (ci2 == null) {
53 SdtdConsole.Instance.Output ("Target playername or entity/steamid id not found.");
[224]54 return;
55 }
[230]56 EntityPlayer ep2 = GameManager.Instance.World.Players.dict [ci2.entityId];
[224]57
[230]58 ep1.position = ep2.GetPosition();
59 ep1.position.y += 1;
60 ep1.position.z += 1;
[224]61 }
62
[230]63 NetPackage_EntityTeleport pkg = new NetPackage_EntityTeleport (ep1);
[224]64
[235]65 ci1.SendPackage (pkg);
[224]66 }
67 } catch (Exception e) {
68 Log.Out ("Error in TeleportPlayer.Run: " + e);
69 }
70 }
71
72 }
73}
Note: See TracBrowser for help on using the repository browser.