forked from cartman-2000/TeleportUtil
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CommandTprel.cs
93 lines (85 loc) · 3.29 KB
/
CommandTprel.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using System.Collections.Generic;
using Rocket.API;
using Rocket.Unturned.Chat;
using Rocket.Unturned.Player;
using UnityEngine;
using SDG.Unturned;
using Rocket.API.Extensions;
namespace TeleportUtil
{
public class CommandTprel : IRocketCommand
{
public static string help = "Teleport to x,y,z coords relative to yourself.";
public static string syntax = "<x> <y> <z>";
public AllowedCaller AllowedCaller
{
get { return AllowedCaller.Player; }
}
public string Name
{
get { return "tprel"; }
}
public string Help
{
get { return help; }
}
public string Syntax
{
get { return syntax; }
}
public List<string> Aliases
{
get { return new List<string>(); }
}
public List<string> Permissions
{
get { return new List<string>() { "TeleportUtil.tprel" }; }
}
public void Execute(IRocketPlayer caller, string[] command)
{
if (command.Length == 0)
{
UnturnedChat.Say(caller, TeleportUtil.Instance.Translate("tprel_help"));
return;
}
// Only allow the command to be ran with all three parameters.
if (command.Length != 3)
{
UnturnedChat.Say(caller, TeleportUtil.Instance.Translate("invalid_arg"));
return;
}
else
{
float? x = command.GetFloatParameter(0);
float? y = command.GetFloatParameter(1);
float? z = command.GetFloatParameter(2);
UnturnedPlayer unturnedCaller = (UnturnedPlayer)caller;
Vector3 newLocation;
if (x.HasValue && y.HasValue && z.HasValue)
{
// Compute new location from the relative location parameters entered into the command.
if (unturnedCaller.IsInVehicle)
{
InteractableVehicle vehicle = unturnedCaller.CurrentVehicle;
newLocation = new Vector3(vehicle.transform.position.x + x.Value, vehicle.transform.position.y + y.Value, vehicle.transform.position.z + z.Value);
if (vehicle.TeleportCar(unturnedCaller, newLocation))
UnturnedChat.Say(caller, TeleportUtil.Instance.Translate("tp_success", newLocation.xyz_Location()));
else
UnturnedChat.Say(caller, TeleportUtil.Instance.Translate("tp_fail_vehicle"));
}
else
{
newLocation = new Vector3(unturnedCaller.Position.x + x.Value, unturnedCaller.Position.y + y.Value, unturnedCaller.Position.z + z.Value);
unturnedCaller.Teleport(newLocation, unturnedCaller.Rotation);
UnturnedChat.Say(caller, TeleportUtil.Instance.Translate("tp_success", newLocation.xyz_Location()));
}
}
else
{
UnturnedChat.Say(caller, TeleportUtil.Instance.Translate("invalid_arg"));
return;
}
}
}
}
}