update(vehicle): impound check & reclaiming

This commit is contained in:
Andyyy7666
2023-09-27 00:22:57 +02:00
parent 83212d45c2
commit a5a9290b5d
2 changed files with 48 additions and 16 deletions

View File

@@ -142,11 +142,13 @@ local function parkVehicle(veh)
TriggerServerEvent("ND_Vehicles:storeVehicle", VehToNet(veh)) TriggerServerEvent("ND_Vehicles:storeVehicle", VehToNet(veh))
end end
local function isVehicleClassForGarage(class, garageType) local function isVehicleAvailable(vehicle, garageType, impound)
if not class then return true end 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 for garType, garClass in pairs(garageTypes) do
print(garType, garageType, garClass, class) if available and garType == garageType and garClass == class then
if garType == garageType and garClass == class then
return true return true
end end
end end
@@ -200,24 +202,30 @@ local function createMenuOptions(vehicle, vehicleSpawns)
} }
end end
local function createMenu(vehicles, garageType, vehicleSpawns) local function createMenu(vehicles, garageType, vehicleSpawns, impound)
local options = { local options = {}
{ if not impound then
options[#options+1] = {
title = "Park vehicle", title = "Park vehicle",
onSelect = function(args) onSelect = function(args)
local veh = getClosestOwnedVehicle() local veh = getClosestOwnedVehicle()
parkVehicle(veh) parkVehicle(veh)
end end
} }
} end
for _, vehicle in ipairs(vehicles) do 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) options[#options+1] = createMenuOptions(vehicle, vehicleSpawns)
end end
end end
if impound and #options == 0 then
options[#options+1] = {
title = "No vehicles found",
}
end
return { return {
id = ("garage_%s"):format(garageType), id = ("garage_%s"):format(garageType),
title = "Parking garage", title = impound and "Vehicle impound" or "Parking garage",
options = options, options = options,
onExit = function() onExit = function()
garageOpen = false garageOpen = false
@@ -233,8 +241,8 @@ for i=1, #locations do
distance = 45.0, distance = 45.0,
clothing = clothing[math.random(1, #clothing)], clothing = clothing[math.random(1, #clothing)],
blip = { blip = {
label = ("Parking garage (%s)"):format(location.garageType), label = location.impound and ("Impound (%s)"):format(location.garageType) or ("Parking garage (%s)"):format(location.garageType),
sprite = sprite[location.garageType], sprite = location.impound and 285 or sprite[location.garageType],
scale = 0.7, scale = 0.7,
color = 3, color = 3,
groups = location.groups groups = location.groups
@@ -247,7 +255,7 @@ for i=1, #locations do
{ {
name = "nd_core:garagePed", name = "nd_core:garagePed",
icon = "fa-solid fa-warehouse", icon = "fa-solid fa-warehouse",
label = "View garage", label = location.impound and "View impounded vehicles" or "View garage",
distance = 2.0, distance = 2.0,
canInteract = function(entity, distance, coords, name, bone) canInteract = function(entity, distance, coords, name, bone)
if not location.groups then return true end if not location.groups then return true end
@@ -261,7 +269,7 @@ for i=1, #locations do
end, end,
onSelect = function(data) onSelect = function(data)
local vehicles = lib.callback.await("ND_Vehicles:getOwnedVehicles") or {} 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.registerContext(menu)
lib.showContext(menu.id) lib.showContext(menu.id)
end end

View File

@@ -650,7 +650,31 @@ end
RegisterNetEvent("ND_Vehicles:takeVehicle", function(vehId, locations) RegisterNetEvent("ND_Vehicles:takeVehicle", function(vehId, locations)
local src = source 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) TriggerClientEvent("ND_Vehicles:blip", src, info.netId, true)
end) end)