1
0
Fork 0
forked from Simnation/Main
Main/resources/[weapons]/[Scripts]/tgiann-weapons-on-back/client/bridge/mf_inv.lua
2025-08-12 13:34:26 +02:00

77 lines
2.3 KiB
Lua

if not config["mf-inventory"] then return end
local playerJob = ""
local lastItems = {}
local function getInventoryItems(identifier)
exports["mf-inventory"]:getInventoryItems(identifier, function(items)
lastItems = items
weaponCheck()
end)
end
RegisterNetEvent('esx:playerLoaded')
AddEventHandler('esx:playerLoaded', function(PlayerData)
playerJob = PlayerData.job.name
getInventoryItems(PlayerData.identifier)
end)
RegisterNetEvent('tgiCore:Client:OnPlayerLogout', function()
self.Functions.RemoveAllWeapons()
end)
RegisterNetEvent('esx:addInventoryItem')
AddEventHandler('esx:addInventoryItem', function(job)
local PlayerData = exports["tgiann-core"]:getPlayerData()
if not PlayerData then return end
getInventoryItems(PlayerData.identifier)
end)
RegisterNetEvent('esx:removeInventoryItem')
AddEventHandler('esx:removeInventoryItem', function(job)
local PlayerData = exports["tgiann-core"]:getPlayerData()
if not PlayerData then return end
getInventoryItems(PlayerData.identifier)
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()
if not lastItems then return end
Wait(100)
self.Functions.CheckWeaponIsRemoved(lastItems)
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.metadata.tgiattachments, joaat(item.name)),
playerJob = playerJob,
isMale = isMale
})
end
end
end