diff --git a/server/functions.lua b/server/functions.lua index 1307990a..6b966d47 100644 --- a/server/functions.lua +++ b/server/functions.lua @@ -20,6 +20,7 @@ local function GetFirstFreeSlot(items, maxSlots) return nil end + local function SetupShopItems(shopItems) local items = {} local slot = 1 @@ -48,6 +49,12 @@ local function SetupShopItems(shopItems) return items end +function IsVehicleOwned(plate) + local result = MySQL.scalar.await('SELECT 1 from player_vehicles WHERE plate = ?', { plate }) + if result then return true end + return false +end + -- Exported Functions function LoadInventory(source, citizenid) diff --git a/server/main.lua b/server/main.lua index c6007722..f11c1966 100644 --- a/server/main.lua +++ b/server/main.lua @@ -45,7 +45,11 @@ end) AddEventHandler('txAdmin:events:serverShuttingDown', function() for inventory, data in pairs(Inventories) do if data.isOpen then - MySQL.prepare('INSERT INTO inventories (identifier, items) VALUES (?, ?) ON DUPLICATE KEY UPDATE items = ?', { inventory, json.encode(data.items), json.encode(data.items) }) + if (inventory:find('glovebox%-') and IsVehicleOwned(inventory:match('glovebox%-(.+)'))) or (inventory:find('trunk%-') and IsVehicleOwned(inventory:match('trunk%-(.+)'))) then + MySQL.prepare('INSERT INTO inventories (identifier, items) VALUES (?, ?) ON DUPLICATE KEY UPDATE items = ?', { inventory, json.encode(data.items), json.encode(data.items) }) + else + MySQL.prepare('INSERT INTO inventories (identifier, items) VALUES (?, ?) ON DUPLICATE KEY UPDATE items = ?', { inventory, json.encode(data.items), json.encode(data.items) }) + end end end end) @@ -174,6 +178,15 @@ RegisterNetEvent('qb-inventory:server:closeInventory', function(inventory) end if not Inventories[inventory] then return end Inventories[inventory].isOpen = false + + if inventory:find('glovebox%-') then + if not IsVehicleOwned(inventory:match('glovebox%-(.+)')) then return end + end + + if inventory:find('trunk%-') then + if not IsVehicleOwned(inventory:match('trunk%-(.+)')) then return end + end + MySQL.prepare('INSERT INTO inventories (identifier, items) VALUES (?, ?) ON DUPLICATE KEY UPDATE items = ?', { inventory, json.encode(Inventories[inventory].items), json.encode(Inventories[inventory].items) }) end)