Fixed #53, minor improvements

This commit is contained in:
ElPumpo
2018-07-24 15:08:51 +02:00
parent cb94b283f3
commit 2f0fcbceaa
2 changed files with 78 additions and 88 deletions
+17 -1
View File
@@ -1,6 +1,7 @@
ESX = nil
local Categories = {}
local Vehicles = {}
local hasSqlRun = false
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
@@ -14,7 +15,13 @@ function RemoveOwnedVehicle (plate)
})
end
AddEventHandler('onMySQLReady', function ()
AddEventHandler('onMySQLReady', function()
LoadVehicles()
end)
function LoadVehicles()
hasSqlRun = true
Categories = MySQL.Sync.fetchAll('SELECT * FROM vehicle_categories')
local vehicles = MySQL.Sync.fetchAll('SELECT * FROM vehicles')
@@ -30,6 +37,15 @@ AddEventHandler('onMySQLReady', function ()
table.insert(Vehicles, vehicle)
end
end
-- extremely useful when restarting script mid-game
Citizen.CreateThread(function()
Citizen.Wait(100) -- hopefully enough for connection to the SQL server
if not hasSqlRun then
LoadVehicles()
end
end)
RegisterServerEvent('esx_vehicleshop:setVehicleOwned')