From 63d0db877742067d198a120c8c138a30799a32a4 Mon Sep 17 00:00:00 2001 From: Nordi98 Date: Mon, 30 Jun 2025 21:31:12 +0200 Subject: [PATCH] fix --- .../[tools]/thommie-nightvision/cl_main.lua | 148 +++++++++++++++++- .../[tools]/thommie-nightvision/sv_main.lua | 11 +- 2 files changed, 154 insertions(+), 5 deletions(-) diff --git a/resources/[tools]/thommie-nightvision/cl_main.lua b/resources/[tools]/thommie-nightvision/cl_main.lua index d739a10a3..7b584bd29 100644 --- a/resources/[tools]/thommie-nightvision/cl_main.lua +++ b/resources/[tools]/thommie-nightvision/cl_main.lua @@ -85,12 +85,104 @@ end) -- Nachtsicht-Befehl RegisterCommand('toggleNV', function() - -- [Rest des Codes bleibt unverändert] + local ped = PlayerPedId() + local gender = IsPedMale(ped) and "male" or "female" + + -- Check if player has the item + QBCore.Functions.TriggerCallback('QBCore:HasItem', function(hasItem) + if hasItem then + -- Check if player is wearing the correct glasses if enabled + if Config.CheckHelmet then + local glassesConfig = Config.Glasses[gender] + + if nvMode == 0 then + -- Enable nightvision + if IsWearingGlasses(ped, glassesConfig.up) then + SetGlasses(ped, glassesConfig.nvDown) + SetNightvision(true) + nvMode = 1 + TriggerServerEvent('InteractSound_SV:PlayWithinDistance', 3.0, 'nightvision', 0.25) + QBCore.Functions.Notify('Nachtsicht aktiviert') + else + QBCore.Functions.Notify('Du trägst nicht die richtige Brille!', 'error') + end + else + -- Disable nightvision + SetGlasses(ped, glassesConfig.up) + SetNightvision(false) + nvMode = 0 + TriggerServerEvent('InteractSound_SV:PlayWithinDistance', 3.0, 'nightvision', 0.25) + QBCore.Functions.Notify('Nachtsicht deaktiviert') + end + else + -- No helmet check, just toggle nightvision + if nvMode == 0 then + SetNightvision(true) + nvMode = 1 + TriggerServerEvent('InteractSound_SV:PlayWithinDistance', 3.0, 'nightvision', 0.25) + QBCore.Functions.Notify('Nachtsicht aktiviert') + else + SetNightvision(false) + nvMode = 0 + TriggerServerEvent('InteractSound_SV:PlayWithinDistance', 3.0, 'nightvision', 0.25) + QBCore.Functions.Notify('Nachtsicht deaktiviert') + end + end + else + QBCore.Functions.Notify('Du hast kein Nachtsichtgerät!', 'error') + end + end, Config.NVItem) end) -- Wärmebild-Befehl RegisterCommand('toggleThermal', function() - -- [Rest des Codes bleibt unverändert] + local ped = PlayerPedId() + local gender = IsPedMale(ped) and "male" or "female" + + -- Check if player has the item + QBCore.Functions.TriggerCallback('QBCore:HasItem', function(hasItem) + if hasItem then + -- Check if player is wearing the correct glasses if enabled + if Config.CheckHelmet then + local glassesConfig = Config.Glasses[gender] + + if thermalMode == 0 then + -- Enable thermal vision + if IsWearingGlasses(ped, glassesConfig.up) then + SetGlasses(ped, glassesConfig.thermalDown) + SetSeethrough(true) + thermalMode = 1 + TriggerServerEvent('InteractSound_SV:PlayWithinDistance', 3.0, 'nightvision', 0.25) + QBCore.Functions.Notify('Wärmebild aktiviert') + else + QBCore.Functions.Notify('Du trägst nicht die richtige Brille!', 'error') + end + else + -- Disable thermal vision + SetGlasses(ped, glassesConfig.up) + SetSeethrough(false) + thermalMode = 0 + TriggerServerEvent('InteractSound_SV:PlayWithinDistance', 3.0, 'nightvision', 0.25) + QBCore.Functions.Notify('Wärmebild deaktiviert') + end + else + -- No helmet check, just toggle thermal vision + if thermalMode == 0 then + SetSeethrough(true) + thermalMode = 1 + TriggerServerEvent('InteractSound_SV:PlayWithinDistance', 3.0, 'nightvision', 0.25) + QBCore.Functions.Notify('Wärmebild aktiviert') + else + SetSeethrough(false) + thermalMode = 0 + TriggerServerEvent('InteractSound_SV:PlayWithinDistance', 3.0, 'nightvision', 0.25) + QBCore.Functions.Notify('Wärmebild deaktiviert') + end + end + else + QBCore.Functions.Notify('Du hast kein Wärmebildgerät!', 'error') + end + end, Config.ThermalItem) end) -- Helm-Lampe-Befehl @@ -105,7 +197,57 @@ RegisterKeyMapping('toggleHelmetLight', 'Helm-Lampe umschalten', 'keyboard', Con -- Event zum Umschalten der Brille RegisterNetEvent('nightvision:toggleGlasses', function(mode) - -- [Rest des Codes bleibt unverändert] + local ped = PlayerPedId() + local gender = IsPedMale(ped) and "male" or "female" + local glassesConfig = Config.Glasses[gender] + + if mode == 'nightvision' then + -- Check if player has the item + QBCore.Functions.TriggerCallback('QBCore:HasItem', function(hasItem) + if hasItem then + if nvMode == 0 then + -- Enable nightvision + SetGlasses(ped, glassesConfig.nvDown) + SetNightvision(true) + nvMode = 1 + TriggerServerEvent('InteractSound_SV:PlayWithinDistance', 3.0, 'nightvision', 0.25) + QBCore.Functions.Notify('Nachtsicht aktiviert') + else + -- Disable nightvision + SetGlasses(ped, glassesConfig.up) + SetNightvision(false) + nvMode = 0 + TriggerServerEvent('InteractSound_SV:PlayWithinDistance', 3.0, 'nightvision', 0.25) + QBCore.Functions.Notify('Nachtsicht deaktiviert') + end + else + QBCore.Functions.Notify('Du hast kein Nachtsichtgerät!', 'error') + end + end, Config.NVItem) + elseif mode == 'thermal' then + -- Check if player has the item + QBCore.Functions.TriggerCallback('QBCore:HasItem', function(hasItem) + if hasItem then + if thermalMode == 0 then + -- Enable thermal vision + SetGlasses(ped, glassesConfig.thermalDown) + SetSeethrough(true) + thermalMode = 1 + TriggerServerEvent('InteractSound_SV:PlayWithinDistance', 3.0, 'nightvision', 0.25) + QBCore.Functions.Notify('Wärmebild aktiviert') + else + -- Disable thermal vision + SetGlasses(ped, glassesConfig.up) + SetSeethrough(false) + thermalMode = 0 + TriggerServerEvent('InteractSound_SV:PlayWithinDistance', 3.0, 'nightvision', 0.25) + QBCore.Functions.Notify('Wärmebild deaktiviert') + end + else + QBCore.Functions.Notify('Du hast kein Wärmebildgerät!', 'error') + end + end, Config.ThermalItem) + end end) -- Behalte den alten Event-Namen für Kompatibilität diff --git a/resources/[tools]/thommie-nightvision/sv_main.lua b/resources/[tools]/thommie-nightvision/sv_main.lua index df9359dc9..dbcdd354b 100644 --- a/resources/[tools]/thommie-nightvision/sv_main.lua +++ b/resources/[tools]/thommie-nightvision/sv_main.lua @@ -3,6 +3,13 @@ local QBCore = exports[Config.CoreName]:GetCoreObject() QBCore.Functions.CreateUseableItem(Config.NVItem, function(source, item) local Player = QBCore.Functions.GetPlayer(source) if Player.Functions.GetItemByName(item.name) then - TriggerClientEvent('nightvision:toggleHelmet', source) + TriggerClientEvent('nightvision:toggleGlasses', source, 'nightvision') end -end) \ No newline at end of file +end) + +QBCore.Functions.CreateUseableItem(Config.ThermalItem, function(source, item) + local Player = QBCore.Functions.GetPlayer(source) + if Player.Functions.GetItemByName(item.name) then + TriggerClientEvent('nightvision:toggleGlasses', source, 'thermal') + end +end)