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

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

Fixes 6_8_11

File size: 3.7 KB
RevLine 
[224]1using System;
2using System.Collections.Generic;
3using System.Reflection;
4
5namespace AllocsFixes.CustomCommands
6{
[250]7 public class TeleportPlayer : ConsoleCmdAbstract {
8 public override string GetDescription () {
[224]9 return "teleport a player to a given location";
10 }
11
[238]12 public override string GetHelp () {
13 return "Usage:\n" +
[250]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" +
[253]18 " to the specified location. Use y = -1 to spawn on ground.\n" +
[250]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";
[238]21 }
22
[250]23 public override string[] GetCommands () {
[224]24 return new string[] { "teleportplayer", "tele" };
25 }
26
[250]27 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo) {
[224]28 try {
[250]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;
[224]32 } else {
[250]33 ClientInfo ci1 = null;
34 EntityPlayer ep1 = null;
[254]35 UnityEngine.Vector3 destPos = new UnityEngine.Vector3 ();
[250]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];
[224]44
[250]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
[253]59 destPos.x = x;
60 destPos.y = y;
61 destPos.z = z;
[250]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
[253]70 destPos = ep2.GetPosition ();
71 destPos.y += 1;
72 destPos.z += 1;
[250]73 }
74 } else if (_params.Count == 3) {
75 if (_senderInfo.RemoteClientInfo == null) {
[253]76 SdtdConsole.Instance.Output ("This command can only be executed in variant 3 on the in-game console.");
[250]77 return;
78 }
79
80 ci1 = _senderInfo.RemoteClientInfo;
81 ep1 = GameManager.Instance.World.Players.dict [ci1.entityId];
82
[224]83 int x = int.MinValue;
84 int y = int.MinValue;
85 int z = int.MinValue;
86
[250]87 int.TryParse (_params [0], out x);
88 int.TryParse (_params [1], out y);
89 int.TryParse (_params [2], out z);
[224]90
91 if (x == int.MinValue || y == int.MinValue || z == int.MinValue) {
[230]92 SdtdConsole.Instance.Output ("At least one of the given coordinates is not a valid integer");
[224]93 return;
94 }
95
[253]96 destPos.x = ep1.position.x + x;
97 destPos.y = ep1.position.y + y;
98 destPos.z = ep1.position.z + z;
[224]99 }
100
[253]101 NetPackageTeleportPlayer pkg = new NetPackageTeleportPlayer (destPos);
[224]102
[235]103 ci1.SendPackage (pkg);
[224]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.