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; } } }
public void Execute(IRocketPlayer caller, string[] command) { if (command.Length == 0) { UnturnedChat.Say(caller, TeleportUtil.Instance.Translate("tpto_help")); return; } if (command.Length > 3) { UnturnedChat.Say(caller, TeleportUtil.Instance.Translate("invalid_arg")); return; } // Don't allow teleport if the player is in a car. UnturnedPlayer unturnedCaller = (UnturnedPlayer)caller; InteractableVehicle vehicle = null; Vector3 newLocation; if (unturnedCaller.IsInVehicle) { vehicle = unturnedCaller.CurrentVehicle; newLocation = vehicle.transform.position; } else { newLocation = unturnedCaller.Position; } // Parse through the list of parameters, and compute new location. foreach (string part in command) { if (part.Length < 2) { UnturnedChat.Say(caller, TeleportUtil.Instance.Translate("invalid_arg")); return; } float distance; if (!float.TryParse(part.Substring(1, part.Length - 1), out distance)) { UnturnedChat.Say(caller, TeleportUtil.Instance.Translate("invalid_arg")); return; } switch (part.Substring(0, 1).ToLower()) { case "u": newLocation.y += distance; break; case "d": newLocation.y -= distance; break; case "n": newLocation.z += distance; break; case "s": newLocation.z -= distance; break; case "e": newLocation.x += distance; break; case "w": newLocation.x -= distance; break; default: UnturnedChat.Say(caller, TeleportUtil.Instance.Translate("invalid_arg")); return; } } if (unturnedCaller.IsInVehicle) { 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 { unturnedCaller.Teleport(newLocation, unturnedCaller.Rotation); UnturnedChat.Say(caller, TeleportUtil.Instance.Translate("tp_success", newLocation.xyz_Location())); } }