From 085c1b36997feb4c6d98b6d24ac0de41009a2faa Mon Sep 17 00:00:00 2001 From: "Alivemonstor [Jayden]" <79489495+Alivemonstor@users.noreply.github.com> Date: Thu, 19 Dec 2024 21:28:53 +0000 Subject: [PATCH 1/5] prevent saving unowned vehicles --- server/main.lua | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/server/main.lua b/server/main.lua index c6007722..f7a15831 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) From 3515e5261432afc5ba5430b61bd8576b9bd310db Mon Sep 17 00:00:00 2001 From: "Alivemonstor [Jayden]" <79489495+Alivemonstor@users.noreply.github.com> Date: Thu, 19 Dec 2024 21:30:16 +0000 Subject: [PATCH 2/5] add function for saving --- server/functions.lua | 7 +++++++ 1 file changed, 7 insertions(+) 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) From 65680bf7ef93df4c85b232e7bc6792716caa699b Mon Sep 17 00:00:00 2001 From: "Alivemonstor [Jayden]" <79489495+Alivemonstor@users.noreply.github.com> Date: Thu, 19 Dec 2024 22:55:36 +0000 Subject: [PATCH 3/5] lint --- server/main.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/main.lua b/server/main.lua index f7a15831..f11c1966 100644 --- a/server/main.lua +++ b/server/main.lua @@ -45,7 +45,7 @@ end) AddEventHandler('txAdmin:events:serverShuttingDown', function() for inventory, data in pairs(Inventories) do if data.isOpen then - if (inventory:find('glovebox%-') and IsVehicleOwned(inventory:match('glovebox%-(.+)'))) or (inventory:find('trunk%-') and IsVehicleOwned(inventory:match('trunk%-(.+)'))) then + 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) }) @@ -179,11 +179,11 @@ RegisterNetEvent('qb-inventory:server:closeInventory', function(inventory) if not Inventories[inventory] then return end Inventories[inventory].isOpen = false - if inventory:find('glovebox%-') then + if inventory:find('glovebox%-') then if not IsVehicleOwned(inventory:match('glovebox%-(.+)')) then return end end - if inventory:find('trunk%-') then + if inventory:find('trunk%-') then if not IsVehicleOwned(inventory:match('trunk%-(.+)')) then return end end From ac09f0601b655cc708ac842997ce811eb3529aef Mon Sep 17 00:00:00 2001 From: "Alivemonstor [Jayden]" <79489495+Alivemonstor@users.noreply.github.com> Date: Sat, 28 Dec 2024 02:18:17 +0000 Subject: [PATCH 4/5] if weapon isnt called weapon --- server/functions.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/functions.lua b/server/functions.lua index 6b966d47..7c4afb3b 100644 --- a/server/functions.lua +++ b/server/functions.lua @@ -752,7 +752,7 @@ function AddItem(identifier, item, amount, slot, info, reason) combinable = itemInfo.combinable } - if QBCore.Shared.SplitStr(item, '_')[1] == 'weapon' then + if itemInfo.type == 'weapon' then if not inventory[slot].info.serie then inventory[slot].info.serie = tostring(QBCore.Shared.RandomInt(2) .. QBCore.Shared.RandomStr(3) .. QBCore.Shared.RandomInt(1) .. QBCore.Shared.RandomStr(2) .. QBCore.Shared.RandomInt(3) .. QBCore.Shared.RandomStr(4)) end From 58fef57ab214c6755e1efac58ef88f9475caf8f6 Mon Sep 17 00:00:00 2001 From: "Alivemonstor [Jayden]" <79489495+Alivemonstor@users.noreply.github.com> Date: Sat, 28 Dec 2024 02:21:10 +0000 Subject: [PATCH 5/5] Revert "if weapon isnt called weapon" This reverts commit ac09f0601b655cc708ac842997ce811eb3529aef. --- server/functions.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/functions.lua b/server/functions.lua index 7c4afb3b..6b966d47 100644 --- a/server/functions.lua +++ b/server/functions.lua @@ -752,7 +752,7 @@ function AddItem(identifier, item, amount, slot, info, reason) combinable = itemInfo.combinable } - if itemInfo.type == 'weapon' then + if QBCore.Shared.SplitStr(item, '_')[1] == 'weapon' then if not inventory[slot].info.serie then inventory[slot].info.serie = tostring(QBCore.Shared.RandomInt(2) .. QBCore.Shared.RandomStr(3) .. QBCore.Shared.RandomInt(1) .. QBCore.Shared.RandomStr(2) .. QBCore.Shared.RandomInt(3) .. QBCore.Shared.RandomStr(4)) end