From 5545650dd5794717a6237bb7887218fcfe0abd92 Mon Sep 17 00:00:00 2001 From: Andyyy7666 <86536434+Andyyy7666@users.noreply.github.com> Date: Tue, 27 Feb 2024 23:13:40 +0100 Subject: [PATCH] feat: impound non parked vehicles --- server/vehicle.lua | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/server/vehicle.lua b/server/vehicle.lua index 54d6849..3c7e50e 100644 --- a/server/vehicle.lua +++ b/server/vehicle.lua @@ -730,3 +730,30 @@ lib.callback.register("ND_Vehicles:getOwnedVehicles", function(src) if not player then return end return NDCore.getVehicles(player.id) end) + +AddEventHandler("ND:characterLoaded", function(player) + local ownedExistingVehicles = {} + local ownedVehicles = NDCore.getVehicles(player.id) + local vehicles = GetAllVehicles() + local vehiclesToImpound = {} + + for i=1, #vehicles do + local veh = vehicles[i] + local state = Entity(veh).state + if state.owner == player.id then + ownedExistingVehicles[#ownedExistingVehicles+1] = state.id + end + end + + for i=1, #ownedVehicles do + local veh = ownedVehicles[i] + if veh and not veh.stored and not veh.impounded and not lib.table.contains(ownedExistingVehicles, veh.id) then + vehiclesToImpound[#vehiclesToImpound+1] = veh.id + end + end + + if #vehiclesToImpound == 0 then return end + + local query = ("UPDATE nd_vehicles SET impounded = ? WHERE owner = ? AND id IN (%s)"):format(table.concat(vehiclesToImpound, ", ")) + MySQL.rawExecute(query, {1, player.id}) +end)