Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ 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
TriggerClientEvent('QBCore:Notify', self.PlayerData.source, Lang:t('error.item_not_exist'), 'error')
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)),
Expand Down Expand Up @@ -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)
Expand Down
46 changes: 18 additions & 28 deletions lj-inventory/client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
112 changes: 110 additions & 2 deletions lj-inventory/server/decay.lua
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
Loading