forked from Simnation/Main
65 lines
1.9 KiB
Lua
65 lines
1.9 KiB
Lua
![]() |
if not config.ox_inventory then return end
|
||
|
|
||
|
local playerJob = ""
|
||
|
local lastItems = {}
|
||
|
|
||
|
RegisterNetEvent('tgiCore:Client:OnPlayerLoaded')
|
||
|
AddEventHandler('tgiCore:Client:OnPlayerLoaded', function(PlayerData)
|
||
|
playerJob = PlayerData.job.name
|
||
|
lastItems = exports.ox_inventory:GetPlayerItems() or {}
|
||
|
weaponCheck()
|
||
|
end)
|
||
|
|
||
|
RegisterNetEvent('tgiCore:Client:OnPlayerLogout', function()
|
||
|
self.Functions.RemoveAllWeapons()
|
||
|
end)
|
||
|
|
||
|
AddEventHandler('ox_inventory:updateInventory', function(changes)
|
||
|
for i, value in pairs(changes) do
|
||
|
lastItems[i] = value or nil
|
||
|
end
|
||
|
weaponCheck()
|
||
|
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.metadata.serial 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 string.find(string.lower(item.name), "weapon") then
|
||
|
self.Functions.AddWeapon({
|
||
|
weapon = item.name,
|
||
|
key = item.metadata.serial or item.name,
|
||
|
attachments = config.tgiann_attachments and
|
||
|
getTgiannAttachments(item.metadata.tgiattachments, joaat(item.name)) or item.metadata.components,
|
||
|
playerJob = playerJob,
|
||
|
isMale = isMale
|
||
|
})
|
||
|
end
|
||
|
end
|
||
|
end
|