Skip to content

Commit

Permalink
fix: logout support
Browse files Browse the repository at this point in the history
* fixed multiple logout/login bug

* Update client/main.lua

Co-authored-by: Manason <[email protected]>

* Update client/main.lua

Co-authored-by: Manason <[email protected]>

---------

Co-authored-by: Manason <[email protected]>
  • Loading branch information
abdel1touimi and Manason authored Oct 22, 2023
1 parent 5720139 commit ebc4e61
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit ebc4e61

Please sign in to comment.