if not config["codem-inventory"] then return end local playerJob = "" local lastItems = {} RegisterNetEvent('tgiCore:Client:OnPlayerLogout', function() self.Functions.RemoveAllWeapons() end) RegisterNetEvent('tgiCore:Client:OnPlayerLoaded') AddEventHandler('tgiCore:Client:OnPlayerLoaded', function(PlayerData) playerJob = PlayerData.job.name SetTimeout(2000, function() -- some waiting time because the character's inventory data is loaded later lastItems = exports['codem-inventory']:GetClientPlayerInventory() weaponCheck() end) end) RegisterNetEvent('tgiCore:Client:OnJobUpdate') AddEventHandler('tgiCore:Client:OnJobUpdate', function(job) self.Functions.RemoveAllWeapons() playerJob = job.name weaponCheck() end) RegisterNetEvent('codem-inventory:client:additem') AddEventHandler('codem-inventory:client:additem', function(slot, data) lastItems[tostring(slot)] = data weaponCheck() end) RegisterNetEvent('codem-inventory:client:removeitemtoclientInventory') AddEventHandler('codem-inventory:client:removeitemtoclientInventory', function(slot, amount) slot = tostring(slot) if lastItems[slot] then local itemAmount = lastItems[slot].count or lastItems[slot].amount if itemAmount == amount then lastItems[slot] = nil end end weaponCheck() end) RegisterNetEvent('codem-inventory:client:clearinventory') AddEventHandler('codem-inventory:client:clearinventory', function() lastItems = {} weaponCheck() end) RegisterNetEvent('codem-inventory:client:setitembyslot') AddEventHandler('codem-inventory:client:setitembyslot', function(slot, itemData) lastItems[tostring(slot)] = itemData 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 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() if not lastItems then return end Wait(100) self.Functions.CheckWeaponIsRemoved() local isMale = GetEntityModel(PlayerPedId()) == `mp_m_freemode_01` for _, item in pairs(lastItems) do if item and item.type == "weapon" then 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