Editable files

Client bridge/main.lua

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, 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, data.component)
                GiveWeaponComponentToWeaponObject(entity, data.component)
                SetModelAsNoLongerNeeded(data.component)
            else
                SetWeaponObjectTintIndex(entity, data.component)
            end
        end
    else
        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
    end
end

Client Example Bridge

if config.framework ~= "qb" then return end
if config.oxinventory then return end

local playerJob = ""
local lastItems = {}

RegisterNetEvent('QBCore:Client:OnPlayerUnload', function()
    self.Functions.RemoveAllWeapons()
end)

RegisterNetEvent('tgiCore:Client:OnPlayerLoaded')
AddEventHandler('tgiCore:Client:OnPlayerLoaded', function()
    local PlayerData = exports["tgiann-core"]:getPlayerData()
    playerJob = PlayerData.job.name
    lastItems = PlayerData?.items
    weaponCheck(lastItems, playerJob)
end)

RegisterNetEvent('QBCore:Player:SetPlayerData', function(PlayerData)
    playerJob = PlayerData.job.name
    lastItems = PlayerData?.items
    weaponCheck(lastItems, playerJob)
end)

RegisterNetEvent('tgiCore:Client:OnJobUpdate')
AddEventHandler('tgiCore:Client:OnJobUpdate', function(job)
    self.Functions.RemoveAllWeapons()
    playerJob = job.name
    weaponCheck(lastItems, playerJob)
end)

self.Functions.CheckWeaponIsRemoved = function(PlayerItems)
    if not next(self.weapons) then return end
    for key, weaponData in pairs(self.weapons) do
        local success = false
        for _, item in pairs(PlayerItems) do
            if key == item.info.serie then
                success = true
                break
            end
        end
        if not success then
            self.Functions.RemoveWeapon(key)
        end
    end
end

function weaponCheck(PlayerItems, playerJob)
    if not PlayerItems then return end
    local isMale = GetEntityModel(PlayerPedId()) == `mp_m_freemode_01`
    for _, item in pairs(PlayerItems) do
        if item.type == "weapon" then
            self.Functions.AddWeapon({
                weapon = item.name,
                key = item.info.serie,
                attachments = config.tgiann_attachments and item.info.tgiattachments or item.info.attachments,
                playerJob = playerJob,
                isMale = isMale
            })
        end
    end
    self.Functions.CheckWeaponIsRemoved(PlayerItems)
end

Last updated