source: binary-improvements/7dtd-server-fixes/src/CustomCommands/TeleportPlayer.cs@ 172

Last change on this file since 172 was 163, checked in by alloc, 10 years ago

fixes

File size: 1.7 KB
RevLine 
[163]1using AllocsFixes.PersistentData;
2using System;
3using System.Collections.Generic;
4
5namespace AllocsFixes.CustomCommands
6{
7 public class TeleportPlayer : ConsoleCommand
8 {
9 public TeleportPlayer (ConsoleSdtd cons) : base(cons)
10 {
11 }
12
13 public override string Description ()
14 {
15 return "teleport a player to a given location";
16 }
17
18 public override string[] Names ()
19 {
20 return new string[] { "teleportplayer", "tele" };
21 }
22
23 public override void Run (string[] _params)
24 {
25 try {
26 if (_params.Length != 4) {
27 m_Console.SendResult ("Usage: teleportplayer <entityid|playername|steamid> <x> <y> <z>");
28 } else {
29 string steamid = PersistentContainer.Instance.Players.GetSteamID (_params [0], true);
30 if (steamid == null) {
31 m_Console.SendResult ("Playername or entity/steamid id not found.");
32 return;
33 }
34
35 Player p = PersistentContainer.Instance.Players [steamid];
36 if (!p.IsOnline) {
37 m_Console.SendResult ("Player not online.");
38 return;
39 }
40
41 int x = int.MinValue;
42 int.TryParse (_params [1], out x);
43 int y = int.MinValue;
44 int.TryParse (_params [2], out y);
45 int z = int.MinValue;
46 int.TryParse (_params [3], out z);
47
48 if (x == int.MinValue || y == int.MinValue || z == int.MinValue) {
49 m_Console.SendResult ("At least one of the given coordinates is not a valid integer");
50 return;
51 }
52
53 p.Entity.position.x = x;
54 p.Entity.position.y = y;
55 p.Entity.position.z = z;
56 NetPackage_EntityPosAndRot pkg = new NetPackage_EntityPosAndRot(p.Entity);
57
58 p.ClientInfo.netConnection[0].mdv0005(pkg);
59 }
60 } catch (Exception e) {
61 Log.Out ("Error in TeleportPlayer.Run: " + e);
62 }
63 }
64 }
65}
Note: See TracBrowser for help on using the repository browser.