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
172 changes: 159 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,59 @@ 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)),
}
end
if (totalWeight + (itemInfo['weight'] * amount)) <= QBCore.Config.Player.MaxWeight then
if (slot and self.PlayerData.items[slot]) and (self.PlayerData.items[slot].name:lower() == item:lower()) and (itemInfo['type'] == 'item' and not itemInfo['unique']) then
self.PlayerData.items[slot].amount = self.PlayerData.items[slot].amount + amount
self.Functions.UpdatePlayerData()
TriggerEvent('qb-log:server:CreateLog', 'playerinventory', 'AddItem', 'green', '**' .. GetPlayerName(self.PlayerData.source) .. ' (citizenid: ' .. self.PlayerData.citizenid .. ' | id: ' .. self.PlayerData.source .. ')** got item: [slot:' .. slot .. '], itemname: ' .. self.PlayerData.items[slot].name .. ', added amount: ' .. amount .. ', new total amount: ' .. self.PlayerData.items[slot].amount)
return true
elseif (not itemInfo['unique'] and slot or slot and self.PlayerData.items[slot] == nil) then
self.PlayerData.items[slot] = { name = itemInfo['name'], amount = amount, info = info or '', label = itemInfo['label'], description = itemInfo['description'] or '', weight = itemInfo['weight'], type = itemInfo['type'], unique = itemInfo['unique'], useable = itemInfo['useable'], image = itemInfo['image'], shouldClose = itemInfo['shouldClose'], slot = slot, combinable = itemInfo['combinable'], created = itemInfo['created'] }
self.Functions.UpdatePlayerData()
TriggerEvent('qb-log:server:CreateLog', 'playerinventory', 'AddItem', 'green', '**' .. GetPlayerName(self.PlayerData.source) .. ' (citizenid: ' .. self.PlayerData.citizenid .. ' | id: ' .. self.PlayerData.source .. ')** got item: [slot:' .. slot .. '], itemname: ' .. self.PlayerData.items[slot].name .. ', added amount: ' .. amount .. ', new total amount: ' .. self.PlayerData.items[slot].amount)
return true
if (slot and self.PlayerData.items[slot]) and (self.PlayerData.items[slot].name:lower() == item:lower()) and (itemInfo['type'] == 'item' and not itemInfo['unique']) then

if info.quality == self.PlayerData.items[slot].info.quality or self.PlayerData.items[slot].info.quality >= 99 then

self.PlayerData.items[slot].amount = self.PlayerData.items[slot].amount + amount

self.Functions.UpdatePlayerData()
TriggerEvent('qb-log:server:CreateLog', 'playerinventory', 'AddItem', 'green', '**' .. GetPlayerName(self.PlayerData.source) .. ' (citizenid: ' .. self.PlayerData.citizenid .. ' | id: ' .. self.PlayerData.source .. ')** got item: [slot:' .. slot .. '], itemname: ' .. self.PlayerData.items[slot].name .. ', added amount: ' .. amount .. ', new total amount: ' .. self.PlayerData.items[slot].amount)

return true

else
slot = nil
for i = 1, QBConfig.Player.MaxInvSlots, 1 do
if self.PlayerData.items[i] == nil then
self.PlayerData.items[i] = { name = itemInfo['name'], amount = amount, info = info or '', label = itemInfo['label'], description = itemInfo['description'] or '', weight = itemInfo['weight'], type = itemInfo['type'], unique = itemInfo['unique'], useable = itemInfo['useable'], image = itemInfo['image'], shouldClose = itemInfo['shouldClose'], slot = i, combinable = itemInfo['combinable'], created = itemInfo['created'] }


self.Functions.UpdatePlayerData()
TriggerEvent('qb-log:server:CreateLog', 'playerinventory', 'AddItem', 'green', '**' .. GetPlayerName(self.PlayerData.source) .. ' (citizenid: ' .. self.PlayerData.citizenid .. ' | id: ' .. self.PlayerData.source .. ')** got item: [slot:' .. i .. '], itemname: ' .. self.PlayerData.items[i].name .. ', added amount: ' .. amount .. ', new total amount: ' .. self.PlayerData.items[i].amount)


return true
end
end

