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

Last change on this file since 197 was 189, checked in by alloc, 10 years ago

fixes

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