128 lines
		
	
	
	
		
			4.3 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
			
		
		
	
	
			128 lines
		
	
	
	
		
			4.3 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
| local QBCore = exports[Config.CoreName]:GetCoreObject()
 | |
| local nvMode = 0
 | |
| local thermalMode = 0
 | |
| local flashlightActive = false
 | |
| 
 | |
| -- Funktion zum Prüfen des Charaktergeschlechts
 | |
| local function IsPedMale(ped)
 | |
|     return GetEntityModel(ped) == `mp_m_freemode_01`
 | |
| end
 | |
| 
 | |
| -- Funktion zum Vergleichen der aktuellen Brille mit einer Konfigurationsbrille
 | |
| local function IsWearingGlasses(ped, glassesConfig)
 | |
|     local currentDrawable = GetPedPropIndex(ped, 1)
 | |
|     local currentTexture = GetPedPropTextureIndex(ped, 1)
 | |
|     
 | |
|     return currentDrawable == glassesConfig.drawable and currentTexture == glassesConfig.texture
 | |
| end
 | |
| 
 | |
| -- Funktion zum Prüfen, ob der Spieler den richtigen Helm trägt
 | |
| local function IsWearingFlashlightHelmet(ped)
 | |
|     local gender = IsPedMale(ped) and "male" or "female"
 | |
|     local helmetConfig = Config.FlashlightHelmet[gender]
 | |
|     
 | |
|     local currentDrawable = GetPedPropIndex(ped, 0)  -- 0 ist der Index für Helme
 | |
|     local currentTexture = GetPedPropTextureIndex(ped, 0)
 | |
|     
 | |
|     return currentDrawable == helmetConfig.drawable and currentTexture == helmetConfig.texture
 | |
| end
 | |
| 
 | |
| -- Funktion zum Setzen einer Brille aus der Konfiguration
 | |
| local function SetGlasses(ped, glassesConfig)
 | |
|     SetPedPropIndex(ped, 1, glassesConfig.drawable, glassesConfig.texture, true)
 | |
| end
 | |
| 
 | |
| -- Funktion zum Deaktivieren aller Sichtmodi
 | |
| local function DisableAllVisionModes()
 | |
|     SetNightvision(false)
 | |
|     SetSeethrough(false)
 | |
|     nvMode = 0
 | |
|     thermalMode = 0
 | |
| end
 | |
| 
 | |
| -- Funktion zum Aktivieren der Helm-Lampe (GTA-Style)
 | |
| local function ToggleHelmetFlashlight()
 | |
|     local ped = PlayerPedId()
 | |
|     
 | |
|     -- Prüfen, ob der Spieler den richtigen Helm trägt
 | |
|     if not IsWearingFlashlightHelmet(ped) then
 | |
|         QBCore.Functions.Notify('Du trägst keinen Helm mit Lampe!', 'error')
 | |
|         return
 | |
|     end
 | |
|     
 | |
|     -- Taschenlampe umschalten mit nativer GTA-Funktion
 | |
|     if flashlightActive then
 | |
|         SetFlashLightKeepOnWhileMoving(false)
 | |
|         TriggerServerEvent('InteractSound_SV:PlayWithinDistance', 3.0, 'flashlight', 0.4)
 | |
|         flashlightActive = false
 | |
|         QBCore.Functions.Notify('Helm-Lampe ausgeschaltet!')
 | |
|     else
 | |
|         SetFlashLightKeepOnWhileMoving(true)
 | |
|         TriggerServerEvent('InteractSound_SV:PlayWithinDistance', 3.0, 'flashlight', 0.4)
 | |
|         flashlightActive = true
 | |
|         QBCore.Functions.Notify('Helm-Lampe eingeschaltet!')
 | |
|     end
 | |
| end
 | |
| 
 | |
| -- Thread zur Überprüfung, ob der Helm noch getragen wird
 | |
| Citizen.CreateThread(function()
 | |
|     while true do
 | |
|         Citizen.Wait(1000) -- Überprüfe jede Sekunde
 | |
|         
 | |
|         if flashlightActive then
 | |
|             local ped = PlayerPedId()
 | |
|             
 | |
|             -- Prüfen, ob der Spieler noch den richtigen Helm trägt
 | |
|             if not IsWearingFlashlightHelmet(ped) then
 | |
|                 -- Deaktiviere die Lampe, wenn der Helm abgenommen wurde
 | |
|                 SetFlashLightKeepOnWhileMoving(false)
 | |
|                 flashlightActive = false
 | |
|                 QBCore.Functions.Notify('Helm-Lampe ausgeschaltet, da der Helm abgenommen wurde!', 'error')
 | |
|             end
 | |
|         end
 | |
|     end
 | |
| end)
 | |
| 
 | |
| -- Nachtsicht-Befehl
 | |
| RegisterCommand('toggleNV', function()
 | |
|     -- [Rest des Codes bleibt unverändert]
 | |
| end)
 | |
| 
 | |
| -- Wärmebild-Befehl
 | |
| RegisterCommand('toggleThermal', function()
 | |
|     -- [Rest des Codes bleibt unverändert]
 | |
| end)
 | |
| 
 | |
| -- Helm-Lampe-Befehl
 | |
| RegisterCommand('toggleHelmetLight', function()
 | |
|     ToggleHelmetFlashlight()
 | |
| end)
 | |
| 
 | |
| -- Tastenbelegungen registrieren
 | |
| RegisterKeyMapping('toggleNV', 'Nachtsicht umschalten', 'keyboard', Config.NVKey)
 | |
| RegisterKeyMapping('toggleThermal', 'Wärmebild umschalten', 'keyboard', Config.ThermalKey)
 | |
| RegisterKeyMapping('toggleHelmetLight', 'Helm-Lampe umschalten', 'keyboard', Config.FlashlightKey)
 | |
| 
 | |
| -- Event zum Umschalten der Brille
 | |
| RegisterNetEvent('nightvision:toggleGlasses', function(mode)
 | |
|     -- [Rest des Codes bleibt unverändert]
 | |
| end)
 | |
| 
 | |
| -- Behalte den alten Event-Namen für Kompatibilität
 | |
| RegisterNetEvent('nightvision:toggleHelmet', function()
 | |
|     TriggerEvent('nightvision:toggleGlasses', 'nightvision')
 | |
| end)
 | |
| 
 | |
| -- Cleanup beim Ressource-Stop
 | |
| AddEventHandler('onResourceStop', function(resourceName)
 | |
|     if (GetCurrentResourceName() ~= resourceName) then return end
 | |
|     
 | |
|     -- Deaktiviere alle Effekte
 | |
|     DisableAllVisionModes()
 | |
|     
 | |
|     -- Deaktiviere die Taschenlampe
 | |
|     if flashlightActive then
 | |
|         SetFlashLightKeepOnWhileMoving(false)
 | |
|         flashlightActive = false
 | |
|     end
 | |
| end)
 | 
