From ebc4e61b407ac7c10ca8ba90ae3cf8e5af99da93 Mon Sep 17 00:00:00 2001 From: Abdelouahed TOUIMI Date: Sun, 22 Oct 2023 21:04:41 +0100 Subject: [PATCH] fix: logout support * fixed multiple logout/login bug * Update client/main.lua Co-authored-by: Manason * Update client/main.lua Co-authored-by: Manason --------- Co-authored-by: Manason --- client/main.lua | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/client/main.lua b/client/main.lua index 2b601d4..a02fd21 100644 --- a/client/main.lua +++ b/client/main.lua @@ -534,6 +534,8 @@ local function createShowroomVehicle(model, coords) end --- Initial function to set things up. Creating vehicleshops defined in the config and spawns the sellable vehicles +local shopVehs = {} + local function init() CreateThread(function() for name, shop in pairs(Config.Shops) do @@ -561,6 +563,7 @@ local function init() for i = 1, #showroomVehicles do local showroomVehicle = showroomVehicles[i] local veh = createShowroomVehicle(showroomVehicle.defaultVehicle, showroomVehicle.coords) + shopVehs[#shopVehs+1] = veh if Config.UsingTarget then createVehicleTarget(shopName, veh) else @@ -579,6 +582,13 @@ AddEventHandler('QBCore:Client:OnPlayerLoaded', function() init() end) +AddEventHandler('QBCore:Client:OnPlayerUnload', function() + for i = 1, #shopVehs do + DeleteEntity(shopVehs[i]) + end + shopVehs = {} +end) + --- Starts the test drive. If vehicle parameter is not provided then the test drive will start with the closest vehicle to the player. --- @param args table RegisterNetEvent('qb-vehicleshop:client:TestDrive', function(args) @@ -615,7 +625,7 @@ RegisterNetEvent('qb-vehicleshop:client:swapVehicle', function(data) local veh = createShowroomVehicle(data.toVehicle, dataClosestVehicle.coords) Config.Shops[shopName].ShowroomVehicles[data.ClosestVehicle].chosenVehicle = data.toVehicle - + if Config.UsingTarget then createVehicleTarget(shopName, veh) end end)