/// <summary> /// Removes the vehicle. /// </summary> /// <param name="licencedPlayer">The licenced player.</param> /// <param name="vehicleSettings">The vehicle settings.</param> private void RemoveVehicle(LicencedPlayer licencedPlayer, VehicleSettings vehicleSettings) { var player = licencedPlayer.Player; var vehicle = licencedPlayer.GetVehicle(vehicleSettings.prefab); if (player != null && vehicle == null) { SendReply(player, string.Format(Msg("vehicleNotYetPurchased", player.UserIDString), vehicleSettings.name)); } else { var vehicleId = vehicle.Id; _vehiclesCache.Remove(vehicle.Id); BaseNetworkable.serverEntities.Find(vehicle.Id)?.Kill(); vehicle.Id = 0; licencedPlayer.SetVehicle(vehicle); if (player != null && vehicleId != 0) { SendReply(player, string.Format(Msg("vehicleRecalled", player.UserIDString), vehicleSettings.name)); } else if (player != null && vehicleId == 0) { SendReply(player, string.Format(Msg("vehicleNotOut", player.UserIDString), vehicleSettings.name)); } } }
/// <summary> /// Buys the vehicle. /// </summary> /// <param name="player">The player.</param> /// <param name="licencedPlayer">The licenced player.</param> /// <param name="prefab">The prefab.</param> private void BuyVehicle(BasePlayer player, LicencedPlayer licencedPlayer, string prefab) { Vehicle vehicle; var vehicleSettings = GetVehicleSettings(prefab); if (licencedPlayer.Vehicles.TryGetValue(prefab, out vehicle)) { SendReply(player, string.Format(Msg("vehicleAlreadyPurchased", player.UserIDString), vehicleSettings.name)); } else if (vehicleSettings.name != "null" && vehicleSettings.purchasable) { if (Withdraw(player, vehicleSettings)) { vehicle = new Vehicle(prefab, player.userID); licencedPlayer.SetVehicle(vehicle); } } else { SendReply(player, string.Format(Msg("vehicleCannotBeBuyed", player.UserIDString), vehicleSettings.name)); } }
/// <summary> /// Spawns the vehicle. /// </summary> /// <param name="licencedPlayer">The licenced player.</param> /// <param name="prefab">The prefab.</param> /// <returns></returns> private BaseEntity SpawnVehicle(LicencedPlayer licencedPlayer, string prefab) { var player = licencedPlayer.Player; if (player == null) { return(null); } var vehicleSettings = GetVehicleSettings(prefab); var vehicle = licencedPlayer.GetVehicle(prefab); if (vehicle == null) { return(null); } var position = player.transform.position + new Vector3(0f, 1.6f, 0f); var rotation = player.transform.rotation; BaseEntity entity = GameManager.server.CreateEntity(vehicle.Prefab, position + (Vector3.forward * vehicleSettings.distanceToSpawn), rotation); if (entity == null) { return(null); } entity.enableSaving = true; entity.Spawn(); if (entity.net == null) { return(null); } vehicle.Spawned = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0)); vehicle.Id = entity.net.ID; vehicle.LastDismount = DateTime.UtcNow; _vehiclesCache.Add(vehicle.Id, vehicle); licencedPlayer.SetVehicle(vehicle); SendReply(player, string.Format(Msg("vehicleSpawned", player.UserIDString), vehicleSettings.name)); return(entity); }