forked from Simnation/Main
35 lines
1.1 KiB
Lua
35 lines
1.1 KiB
Lua
local QBCore = exports[Config.CoreName]:GetCoreObject()
|
|
|
|
-- Function to check if player has an item
|
|
local function HasItem(source, itemName)
|
|
local items = exports["tgiann-inventory"]:GetPlayerItems(source)
|
|
if not items then return false end
|
|
|
|
for _, item in pairs(items) do
|
|
if item.name == itemName then
|
|
return true
|
|
end
|
|
end
|
|
|
|
return false
|
|
end
|
|
|
|
-- Event for client to check if player has an item
|
|
RegisterNetEvent('nightvision:checkItem', function(itemName)
|
|
local src = source
|
|
local hasItem = HasItem(src, itemName)
|
|
TriggerClientEvent('nightvision:itemCheckResult', src, itemName, hasItem)
|
|
end)
|
|
|
|
-- Register usable items
|
|
QBCore.Functions.CreateUseableItem(Config.NVItem, function(source, item)
|
|
if HasItem(source, item.name) then
|
|
TriggerClientEvent('nightvision:toggleHelmet', source)
|
|
end
|
|
end)
|
|
|
|
QBCore.Functions.CreateUseableItem(Config.ThermalItem, function(source, item)
|
|
if HasItem(source, item.name) then
|
|
TriggerClientEvent('nightvision:toggleGlasses', source, 'thermal')
|
|
end
|
|
end)
|