Skip to content

Commit

Permalink
Some code simplifacation.
Browse files Browse the repository at this point in the history
  • Loading branch information
cartman-2000 committed Jul 29, 2015
1 parent 0a198e3 commit f1cb811
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
13 changes: 5 additions & 8 deletions CommandLocate.cs
Expand Up @@ -41,32 +41,29 @@ public List<string> Permissions

public void Execute(IRocketPlayer caller, string[] command)
{
if ((caller is ConsolePlayer && command.Length < 1) || command.Length > 1)
// Get playername, if one was set in the command. Don't allow the command to be ran on self from the console.
UnturnedPlayer target = command.GetUnturnedPlayerParameter(0);
if ((caller is ConsolePlayer && command.Length < 1) || command.Length > 1 || (target == null && command.Length == 1 && caller.HasPermission("locate.other")))
{
UnturnedChat.Say(caller, TeleportUtil.Instance.Translate("can't_locate_player"));
return;
}
if (command.Length == 1)
{
// Only allow the player to locate another player if they have the right permission.
if (!caller.HasPermission("locate.other"))
{
UnturnedChat.Say(caller, TeleportUtil.Instance.Translate("locate_other_not_allowed"));
return;
}
UnturnedPlayer target = command.GetUnturnedPlayerParameter(0);
if (target == null)
{
UnturnedChat.Say(caller, TeleportUtil.Instance.Translate("can't_locate_player"));
return;
}
else
{
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
{
UnturnedPlayer unturnedCaller = UnturnedPlayer.FromName(caller.Id);
UnturnedPlayer unturnedCaller = (UnturnedPlayer)caller;
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)));
}
}
Expand Down
7 changes: 6 additions & 1 deletion CommandTprel.cs
Expand Up @@ -43,12 +43,13 @@ public List<string> Permissions

public void Execute(IRocketPlayer caller, string[] command)
{
UnturnedPlayer unturnedCaller = UnturnedPlayer.FromName(caller.Id);
if (command.Length == 0)
{
UnturnedChat.Say(caller, TeleportUtil.Instance.Translate("tprel_help", new object[] { }));
return;
}

// Only allow the command to be ran with all three parameters.
if (command.Length != 3)
{
UnturnedChat.Say(caller, TeleportUtil.Instance.Translate("invalid_arg", new object[] { }));
Expand All @@ -59,14 +60,18 @@ public void Execute(IRocketPlayer caller, string[] command)
float? x = command.GetFloatParameter(0);
float? y = command.GetFloatParameter(1);
float? z = command.GetFloatParameter(2);
UnturnedPlayer unturnedCaller = (UnturnedPlayer)caller;

if (x.HasValue && y.HasValue && z.HasValue)
{
// Don't allow the player to teleport if they are in a car.
if (unturnedCaller.Stance == EPlayerStance.DRIVING || unturnedCaller.Stance == EPlayerStance.SITTING)
{
UnturnedChat.Say(caller, TeleportUtil.Instance.Translate("tp_fail", new object[] { }));
return;
}

// Compute new location from the relative location parameters entered into the command.
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) }));
Expand Down
6 changes: 5 additions & 1 deletion CommandTpto.cs
Expand Up @@ -42,7 +42,6 @@ public List<string> Permissions

public void Execute(IRocketPlayer caller, string[] command)
{
UnturnedPlayer unturnedCaller = UnturnedPlayer.FromName(caller.Id);
if (command.Length == 0)
{
UnturnedChat.Say(caller, TeleportUtil.Instance.Translate("tpto_help", new object[] { }));
Expand All @@ -53,11 +52,16 @@ public void Execute(IRocketPlayer caller, string[] command)
UnturnedChat.Say(caller, TeleportUtil.Instance.Translate("invalid_arg", new object[] { }));
return;
}

// Don't allow teleport if the player is in a car.
UnturnedPlayer unturnedCaller = (UnturnedPlayer)caller;
if (unturnedCaller.Stance == EPlayerStance.DRIVING || unturnedCaller.Stance == EPlayerStance.SITTING)
{
UnturnedChat.Say(caller, TeleportUtil.Instance.Translate("tp_fail", new object[] { }));
return;
}

// Parse through the list of parameters, and compute new location.
Vector3 newLocation = unturnedCaller.Position;
foreach (string part in command)
{
Expand Down
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.3.0.0")]
[assembly: AssemblyFileVersion("1.3.0.0")]
[assembly: AssemblyVersion("1.3.0.1")]
[assembly: AssemblyFileVersion("1.3.0.1")]

0 comments on commit f1cb811

Please sign in to comment.