From a5a9290b5d17e9ee5c146ee078f1d50bf7d601a6 Mon Sep 17 00:00:00 2001 From: Andyyy7666 <86536434+Andyyy7666@users.noreply.github.com> Date: Wed, 27 Sep 2023 00:22:57 +0200 Subject: [PATCH] update(vehicle): impound check & reclaiming --- client/vehicle/garages.lua | 36 ++++++++++++++++++++++-------------- server/vehicle.lua | 28 ++++++++++++++++++++++++++-- 2 files changed, 48 insertions(+), 16 deletions(-) diff --git a/client/vehicle/garages.lua b/client/vehicle/garages.lua index 110c65a..09c3536 100644 --- a/client/vehicle/garages.lua +++ b/client/vehicle/garages.lua @@ -142,11 +142,13 @@ local function parkVehicle(veh) TriggerServerEvent("ND_Vehicles:storeVehicle", VehToNet(veh)) end -local function isVehicleClassForGarage(class, garageType) - if not class then return true end +local function isVehicleAvailable(vehicle, garageType, impound) + local class = vehicle.properties.class + local available = vehicle.available and not impound or vehicle.impounded and impound + if available and not garageTypes[garageType] then return true end + for garType, garClass in pairs(garageTypes) do - print(garType, garageType, garClass, class) - if garType == garageType and garClass == class then + if available and garType == garageType and garClass == class then return true end end @@ -200,24 +202,30 @@ local function createMenuOptions(vehicle, vehicleSpawns) } end -local function createMenu(vehicles, garageType, vehicleSpawns) - local options = { - { +local function createMenu(vehicles, garageType, vehicleSpawns, impound) + local options = {} + if not impound then + options[#options+1] = { title = "Park vehicle", onSelect = function(args) local veh = getClosestOwnedVehicle() parkVehicle(veh) end } - } + end for _, vehicle in ipairs(vehicles) do - if vehicle.available and isVehicleClassForGarage(vehicle.properties.class, garageType) then + if isVehicleAvailable(vehicle, garageType, impound) then options[#options+1] = createMenuOptions(vehicle, vehicleSpawns) end end + if impound and #options == 0 then + options[#options+1] = { + title = "No vehicles found", + } + end return { id = ("garage_%s"):format(garageType), - title = "Parking garage", + title = impound and "Vehicle impound" or "Parking garage", options = options, onExit = function() garageOpen = false @@ -233,8 +241,8 @@ for i=1, #locations do distance = 45.0, clothing = clothing[math.random(1, #clothing)], blip = { - label = ("Parking garage (%s)"):format(location.garageType), - sprite = sprite[location.garageType], + label = location.impound and ("Impound (%s)"):format(location.garageType) or ("Parking garage (%s)"):format(location.garageType), + sprite = location.impound and 285 or sprite[location.garageType], scale = 0.7, color = 3, groups = location.groups @@ -247,7 +255,7 @@ for i=1, #locations do { name = "nd_core:garagePed", icon = "fa-solid fa-warehouse", - label = "View garage", + label = location.impound and "View impounded vehicles" or "View garage", distance = 2.0, canInteract = function(entity, distance, coords, name, bone) if not location.groups then return true end @@ -261,7 +269,7 @@ for i=1, #locations do end, onSelect = function(data) local vehicles = lib.callback.await("ND_Vehicles:getOwnedVehicles") or {} - local menu = createMenu(vehicles, location.garageType, location.vehicleSpawns) + local menu = createMenu(vehicles, location.garageType, location.vehicleSpawns, location.impound) lib.registerContext(menu) lib.showContext(menu.id) end diff --git a/server/vehicle.lua b/server/vehicle.lua index 2cafc5d..c932c7f 100644 --- a/server/vehicle.lua +++ b/server/vehicle.lua @@ -199,7 +199,7 @@ function NDCore.giveVehicleAccess(source, vehicle, access, info) vehId = vehicleId, vehNetId = netId }) - + if access and not hasKey then ox_inventory:AddItem(source, "keys", 1, { vehOwner = owner or state.owner, @@ -650,7 +650,31 @@ end RegisterNetEvent("ND_Vehicles:takeVehicle", function(vehId, locations) local src = source - local info = NDCore.spawnOwnedVehicle(src, vehId, isParkingAvailable(locations)) + local vehicle = NDCore.getVehicleById(vehId) + local player = NDCore.getPlayer(src) + if not player or not vehicle or vehicle.owner ~= player.id then return end + if vehicle.impounded then + local reclaimPrice = 200 + if player.deductMoney("bank", reclaimPrice, "Vehicle impound reclaim") then + MySQL.query("UPDATE nd_vehicles SET impounded = ? WHERE id = ?", {0, vehicle.id}) + player.notify({ + title = "Impound", + description = ("Paid $%d to reclaim vehicle!"):format(reclaimPrice), + type = "success", + position = "bottom" + }) + else + player.notify({ + title = "Impound", + description = ("Price to reclaim is $%d, you don't have enough!"):format(reclaimPrice), + type = "error", + position = "bottom" + }) + end + end + + local info = NDCore.spawnOwnedVehicle(src, vehicle.id, isParkingAvailable(locations)) + if not info then return end TriggerClientEvent("ND_Vehicles:blip", src, info.netId, true) end)