diff --git a/server/main.lua b/server/main.lua index a5e0d204..8dae446f 100644 --- a/server/main.lua +++ b/server/main.lua @@ -984,6 +984,219 @@ local function CreateNewDrop(source, fromSlot, toSlot, itemAmount, created) end end +local function OpenInventory(name, id, other, origin) + local src = origin + local ply = Player(src) + local Player = QBCore.Functions.GetPlayer(src) + if ply.state.inv_busy then + return QBCore.Functions.Notify(src, Lang:t("notify.noaccess"), 'error') + end + if name and id then + local secondInv = {} + if name == "stash" then + if Stashes[id] then + if Stashes[id].isOpen then + local Target = QBCore.Functions.GetPlayer(Stashes[id].isOpen) + if Target then + TriggerClientEvent('inventory:client:CheckOpenState', Stashes[id].isOpen, name, id, Stashes[id].label) + else + Stashes[id].isOpen = false + end + end + end + local maxweight = 1000000 + local slots = 50 + if other then + maxweight = other.maxweight or 1000000 + slots = other.slots or 50 + end + secondInv.name = "stash-"..id + secondInv.label = "Stash-"..id + secondInv.maxweight = maxweight + secondInv.inventory = {} + secondInv.slots = slots + if Stashes[id] and Stashes[id].isOpen then + secondInv.name = "none-inv" + secondInv.label = "Stash-None" + secondInv.maxweight = 1000000 + secondInv.inventory = {} + secondInv.slots = 0 + else + local stashItems = GetStashItems(id) + if next(stashItems) then + secondInv.inventory = stashItems + Stashes[id] = {} + Stashes[id].items = stashItems + Stashes[id].isOpen = src + Stashes[id].label = secondInv.label + else + Stashes[id] = {} + Stashes[id].items = {} + Stashes[id].isOpen = src + Stashes[id].label = secondInv.label + end + end + elseif name == "trunk" then + if Trunks[id] then + if Trunks[id].isOpen then + local Target = QBCore.Functions.GetPlayer(Trunks[id].isOpen) + if Target then + TriggerClientEvent('inventory:client:CheckOpenState', Trunks[id].isOpen, name, id, Trunks[id].label) + else + Trunks[id].isOpen = false + end + end + end + secondInv.name = "trunk-"..id + secondInv.label = "Trunk-"..id + secondInv.maxweight = other.maxweight or 60000 + secondInv.inventory = {} + secondInv.slots = other.slots or 50 + if (Trunks[id] and Trunks[id].isOpen) or (QBCore.Shared.SplitStr(id, "PLZI")[2] and (Player.PlayerData.job.name ~= "police" or Player.PlayerData.job.type ~= "leo")) then + secondInv.name = "none-inv" + secondInv.label = "Trunk-None" + secondInv.maxweight = other.maxweight or 60000 + secondInv.inventory = {} + secondInv.slots = 0 + else + if id then + local ownedItems = GetOwnedVehicleItems(id) + if IsVehicleOwned(id) and next(ownedItems) then + secondInv.inventory = ownedItems + Trunks[id] = {} + Trunks[id].items = ownedItems + Trunks[id].isOpen = src + Trunks[id].label = secondInv.label + elseif Trunks[id] and not Trunks[id].isOpen then + secondInv.inventory = Trunks[id].items + Trunks[id].isOpen = src + Trunks[id].label = secondInv.label + else + Trunks[id] = {} + Trunks[id].items = {} + Trunks[id].isOpen = src + Trunks[id].label = secondInv.label + end + end + end + elseif name == "glovebox" then + if Gloveboxes[id] then + if Gloveboxes[id].isOpen then + local Target = QBCore.Functions.GetPlayer(Gloveboxes[id].isOpen) + if Target then + TriggerClientEvent('inventory:client:CheckOpenState', Gloveboxes[id].isOpen, name, id, Gloveboxes[id].label) + else + Gloveboxes[id].isOpen = false + end + end + end + secondInv.name = "glovebox-"..id + secondInv.label = "Glovebox-"..id + secondInv.maxweight = 10000 + secondInv.inventory = {} + secondInv.slots = 5 + if Gloveboxes[id] and Gloveboxes[id].isOpen then + secondInv.name = "none-inv" + secondInv.label = "Glovebox-None" + secondInv.maxweight = 10000 + secondInv.inventory = {} + secondInv.slots = 0 + else + local ownedItems = GetOwnedVehicleGloveboxItems(id) + if Gloveboxes[id] and not Gloveboxes[id].isOpen then + secondInv.inventory = Gloveboxes[id].items + Gloveboxes[id].isOpen = src + Gloveboxes[id].label = secondInv.label + elseif IsVehicleOwned(id) and next(ownedItems) then + secondInv.inventory = ownedItems + Gloveboxes[id] = {} + Gloveboxes[id].items = ownedItems + Gloveboxes[id].isOpen = src + Gloveboxes[id].label = secondInv.label + else + Gloveboxes[id] = {} + Gloveboxes[id].items = {} + Gloveboxes[id].isOpen = src + Gloveboxes[id].label = secondInv.label + end + end + elseif name == "shop" then + secondInv.name = "itemshop-"..id + secondInv.label = other.label + secondInv.maxweight = 900000 + secondInv.inventory = SetupShopItems(other.items) + ShopItems[id] = {} + ShopItems[id].items = other.items + secondInv.slots = #other.items + elseif name == "traphouse" then + secondInv.name = "traphouse-"..id + secondInv.label = other.label + secondInv.maxweight = 900000 + secondInv.inventory = other.items + secondInv.slots = other.slots + elseif name == "crafting" then + secondInv.name = "crafting" + secondInv.label = other.label + secondInv.maxweight = 900000 + secondInv.inventory = other.items + secondInv.slots = #other.items + elseif name == "attachment_crafting" then + secondInv.name = "attachment_crafting" + secondInv.label = other.label + secondInv.maxweight = 900000 + secondInv.inventory = other.items + secondInv.slots = #other.items + elseif name == "otherplayer" then + local OtherPlayer = QBCore.Functions.GetPlayer(tonumber(id)) + if OtherPlayer then + secondInv.name = "otherplayer-"..id + secondInv.label = "Player-"..id + secondInv.maxweight = Config.MaxInventoryWeight + secondInv.inventory = OtherPlayer.PlayerData.items + if (Player.PlayerData.job.name == "police" or Player.PlayerData.job.type == "leo") and Player.PlayerData.job.onduty then + secondInv.slots = Config.MaxInventorySlots + else + secondInv.slots = Config.MaxInventorySlots - 1 + end + Wait(250) + end + else + if Drops[id] then + if Drops[id].isOpen then + local Target = QBCore.Functions.GetPlayer(Drops[id].isOpen) + if Target then + TriggerClientEvent('inventory:client:CheckOpenState', Drops[id].isOpen, name, id, Drops[id].label) + else + Drops[id].isOpen = false + end + end + end + if Drops[id] and not Drops[id].isOpen then + secondInv.coords = Drops[id].coords + secondInv.name = id + secondInv.label = "Dropped-"..tostring(id) + secondInv.maxweight = 100000 + secondInv.inventory = Drops[id].items + secondInv.slots = 30 + Drops[id].isOpen = src + Drops[id].label = secondInv.label + Drops[id].createdTime = os.time() + else + secondInv.name = "none-inv" + secondInv.label = "Dropped-None" + secondInv.maxweight = 100000 + secondInv.inventory = {} + secondInv.slots = 0 + end + end + TriggerClientEvent("lj-inventory:client:closeinv", id) + TriggerClientEvent("inventory:client:OpenInventory", src, {}, Player.PlayerData.items, secondInv) + else + TriggerClientEvent("inventory:client:OpenInventory", src, {}, Player.PlayerData.items) + end +end +exports('OpenInventory',OpenInventory) + -- Events AddEventHandler('QBCore:Server:PlayerLoaded', function(Player) @@ -1055,10 +1268,19 @@ RegisterNetEvent('QBCore:Server:UpdateObject', function() QBCore = exports['qb-core']:GetCoreObject() end) -RegisterNetEvent('inventory:server:addTrunkItems', function(plate, items) +function addTrunkItems(plate, items) Trunks[plate] = {} Trunks[plate].items = items -end) +end + +exports('addTrunkItems',addTrunkItems) + +function addGloveboxItems(plate, items) + Gloveboxes[plate] = {} + Gloveboxes[plate].items = items +end + +exports('addGloveboxItems',addGloveboxItems) RegisterNetEvent('inventory:server:combineItem', function(item, fromItem, toItem) local src = source @@ -1134,10 +1356,12 @@ RegisterNetEvent('inventory:server:SetIsOpenState', function(IsOpen, type, id) end) RegisterNetEvent('inventory:server:OpenInventory', function(name, id, other) - local src = source - local ply = Player(src) - local Player = QBCore.Functions.GetPlayer(src) - if not ply.state.inv_busy then + local src = source + local ply = Player(src) + local Player = QBCore.Functions.GetPlayer(src) + if ply.state.inv_busy then + return QBCore.Functions.Notify(src, Lang:t("notify.noaccess"), 'error') + end if name and id then local secondInv = {} if name == "stash" then @@ -1199,7 +1423,7 @@ RegisterNetEvent('inventory:server:OpenInventory', function(name, id, other) secondInv.maxweight = other.maxweight or 60000 secondInv.inventory = {} secondInv.slots = other.slots or 50 - if (Trunks[id] and Trunks[id].isOpen) or (QBCore.Shared.SplitStr(id, "PLZI")[2] and Player.PlayerData.job.name ~= "police") then + if (Trunks[id] and Trunks[id].isOpen) or (QBCore.Shared.SplitStr(id, "PLZI")[2] and (Player.PlayerData.job.name ~= "police" or Player.PlayerData.job.type ~= "leo")) then secondInv.name = "none-inv" secondInv.label = "Trunk-None" secondInv.maxweight = other.maxweight or 60000 @@ -1300,7 +1524,7 @@ RegisterNetEvent('inventory:server:OpenInventory', function(name, id, other) secondInv.label = "Player-"..id secondInv.maxweight = Config.MaxInventoryWeight secondInv.inventory = OtherPlayer.PlayerData.items - if Player.PlayerData.job.name == "police" and Player.PlayerData.job.onduty then + if (Player.PlayerData.job.name == "police" or Player.PlayerData.job.type == "leo") and Player.PlayerData.job.onduty then secondInv.slots = Config.MaxInventorySlots else secondInv.slots = Config.MaxInventorySlots - 1 @@ -1336,13 +1560,10 @@ RegisterNetEvent('inventory:server:OpenInventory', function(name, id, other) secondInv.slots = 0 end end - TriggerClientEvent("qb-inventory:client:closeinv", id) + TriggerClientEvent("lj-inventory:client:closeinv", id) TriggerClientEvent("inventory:client:OpenInventory", src, {}, Player.PlayerData.items, secondInv) else TriggerClientEvent("inventory:client:OpenInventory", src, {}, Player.PlayerData.items) - end - else - TriggerClientEvent('QBCore:Notify', src, 'Not Accessible', 'error') end end) @@ -2479,3 +2700,12 @@ QBCore.Functions.CreateCallback('inventory:server:ConvertQuality', function(sour data.other = other cb(data) end) + +-- Warning Messages + +RegisterNetEvent('inventory:server:addTrunkItems', function() + print('inventory:server:addTrunkItems has been deprecated please use exports[\'ps-inventory\']:addTrunkItems(plate, items)') +end) +RegisterNetEvent('inventory:server:addGloveboxItems', function() + print('inventory:server:addGloveboxItems has been deprecated please use exports[\'ps-inventory\']:addGloveboxItems(plate, items)') +end)