1
0
Fork 0
forked from Simnation/Main
Main/resources/[tools]/thommie-nightvision/sv_main.lua

36 lines
1 KiB
Lua
Raw Permalink Normal View History

2025-06-29 23:58:18 +02:00
local QBCore = exports[Config.CoreName]:GetCoreObject()
2025-07-11 12:26:43 +02:00
-- 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
2025-07-11 12:35:12 +02:00
RegisterNetEvent('nightvision:checkItem', function(itemName, callbackEvent)
2025-07-11 12:26:43 +02:00
local src = source
local hasItem = HasItem(src, itemName)
2025-07-11 12:35:12 +02:00
TriggerClientEvent(callbackEvent, src, hasItem)
2025-07-11 12:26:43 +02:00
end)
-- Register usable items
2025-06-29 23:58:18 +02:00
QBCore.Functions.CreateUseableItem(Config.NVItem, function(source, item)
2025-07-11 12:26:43 +02:00
if HasItem(source, item.name) then
2025-06-30 21:37:12 +02:00
TriggerClientEvent('nightvision:toggleHelmet', source)
2025-06-29 23:58:18 +02:00
end
2025-07-11 12:26:43 +02:00
end)
QBCore.Functions.CreateUseableItem(Config.ThermalItem, function(source, item)
if HasItem(source, item.name) then
TriggerClientEvent('nightvision:toggleGlasses', source, 'thermal')
end
end)