Skip to content

Commit

Permalink
Updated to work on Rocket mod v4.6.
Browse files Browse the repository at this point in the history
  • Loading branch information
cartman-2000 committed Jul 28, 2015
1 parent 8cc8d47 commit 0a198e3
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 149 deletions.
66 changes: 36 additions & 30 deletions CommandLocate.cs
@@ -1,68 +1,74 @@
using System;
using System.Collections.Generic;
using Rocket.API;
using Rocket.Unturned.Chat;
using Rocket.Unturned.Commands;
using Rocket.Unturned.Player;
using Rocket.Unturned;


namespace TeleportUtil
{
public class CommandLocate : IRocketCommand
{
public bool AllowFromConsole
{
get { return true; }
}

public string Name
{
get { return "locate"; }
}

public string Help
{
get { return "Prints out the location of a player on the map for usage in the /tp command."; }
}

public string Syntax
{
get { return "[\"name\"]"; }
}

public List<string> Aliases
{
get { return new List<string>(); }
}

public void Execute(RocketPlayer caller, string[] command)
public List<string> Permissions
{
get { return new List<string>() { "TeleportUtil.locate" }; }
}

public void Execute(IRocketPlayer caller, string[] command)
{
if ((caller == null && command.Length < 1) || command.Length > 1)
if ((caller is ConsolePlayer && command.Length < 1) || command.Length > 1)
{
RocketChat.Say(caller, TeleportUtil.Instance.Translate("can't_locate_player", new object[] {}));
UnturnedChat.Say(caller, TeleportUtil.Instance.Translate("can't_locate_player"));
return;
}
if (command.Length == 1)
{
if (!caller.HasPermission("locate.other"))
{
RocketChat.Say(caller, TeleportUtil.Instance.Translate("locate_other_not_allowed", new object[] { }));
UnturnedChat.Say(caller, TeleportUtil.Instance.Translate("locate_other_not_allowed"));
return;
}
RocketPlayer target = RocketPlayer.FromName(command[0]);
UnturnedPlayer target = command.GetUnturnedPlayerParameter(0);
if (target == null)
{
RocketChat.Say(caller, TeleportUtil.Instance.Translate("can't_locate_player", new object[] { }));
UnturnedChat.Say(caller, TeleportUtil.Instance.Translate("can't_locate_player"));
return;
}
else
{
RocketChat.Say(caller, TeleportUtil.Instance.Translate("location_on_map_other", new object[] { target.CharacterName.Truncate(14), Math.Round(target.Position.x, 2), Math.Round(target.Position.y, 2), Math.Round(target.Position.z, 2) }));
UnturnedChat.Say(caller, TeleportUtil.Instance.Translate("location_on_map_other", target.CharacterName.Truncate(14), Math.Round(target.Position.x, 2), Math.Round(target.Position.y, 2), Math.Round(target.Position.z, 2)));
}
}
else
{
RocketChat.Say(caller, TeleportUtil.Instance.Translate("location_on_map", new object[] { Math.Round(caller.Position.x, 2), Math.Round(caller.Position.y, 2), Math.Round(caller.Position.z, 2) }));
UnturnedPlayer unturnedCaller = UnturnedPlayer.FromName(caller.Id);
UnturnedChat.Say(caller, TeleportUtil.Instance.Translate("location_on_map", Math.Round(unturnedCaller.Position.x, 2), Math.Round(unturnedCaller.Position.y, 2), Math.Round(unturnedCaller.Position.z, 2)));
}
}

public string Help
{
get { return "Prints out the location of a player on the map for usage in the /tp command."; }
}

public string Name
{
get { return "locate"; }
}

public bool RunFromConsole
{
get { return true; }
}

public string Syntax
{
get { return "[\"name\"]"; }
}
}
}
70 changes: 38 additions & 32 deletions CommandTprel.cs
@@ -1,31 +1,57 @@
using System;
using System.Collections.Generic;
using Rocket.Unturned;
using Rocket.API;
using Rocket.Unturned.Chat;
using Rocket.Unturned.Commands;
using Rocket.Unturned.Player;
using UnityEngine;
using SDG.Unturned;