end
elseif not itemInfo['unique'] or (not slot or slot == nil) or itemInfo['type'] == 'item' and self.PlayerData.items[slot].info.quality ~= info.quality and self.PlayerData.items[slot].name:lower() == item:lower() then
for i = 1, QBConfig.Player.MaxInvSlots, 1 do
if self.PlayerData.items[i] == nil then
self.PlayerData.items[i] = { name = itemInfo['name'], amount = amount, info = info or '', label = itemInfo['label'], description = itemInfo['description'] or '', weight = itemInfo['weight'], type = itemInfo['type'], unique = itemInfo['unique'], useable = itemInfo['useable'], image = itemInfo['image'], shouldClose = itemInfo['shouldClose'], slot = i, combinable = itemInfo['combinable'], created = itemInfo['created'] }
self.Functions.UpdatePlayerData()
TriggerEvent('qb-log:server:CreateLog', 'playerinventory', 'AddItem', 'green', '**' .. GetPlayerName(self.PlayerData.source) .. ' (citizenid: ' .. self.PlayerData.citizenid .. ' | id: ' .. self.PlayerData.source .. ')** got item: [slot:' .. i .. '], itemname: ' .. self.PlayerData.items[i].name .. ', added amount: ' .. amount .. ', new total amount: ' .. self.PlayerData.items[i].amount)


return true
end
end
elseif (itemInfo['unique']) or (not slot or slot == nil) or (itemInfo['type'] == 'weapon') then
for i = 1, QBConfig.Player.MaxInvSlots, 1 do
if self.PlayerData.items[i] == nil then
Expand All @@ -71,7 +99,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
Expand Down Expand Up @@ -144,3 +191,102 @@ function QBCore.Player.SaveInventory(source)
end
end
```


# if u are on Latest updated qbcore u need to replace this Add Item function not above


### self.Functions.AddItem | server/player.lua | replace with below:

```lua
function self.Functions.AddItem(item, amount, slot, info,created)
local totalWeight = QBCore.Player.GetTotalWeight(self.PlayerData.items)
local itemInfo = QBCore.Shared.Items[item:lower()]

local time = os.time()
if not created then
itemInfo['created'] = time
else
itemInfo['created'] = created
end
-- itemInfo['created'] = time
if itemInfo["type"] == 'item' and info == nil then
info = { quality = 100 }
end

if not itemInfo and not self.Offline then
TriggerClientEvent('QBCore:Notify', self.PlayerData.source, Lang:t('error.item_not_exist'), 'error')
return
end

amount = tonumber(amount)
slot = tonumber(slot) or QBCore.Player.GetFirstSlotByItem(self.PlayerData.items, item)
if itemInfo['type'] == 'weapon' and not info 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)),
}
end
if (totalWeight + (itemInfo['weight'] * amount)) <= QBCore.Config.Player.MaxWeight then


if (slot and self.PlayerData.items[slot]) and (self.PlayerData.items[slot].name:lower() == item:lower()) and (itemInfo['type'] == 'item' and not itemInfo['unique']) then

if info.quality == self.PlayerData.items[slot].info.quality or self.PlayerData.items[slot].info.quality >= 99 then

self.PlayerData.items[slot].amount = self.PlayerData.items[slot].amount + amount
if not self.Offline then
self.Functions.UpdatePlayerData()
TriggerEvent('qb-log:server:CreateLog', 'playerinventory', 'AddItem', 'green', '**' .. GetPlayerName(self.PlayerData.source) .. ' (citizenid: ' .. self.PlayerData.citizenid .. ' | id: ' .. self.PlayerData.source .. ')** got item: [slot:' .. slot .. '], itemname: ' .. self.PlayerData.items[slot].name .. ', added amount: ' .. amount .. ', new total amount: ' .. self.PlayerData.items[slot].amount)
end
return true

else
slot = nil
for i = 1, QBConfig.Player.MaxInvSlots, 1 do
if self.PlayerData.items[i] == nil then
self.PlayerData.items[i] = { name = itemInfo['name'], amount = amount, info = info or '', label = itemInfo['label'], description = itemInfo['description'] or '', weight = itemInfo['weight'], type = itemInfo['type'], unique = itemInfo['unique'], useable = itemInfo['useable'], image = itemInfo['image'], shouldClose = itemInfo['shouldClose'], slot = i, combinable = itemInfo['combinable'], created = itemInfo['created'] }

