public void UnparkCommand(Client player, int vehicleId) { VehicleModel vehicle = GetParkedVehicleById(vehicleId); if (vehicle == null) { // There's no vehicle with that identifier player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.vehicle_not_exists); } else if (!Vehicles.HasPlayerVehicleKeys(player, vehicle)) { player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.not_car_keys); } else { // Get the closest parking ParkingModel parking = parkingList.Where(p => player.Position.DistanceTo(p.position) < 2.5f).FirstOrDefault(); if (parking == null) { // Player's not in any parking player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.not_parking_near); return; } // Check whether the vehicle is in this parking if (parking.id != vehicle.parking) { // The vehicle is not in this parking player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.vehicle_not_this_parking); return; } int playerMoney = player.GetSharedData(EntityData.PLAYER_MONEY); switch (parking.type) { case Constants.PARKING_TYPE_DEPOSIT: // Remove player's money if (playerMoney >= Constants.PRICE_PARKING_DEPOSIT) { player.SetSharedData(EntityData.PLAYER_MONEY, playerMoney - Constants.PRICE_PARKING_DEPOSIT); string message = string.Format(InfoRes.unpark_money, Constants.PRICE_PARKING_DEPOSIT); player.SendChatMessage(Constants.COLOR_INFO + message); } else { string message = string.Format(ErrRes.parking_not_money, Constants.PRICE_PARKING_DEPOSIT); player.SendChatMessage(Constants.COLOR_ERROR + message); return; } break; default: player.SendChatMessage(Constants.COLOR_INFO + InfoRes.vehicle_unparked); break; } // Set the values to unpark the vehicle vehicle.dimension = player.Dimension; vehicle.position = parking.position; vehicle.parking = 0; vehicle.parked = 0; // Recreate the vehicle Vehicle newVehicle = Vehicles.CreateIngameVehicle(vehicle); // Update parking values newVehicle.SetData(EntityData.VEHICLE_DIMENSION, 0); newVehicle.SetData(EntityData.VEHICLE_PARKING, 0); newVehicle.SetData(EntityData.VEHICLE_PARKED, 0); // Unlink from the parking parkedCars.Remove(GetParkedVehicle(vehicleId)); } }