diff --git a/README.md b/README.md index 0c91e4b..71aadb3 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ self.Functions.AddItem = function(item, amount, slot, info, created) itemInfo['created'] = created end -- itemInfo['created'] = time - if itemInfo["type"] == 'item' and info == nil then + if itemInfo["type"] == 'item' and (info == nil or info == '') then info = { quality = 100 } end if itemInfo == nil then @@ -38,7 +38,7 @@ self.Functions.AddItem = function(item, amount, slot, info, created) return end local amount = tonumber(amount) - local slot = tonumber(slot) or QBCore.Player.GetFirstSlotByItem(self.PlayerData.items, item) + local slot = tonumber(slot) or QBCore.Player.GetFirstSlotByItem(self.PlayerData.items, item, info) if itemInfo['type'] == 'weapon' and info == nil then 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)), @@ -71,8 +71,26 @@ self.Functions.AddItem = function(item, amount, slot, info, created) return false end ``` - - +### QBCore.Player.GetFirstSlotByItem | server/player.lua | replace with below: +```lua +function QBCore.Player.GetFirstSlotByItem(items, itemName, info) + if not items then return nil end + for slot, item in pairs(items) do + if info then + if item.name:lower() == itemName:lower() then + if tonumber(item.info.quality) == tonumber(info.quality) then + return tonumber(slot) + end + end + else + if item.name:lower() == itemName:lower() and tonumber(item.info.quality) > 0 then + return tonumber(slot) + end + end + end + return nil +end +``` ### QBCore.Player.LoadInventory | server/player.lua | replace with below: ```lua function QBCore.Player.LoadInventory(PlayerData) diff --git a/lj-inventory/client/main.lua b/lj-inventory/client/main.lua index 9704dc2..12488ae 100644 --- a/lj-inventory/client/main.lua +++ b/lj-inventory/client/main.lua @@ -63,18 +63,12 @@ local function FormatWeaponAttachments(itemdata) itemdata.name = itemdata.name:upper() if itemdata.info.attachments ~= nil and next(itemdata.info.attachments) ~= nil then for k, v in pairs(itemdata.info.attachments) do - if WeaponAttachments[itemdata.name] ~= nil then - for key, value in pairs(WeaponAttachments[itemdata.name]) do - if value.component == v.component then - item = value.item - attachments[#attachments+1] = { - attachment = key, - label = QBCore.Shared.Items[item].label - --label = value.label - } - end - end - end + attachments[#attachments+1] = { + attachment = v.item, + label = v.label, + image = QBCore.Shared.Items[v.item].image, + component = v.component + } end end return attachments @@ -330,7 +324,7 @@ RegisterNetEvent('inventory:server:RobPlayer', function(TargetId) }) end) -RegisterNetEvent('inventory:client:OpenInventory', function(PlayerAmmo, inventory, other) +RegisterNetEvent('inventory:client:OpenInventory', function(PlayerAmmo, inventory, other, id) if not IsEntityDead(PlayerPedId()) then Wait(500) ToggleHotbar(false) @@ -354,7 +348,7 @@ RegisterNetEvent('inventory:client:OpenInventory', function(PlayerAmmo, inventor maxammo = Config.MaximumAmmoValues, }) inInventory = true - end,inventory,other) + end,inventory,other, id) end end) @@ -706,30 +700,26 @@ RegisterNUICallback('RemoveAttachment', function(data, cb) local ped = PlayerPedId() local WeaponData = QBCore.Shared.Items[data.WeaponData.name] local label = QBCore.Shared.Items - local Attachment = WeaponAttachments[WeaponData.name:upper()][data.AttachmentData.attachment] + data.AttachmentData.attachment = data.AttachmentData.attachment:gsub("(.*).*_",'') QBCore.Functions.TriggerCallback('weapons:server:RemoveAttachment', function(NewAttachments) if NewAttachments ~= false then - local Attachies = {} - RemoveWeaponComponentFromPed(ped, GetHashKey(data.WeaponData.name), GetHashKey(Attachment.component)) + local attachments = {} + RemoveWeaponComponentFromPed(ped, GetHashKey(data.WeaponData.name), GetHashKey(data.AttachmentData.component)) for k, v in pairs(NewAttachments) do - for wep, pew in pairs(WeaponAttachments[WeaponData.name:upper()]) do - if v.component == pew.component then - item = pew.item - Attachies[#Attachies+1] = { - attachment = pew.item, - label = QBCore.Shared.Items[item].label, - } - end - end + attachments[#attachments+1] = { + attachment = v.item, + label = v.label, + image = QBCore.Shared.Items[v.item].image + } end local DJATA = { - Attachments = Attachies, + Attachments = attachments, WeaponData = WeaponData, } cb(DJATA) else - RemoveWeaponComponentFromPed(ped, GetHashKey(data.WeaponData.name), GetHashKey(Attachment.component)) + RemoveWeaponComponentFromPed(ped, GetHashKey(data.WeaponData.name), GetHashKey(data.AttachmentData.component)) cb({}) end end, data.AttachmentData, data.WeaponData) diff --git a/lj-inventory/server/decay.lua b/lj-inventory/server/decay.lua index 1b5822c..ccdbb7c 100644 --- a/lj-inventory/server/decay.lua +++ b/lj-inventory/server/decay.lua @@ -1,6 +1,6 @@ local QBCore = exports['qb-core']:GetCoreObject() -local TimeAllowed = 60 * 60 * 24 * 1 -- Maths for 1 day dont touch its very important and could break everything +local TimeAllowed = 60 * 2 -- Maths for 1 day dont touch its very important and could break everything function ConvertQuality(item) local StartDate = item.created local DecayRate = QBCore.Shared.Items[item.name:lower()]["decay"] ~= nil and QBCore.Shared.Items[item.name:lower()]["decay"] or 0.0 @@ -18,7 +18,7 @@ function ConvertQuality(item) return percentDone end -QBCore.Functions.CreateCallback('inventory:server:ConvertQuality', function(source, cb, inventory, other) +QBCore.Functions.CreateCallback('inventory:server:ConvertQuality', function(source, cb, inventory, other, id) local src = source local data = {} local Player = QBCore.Functions.GetPlayer(src) @@ -85,6 +85,114 @@ QBCore.Functions.CreateCallback('inventory:server:ConvertQuality', function(sour end end end +if id then + if Gloveboxes[id] then + local GlobeBoxItems = GetOwnedVehicleGloveboxItems(stash) + for k, item in pairs(GlobeBoxItems) do + if item.created then + if QBCore.Shared.Items[item.name:lower()]["decay"] ~= nil or QBCore.Shared.Items[item.name:lower()]["decay"] ~= 0 then + if item.info then + if type(item.info) == "string" then + item.info = {} + end + if item.info.quality == nil then + item.info.quality = 100 + end + else + local info = {quality = 100} + item.info = info + end + local quality = ConvertQuality(item) + if item.info.quality then + if quality < item.info.quality then + item.info.quality = quality + end + else + item.info = {quality = quality} + end + else + if item.info then + item.info.quality = 100 + else + local info = {quality = 100} + item.info = info + end + end + end + end + SaveOwnedGloveboxItems(id, GlobeBoxItems) + elseif Trunks[id] then + local trunkItems = GetOwnedVehicleItems(stash) + for k, item in pairs(trunkItems) do + if item.created then + if QBCore.Shared.Items[item.name:lower()]["decay"] ~= nil or QBCore.Shared.Items[item.name:lower()]["decay"] ~= 0 then + if item.info then + if type(item.info) == "string" then + item.info = {} + end + if item.info.quality == nil then + item.info.quality = 100 + end + else + local info = {quality = 100} + item.info = info + end + local quality = ConvertQuality(item) + if item.info.quality then + if quality < item.info.quality then + item.info.quality = quality + end + else + item.info = {quality = quality} + end + else + if item.info then + item.info.quality = 100 + else + local info = {quality = 100} + item.info = info + end + end + end + end + SaveOwnedVehicleItems(id, trunkItems) + elseif Stashes[id] then + local stashItems = GetStashItems(stash) + for k, item in pairs(stashItems) do + if item.created then + if QBCore.Shared.Items[item.name:lower()]["decay"] ~= nil or QBCore.Shared.Items[item.name:lower()]["decay"] ~= 0 then + if item.info then + if type(item.info) == "string" then + item.info = {} + end + if item.info.quality == nil then + item.info.quality = 100 + end + else + local info = {quality = 100} + item.info = info + end + local quality = ConvertQuality(item) + if item.info.quality then + if quality < item.info.quality then + item.info.quality = quality + end + else + item.info = {quality = quality} + end + else + if item.info then + item.info.quality = 100 + else + local info = {quality = 100} + item.info = info + end + end + end + end + SaveStashItems(stash, stashItems) + end + end Player.Functions.SetInventory(inventory) TriggerClientEvent("inventory:client:UpdatePlayerInventory", Player.PlayerData.source, false) data.inventory = inventory diff --git a/lj-inventory/server/main.lua b/lj-inventory/server/main.lua index 16e5466..f4fe559 100644 --- a/lj-inventory/server/main.lua +++ b/lj-inventory/server/main.lua @@ -2,11 +2,11 @@ local QBCore = exports['qb-core']:GetCoreObject() local Drops = {} -local Trunks = {} -local Gloveboxes = {} -local Stashes = {} +Trunks = {} +Gloveboxes = {} +Stashes = {} local ShopItems = {} - +local vitri = {} -- Functions local function recipeContains(recipe, fromItem) @@ -66,7 +66,7 @@ local function SetupShopItems(shop, shopItems) end -- Stash Items -local function GetStashItems(stashId) +function GetStashItems(stashId local items = {} local result = MySQL.Sync.fetchScalar('SELECT items FROM stashitems WHERE stash = ?', {stashId}) if result then @@ -87,6 +87,7 @@ local function GetStashItems(stashId) useable = itemInfo["useable"], image = itemInfo["image"], slot = item.slot, + created = item.created } end end @@ -95,7 +96,7 @@ local function GetStashItems(stashId) return items end -local function SaveStashItems(stashId, items) +function SaveStashItems(stashId, items) if Stashes[stashId].label ~= "Stash-None" then if items then for slot, item in pairs(items) do @@ -291,7 +292,7 @@ local function AddToTrunk(plate, slot, otherslot, itemName, amount, info, create end end -local function RemoveFromTrunk(plate, slot, itemName, amount) +function RemoveFromTrunk(plate, slot, itemName, amount) if Trunks[plate].items[slot] ~= nil and Trunks[plate].items[slot].name == itemName then if Trunks[plate].items[slot].amount > amount then Trunks[plate].items[slot].amount = Trunks[plate].items[slot].amount - amount @@ -310,7 +311,7 @@ local function RemoveFromTrunk(plate, slot, itemName, amount) end -- Glovebox items -local function GetOwnedVehicleGloveboxItems(plate) +function GetOwnedVehicleGloveboxItems(plate) local items = {} local result = MySQL.Sync.fetchScalar('SELECT items FROM gloveboxitems WHERE plate = ?', {plate}) if result then @@ -339,7 +340,7 @@ local function GetOwnedVehicleGloveboxItems(plate) return items end -local function SaveOwnedGloveboxItems(plate, items) +function SaveOwnedGloveboxItems(plate, items) if Gloveboxes[plate].label ~= "Glovebox-None" then if items ~= nil then for slot, item in pairs(items) do @@ -354,7 +355,7 @@ local function SaveOwnedGloveboxItems(plate, items) end end -local function AddToGlovebox(plate, slot, otherslot, itemName, amount, info, created) +function AddToGlovebox(plate, slot, otherslot, itemName, amount, info, created) local amount = tonumber(amount) local ItemData = QBCore.Shared.Items[itemName] @@ -804,7 +805,7 @@ RegisterNetEvent('inventory:server:OpenInventory', function(name, id, other) secondInv.slots = 0 end end - TriggerClientEvent("inventory:client:OpenInventory", src, {}, Player.PlayerData.items, secondInv) + TriggerClientEvent("inventory:client:OpenInventory", src, {}, Player.PlayerData.items, secondInv, id) else TriggerClientEvent("inventory:client:OpenInventory", src, {}, Player.PlayerData.items) end @@ -838,7 +839,32 @@ RegisterNetEvent('inventory:server:SaveInventory', function(type, id) end end end) - +RegisterNetEvent('q4d:server:setQuality',function (amount, name) + local src = source + local Player = QBCore.Functions.GetPlayer(src) + if name then + for k, v in pairs(Player.PlayerData.items) do + if v.name == name then + if (v.info.quality - amount) > 0 then + v.info.quality = v.info.quality - amount + Player.Functions.SetInventory(Player.PlayerData.items, true) + else + v.info.quality = 0 + Player.Functions.SetInventory(Player.PlayerData.items, true) + end + end + end + else + local itemData = Player.PlayerData.items[vitri[src]] + if (itemData.info.quality - amount) > 0 then + itemData.info.quality = itemData.info.quality - amount + Player.Functions.SetInventory(Player.PlayerData.items, true) + else + itemData.info.quality = 0 + Player.Functions.SetInventory(Player.PlayerData.items, true) + end + end +end) -- RegisterNetEvent('inventory:server:UseItemSlot', function(slot) -- local src = source -- local Player = QBCore.Functions.GetPlayer(src) @@ -884,6 +910,7 @@ RegisterNetEvent('inventory:server:UseItemSlot', function(slot) elseif itemData.useable then if itemData.info.quality then if itemData.info.quality > 0 then + vitri[src] = slot TriggerClientEvent("QBCore:Client:UseItem", src, itemData) TriggerClientEvent('inventory:client:ItemBox', src, itemInfo, "use") else @@ -911,6 +938,7 @@ RegisterNetEvent('inventory:server:UseItem', function(inventory, item) end end end + vitri[src] = item.slot TriggerClientEvent("QBCore:Client:UseItem", src, itemData) end end @@ -1446,6 +1474,7 @@ RegisterNetEvent('inventory:server:SetInventoryData', function(fromInventory, to else TriggerClientEvent("QBCore:Notify", src, "Item doesn't exist??", "error") end + TriggerClientEvent("inventory:client:UpdatePlayerInventory", Player.PlayerData.source, false) end end)