tgiCore = nil CreateThread(function() while not tgiCore do tgiCore = tgiCoreExports:getCore() Wait(200) end end) local function LoadModel(model) if HasModelLoaded(model) then return end RequestModel(model) while not HasModelLoaded(model) do Wait(0) end end self.Functions.AddAttachments = function(entity, weaponName, weaponHash, attachments) if not attachments then return end if config.tgiann_attachments then for _, data in pairs(attachments) do local model = GetWeaponComponentTypeModel(data.component) if model ~= 0 then LoadModel(model) GiveWeaponComponentToWeaponObject(entity, data.component) SetModelAsNoLongerNeeded(data.component) else SetWeaponObjectTintIndex(entity, data.component) end end elseif config.core_inventory then for _, data in pairs(attachments) do local model = GetWeaponComponentTypeModel(data.componentHash) if model ~= 0 then LoadModel(model) GiveWeaponComponentToWeaponObject(entity, data.componentHash) SetModelAsNoLongerNeeded(data.componentHash) else SetWeaponObjectTintIndex(entity, data.componentHash) end end elseif config.ox_inventory then if not oxItems then oxItems = exports.ox_inventory:Items() end for i = 1, #attachments do local components = oxItems[attachments[i]].client.component for v = 1, #components do local component = components[v] if DoesWeaponTakeWeaponComponent(weaponHash, component) then local model = GetWeaponComponentTypeModel(component) if model ~= 0 then LoadModel(model) GiveWeaponComponentToWeaponObject(entity, component) SetModelAsNoLongerNeeded(component) end end end end elseif config.framework == "qb" then for _, data in pairs(attachments) do local model = GetWeaponComponentTypeModel(data.component) if model ~= 0 then LoadModel(model) GiveWeaponComponentToWeaponObject(entity, data.component) SetModelAsNoLongerNeeded(data.component) else SetWeaponObjectTintIndex(entity, data.component) end end else --ESX is suck for i = 1, #attachments do local componentData = tgiCore.core.GetWeaponComponent(weaponName, attachments[i]) if componentData then local hash = componentData.hash local model = GetWeaponComponentTypeModel(hash) if model ~= 0 then LoadModel(model) GiveWeaponComponentToWeaponObject(entity, hash) SetModelAsNoLongerNeeded(hash) else SetWeaponObjectTintIndex(entity, hash) end end end end end function getTgiannAttachments(tgiattachments, weapon) local invSettings = exports["tgiann-attachment"]:inventoryConfig() if invSettings then return tgiattachments else local returnVal = nil local waitCb = true tgiCore.cbFunction("tgiann-attachment:getAttachment", function(data) returnVal = data waitCb = false end, weapon) while waitCb do Wait(10) end return returnVal end end