89 lines
		
	
	
	
		
			2.8 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
			
		
		
	
	
			89 lines
		
	
	
	
		
			2.8 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
if not config["qs-inventory"] then return end
 | 
						|
 | 
						|
local playerJob = ""
 | 
						|
local lastItems = {}
 | 
						|
local isBussy = false
 | 
						|
 | 
						|
local function getInventoryItems()
 | 
						|
    if isBussy then return end
 | 
						|
    isBussy = true
 | 
						|
    while exports['qs-inventory']:inInventory() do Wait(10) end -- getUserInventory not updating when inventory is open
 | 
						|
    Wait(1000)                                                  -- getUserInventory is updating late
 | 
						|
    lastItems = exports['qs-inventory']:getUserInventory()
 | 
						|
    weaponCheck(playerJob, true)
 | 
						|
    isBussy = false
 | 
						|
end
 | 
						|
 | 
						|
RegisterNetEvent('tgiCore:Client:OnPlayerLoaded')
 | 
						|
AddEventHandler('tgiCore:Client:OnPlayerLoaded', function(PlayerData)
 | 
						|
    playerJob = PlayerData.job.name
 | 
						|
    getInventoryItems()
 | 
						|
end)
 | 
						|
 | 
						|
RegisterNetEvent('tgiCore:Client:OnPlayerLogout', function()
 | 
						|
    self.Functions.RemoveAllWeapons()
 | 
						|
end)
 | 
						|
 | 
						|
--ESX
 | 
						|
RegisterNetEvent('esx:addInventoryItem')
 | 
						|
AddEventHandler('esx:addInventoryItem', function()
 | 
						|
    getInventoryItems()
 | 
						|
end)
 | 
						|
 | 
						|
RegisterNetEvent('esx:removeInventoryItem')
 | 
						|
AddEventHandler('esx:removeInventoryItem', function()
 | 
						|
    getInventoryItems()
 | 
						|
end)
 | 
						|
 | 
						|
--QB
 | 
						|
RegisterNetEvent('QBCore:Player:SetPlayerData', function(PlayerData)
 | 
						|
    playerJob = PlayerData.job.name
 | 
						|
    lastItems = PlayerData?.items
 | 
						|
    weaponCheck()
 | 
						|
end)
 | 
						|
 | 
						|
RegisterNetEvent('tgiCore:Client:OnJobUpdate')
 | 
						|
AddEventHandler('tgiCore:Client:OnJobUpdate', function(job)
 | 
						|
    self.Functions.RemoveAllWeapons()
 | 
						|
    playerJob = job.name
 | 
						|
    weaponCheck(playerJob)
 | 
						|
end)
 | 
						|
 | 
						|
self.Functions.CheckWeaponIsRemoved = function()
 | 
						|
    if not next(self.weapons) then return end
 | 
						|
    for key, _ in pairs(self.weapons) do
 | 
						|
        local success = false
 | 
						|
        for _, item in pairs(lastItems) do
 | 
						|
            if item and key == (item.info?.serie or item.name) then
 | 
						|
                success = true
 | 
						|
                break
 | 
						|
            end
 | 
						|
        end
 | 
						|
        if not success then
 | 
						|
            self.Functions.RemoveWeapon(key)
 | 
						|
        end
 | 
						|
    end
 | 
						|
end
 | 
						|
 | 
						|
function weaponCheck()
 | 
						|
    Wait(100)
 | 
						|
    self.Functions.CheckWeaponIsRemoved()
 | 
						|
    local isMale = GetEntityModel(PlayerPedId()) == `mp_m_freemode_01`
 | 
						|
    for _, item in pairs(lastItems) do
 | 
						|
        if item then
 | 
						|
            local isWeapon = string.find(string.lower(item.name), "weapon")
 | 
						|
            debug(item.name .. " Check For Add Weapon", "isWeapon: " .. tostring(isWeapon))
 | 
						|
            if isWeapon then
 | 
						|
                debug(item.name .. " Added")
 | 
						|
                self.Functions.AddWeapon({
 | 
						|
                    weapon = item.name,
 | 
						|
                    key = item.info?.serie or item.name,
 | 
						|
                    attachments = config.tgiann_attachments and
 | 
						|
                        getTgiannAttachments(item.info.tgiattachments, joaat(item.name)) or item.info?.attachments,
 | 
						|
                    playerJob = playerJob,
 | 
						|
                    isMale = isMale
 | 
						|
                })
 | 
						|
            end
 | 
						|
        end
 | 
						|
    end
 | 
						|
end
 |