namespace TeleportUtil
{
public class CommandTprel : IRocketCommand
{
public System.Collections.Generic.List<string> Aliases
public bool AllowFromConsole
{
get { return false; }
}

public string Name
{
get { return "tprel"; }
}

public string Help
{
get { return "Teleport to x,y,z coords relative to yourself."; }
}

public string Syntax
{
get { return "<x> <y> <z>"; }
}

public List<string> Aliases
{
get { return new List<string>(); }
}

public void Execute(RocketPlayer caller, string[] command)
public List<string> Permissions
{
get { return new List<string>() { "TeleportUtil.tprel" }; }
}

public void Execute(IRocketPlayer caller, string[] command)
{
UnturnedPlayer unturnedCaller = UnturnedPlayer.FromName(caller.Id);
if (command.Length == 0)
{
RocketChat.Say(caller, TeleportUtil.Instance.Translate("tprel_help", new object[] { }));
UnturnedChat.Say(caller, TeleportUtil.Instance.Translate("tprel_help", new object[] { }));
return;
}
if (command.Length != 3)
{
RocketChat.Say(caller, TeleportUtil.Instance.Translate("invalid_arg", new object[] { }));
UnturnedChat.Say(caller, TeleportUtil.Instance.Translate("invalid_arg", new object[] { }));
return;
}
else
Expand All @@ -36,41 +62,21 @@ public void Execute(RocketPlayer caller, string[] command)

if (x.HasValue && y.HasValue && z.HasValue)
{
if (caller.Stance == EPlayerStance.DRIVING)
if (unturnedCaller.Stance == EPlayerStance.DRIVING || unturnedCaller.Stance == EPlayerStance.SITTING)
{
RocketChat.Say(caller, TeleportUtil.Instance.Translate("tp_fail", new object[] { }));
UnturnedChat.Say(caller, TeleportUtil.Instance.Translate("tp_fail", new object[] { }));
return;
}
Vector3 newLocation = new Vector3(caller.Position.x + x.Value, caller.Position.y + y.Value, caller.Position.z + z.Value);
caller.Teleport(newLocation, caller.Rotation);
RocketChat.Say(caller, TeleportUtil.Instance.Translate("tp_success", new object[] { Math.Round(newLocation.x, 2), Math.Round(newLocation.y, 2), Math.Round(newLocation.z, 2) }));
Vector3 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", new object[] { Math.Round(newLocation.x, 2), Math.Round(newLocation.y, 2), Math.Round(newLocation.z, 2) }));
}
else
{
RocketChat.Say(caller, TeleportUtil.Instance.Translate("invalid_arg", new object[] { }));
UnturnedChat.Say(caller, TeleportUtil.Instance.Translate("invalid_arg", new object[] { }));
return;
}
}
}

public string Help
{
get { return "Teleport to x,y,z coords relative to yourself."; }
}

public string Name
{
get { return "tprel"; }
}

public bool RunFromConsole
{
get { return false; }
}

public string Syntax
{
get { return "<x> <y> <z>"; }
}
}
}
74 changes: 40 additions & 34 deletions CommandTpto.cs
@@ -1,49 +1,75 @@
using System;
using System.Collections.Generic;
using Rocket.Unturned.Commands;
using Rocket.Unturned.Player;
using Rocket.Unturned;
using UnityEngine;
using SDG.Unturned;
using Rocket.API;
using Rocket.Unturned.Chat;
using Rocket.Unturned.Player;

namespace TeleportUtil
{
public class CommandTpto : IRocketCommand
{
public bool AllowFromConsole
{
get { return false; }
}

public string Name
{
get { return "tpto"; }
}

public string Help
{
get { return "Teleport by direction:distance."; }
}

public string Syntax
{
get { return "[<u|d|n|s|w|e>distance] [...] [...]"; }
}

public List<string> Aliases
{
get { return new List<string>(); }
}

public void Execute(RocketPlayer caller, string[] command)
public List<string> Permissions
{
get { return new List<string>() { "TeleportUtil.tpto" }; }
}

public void Execute(IRocketPlayer caller, string[] command)
{
UnturnedPlayer unturnedCaller = UnturnedPlayer.FromName(caller.Id);
if (command.Length == 0)
{
RocketChat.Say(caller, TeleportUtil.Instance.Translate("tpto_help", new object[] { }));
UnturnedChat.Say(caller, TeleportUtil.Instance.Translate("tpto_help", new object[] { }));
return;
}
if (command.Length > 3)
{
RocketChat.Say(caller, TeleportUtil.Instance.Translate("invalid_arg", new object[] { }));
UnturnedChat.Say(caller, TeleportUtil.Instance.Translate("invalid_arg", new object[] { }));
return;
}
if (caller.Stance == EPlayerStance.DRIVING)
if (unturnedCaller.Stance == EPlayerStance.DRIVING || unturnedCaller.Stance == EPlayerStance.SITTING)
{
RocketChat.Say(caller, TeleportUtil.Instance.Translate("tp_fail", new object[] { }));
UnturnedChat.Say(caller, TeleportUtil.Instance.Translate("tp_fail", new object[] { }));
return;
}
Vector3 newLocation = caller.Position;
Vector3 newLocation = unturnedCaller.Position;
foreach (string part in command)
{
if (part.Length < 2)
{
RocketChat.Say(caller, TeleportUtil.Instance.Translate("invalid_arg", new object[] { }));
UnturnedChat.Say(caller, TeleportUtil.Instance.Translate("invalid_arg", new object[] { }));
return;
}
float distance;
if (!float.TryParse(part.Substring(1, part.Length - 1), out distance))
{
RocketChat.Say(caller, TeleportUtil.Instance.Translate("invalid_arg", new object[] { }));
UnturnedChat.Say(caller, TeleportUtil.Instance.Translate("invalid_arg", new object[] { }));
return;
}
switch (part.Substring(0, 1).ToLower())
Expand All @@ -67,32 +93,12 @@ public void Execute(RocketPlayer caller, string[] command)
newLocation.x -= distance;
break;
default:
RocketChat.Say(caller, TeleportUtil.Instance.Translate("invalid_arg", new object[] { }));
UnturnedChat.Say(caller, TeleportUtil.Instance.Translate("invalid_arg", new object[] { }));
return;
}
}
caller.Teleport(newLocation, caller.Rotation);
RocketChat.Say(caller, TeleportUtil.Instance.Translate("tp_success", new object[] { Math.Round(newLocation.x, 2), Math.Round(newLocation.y, 2), Math.Round(newLocation.z, 2) }));
}

public string Help
{
get { return "Teleport by direction:distance."; }
}

public string Name
{
get { return "tpto"; }
}

public bool RunFromConsole
{
get { return false; }
}

public string Syntax
{
get { return "[<u|d|n|s|w|e>distance] [...] [...]"; }
unturnedCaller.Teleport(newLocation, unturnedCaller.Rotation);
UnturnedChat.Say(caller, TeleportUtil.Instance.Translate("tp_success", new object[] { Math.Round(newLocation.x, 2), Math.Round(newLocation.y, 2), Math.Round(newLocation.z, 2) }));
}
}
}
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.0.0")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: AssemblyVersion("1.3.0.0")]
[assembly: AssemblyFileVersion("1.3.0.0")]

0 comments on commit 0a198e3

Please sign in to comment.