if not self.Offline then
self.Functions.UpdatePlayerData()
TriggerEvent('qb-log:server:CreateLog', 'playerinventory', 'AddItem', 'green', '**' .. GetPlayerName(self.PlayerData.source) .. ' (citizenid: ' .. self.PlayerData.citizenid .. ' | id: ' .. self.PlayerData.source .. ')** got item: [slot:' .. i .. '], itemname: ' .. self.PlayerData.items[i].name .. ', added amount: ' .. amount .. ', new total amount: ' .. self.PlayerData.items[i].amount)
end

return true
end
end

end

elseif not itemInfo['unique'] and slot or slot and self.PlayerData.items[slot] == nil then
self.PlayerData.items[slot] = { name = itemInfo['name'], amount = amount, info = info or '', label = itemInfo['label'], description = itemInfo['description'] or '', weight = itemInfo['weight'], type = itemInfo['type'], unique = itemInfo['unique'], useable = itemInfo['useable'], image = itemInfo['image'], shouldClose = itemInfo['shouldClose'], slot = slot, combinable = itemInfo['combinable'] ,created = itemInfo['created']}

if not self.Offline then
self.Functions.UpdatePlayerData()
TriggerEvent('qb-log:server:CreateLog', 'playerinventory', 'AddItem', 'green', '**' .. GetPlayerName(self.PlayerData.source) .. ' (citizenid: ' .. self.PlayerData.citizenid .. ' | id: ' .. self.PlayerData.source .. ')** got item: [slot:' .. slot .. '], itemname: ' .. self.PlayerData.items[slot].name .. ', added amount: ' .. amount .. ', new total amount: ' .. self.PlayerData.items[slot].amount)
end

return true

elseif itemInfo['unique'] or (not slot or slot == nil) or itemInfo['type'] == 'weapon' then
for i = 1, QBConfig.Player.MaxInvSlots, 1 do
if self.PlayerData.items[i] == nil then
self.PlayerData.items[i] = { name = itemInfo['name'], amount = amount, info = info or '', label = itemInfo['label'], description = itemInfo['description'] or '', weight = itemInfo['weight'], type = itemInfo['type'], unique = itemInfo['unique'], useable = itemInfo['useable'], image = itemInfo['image'], shouldClose = itemInfo['shouldClose'], slot = i, combinable = itemInfo['combinable'], created = itemInfo['created'] }

if not self.Offline then
self.Functions.UpdatePlayerData()
TriggerEvent('qb-log:server:CreateLog', 'playerinventory', 'AddItem', 'green', '**' .. GetPlayerName(self.PlayerData.source) .. ' (citizenid: ' .. self.PlayerData.citizenid .. ' | id: ' .. self.PlayerData.source .. ')** got item: [slot:' .. i .. '], itemname: ' .. self.PlayerData.items[i].name .. ', added amount: ' .. amount .. ', new total amount: ' .. self.PlayerData.items[i].amount)
end

return true
end
end
end
elseif not self.Offline then
TriggerClientEvent('QBCore:Notify', self.PlayerData.source, Lang:t('error.too_heavy'), 'error')
end
return false
end
```



30 changes: 30 additions & 0 deletions lj-inventory/server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,7 @@ RegisterNetEvent('inventory:server:UseItemSlot', function(slot)
if itemData.type == "weapon" then
if itemData.info.quality then
if itemData.info.quality > 0 then
vitri = slot
TriggerClientEvent("inventory:client:UseWeapon", src, itemData, true)
else
TriggerClientEvent("inventory:client:UseWeapon", src, itemData, false)
Expand All @@ -890,6 +891,7 @@ RegisterNetEvent('inventory:server:UseItemSlot', function(slot)
TriggerClientEvent("QBCore:Notify", src, "You can't use this item", "error")
end
else

TriggerClientEvent("QBCore:Client:UseItem", src, itemData)
TriggerClientEvent('inventory:client:ItemBox', src, itemInfo, "use")
end
Expand All @@ -911,6 +913,7 @@ RegisterNetEvent('inventory:server:UseItem', function(inventory, item)
end
end
end
vitri = item.slot
TriggerClientEvent("QBCore:Client:UseItem", src, itemData)
end
end
Expand Down Expand Up @@ -1663,3 +1666,30 @@ QBCore.Functions.CreateUseableItem("id_card", function(source, item)
end
end
end)

RegisterNetEvent('lj-inventory: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]
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)