88 lines
		
	
	
	
		
			2.6 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
			
		
		
	
	
			88 lines
		
	
	
	
		
			2.6 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
| if config.framework ~= "esx" then return end
 | |
| if not config.useDefaultInventory then return end
 | |
| 
 | |
| local playerJob = ""
 | |
| local lastItems = {}
 | |
| 
 | |
| local function getInventoryItems()
 | |
|     tgiCore.cbFunction('tgiann-weapons-on-back:esx_inv:server:getInventory', function(playerItems, loadout)
 | |
|         local itemList = {}
 | |
|         -- ESX is suck
 | |
|         if loadout and #loadout > 0 then
 | |
|             for i = 1, #loadout do
 | |
|                 itemList[#itemList + 1] = loadout[i]
 | |
|             end
 | |
|         end
 | |
| 
 | |
|         if playerItems and #playerItems > 0 then
 | |
|             for i = 1, #playerItems do
 | |
|                 if playerItems[i].count > 0 then
 | |
|                     itemList[#itemList + 1] = playerItems[i]
 | |
|                 end
 | |
|             end
 | |
|         end
 | |
|         lastItems = itemList
 | |
|         weaponCheck()
 | |
|     end)
 | |
| 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)
 | |
| 
 | |
| RegisterNetEvent('esx:addInventoryItem')
 | |
| AddEventHandler('esx:addInventoryItem', function(job)
 | |
|     getInventoryItems()
 | |
| end)
 | |
| 
 | |
| RegisterNetEvent('esx:removeInventoryItem')
 | |
| AddEventHandler('esx:removeInventoryItem', function(job)
 | |
|     getInventoryItems()
 | |
| end)
 | |
| 
 | |
| RegisterNetEvent('tgiCore:Client:OnJobUpdate')
 | |
| AddEventHandler('tgiCore:Client:OnJobUpdate', function(job)
 | |
|     self.Functions.RemoveAllWeapons()
 | |
|     playerJob = job.name
 | |
|     weaponCheck()
 | |
| 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.name then
 | |
|                 success = true
 | |
|                 break
 | |
|             end
 | |
|         end
 | |
|         if not success then
 | |
|             self.Functions.RemoveWeapon(key)
 | |
|         end
 | |
|     end
 | |
| end
 | |
| 
 | |
| function weaponCheck()
 | |
|     self.Functions.CheckWeaponIsRemoved()
 | |
|     Wait(100)
 | |
|     local isMale = GetEntityModel(PlayerPedId()) == `mp_m_freemode_01`
 | |
|     for _, item in pairs(lastItems) do
 | |
|         if item and string.find(string.lower(item.name), "weapon") then
 | |
|             self.Functions.AddWeapon({
 | |
|                 weapon = item.name,
 | |
|                 key = item.name,
 | |
|                 attachments = config.tgiann_attachments and
 | |
|                     getTgiannAttachments(item?.info?.tgiattachments, joaat(item.name)) or item.components,
 | |
|                 playerJob = playerJob,
 | |
|                 isMale = isMale
 | |
|             })
 | |
|         end
 | |
|     end
 | |
| end
 | 
