edit
This commit is contained in:
		
							parent
							
								
									ee2240f1d6
								
							
						
					
					
						commit
						7de5955637
					
				
					 2 changed files with 65 additions and 13 deletions
				
			
		| 
						 | 
				
			
			@ -2,10 +2,21 @@ local QBCore = exports[Config.CoreName]:GetCoreObject()
 | 
			
		|||
local mode = 0
 | 
			
		||||
local canToggle = false
 | 
			
		||||
 | 
			
		||||
-- Funktion zum Prüfen des Charaktergeschlechts
 | 
			
		||||
local function IsPedMale(ped)
 | 
			
		||||
    return GetEntityModel(ped) == `mp_m_freemode_01`
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
RegisterCommand('toggleNV', function()
 | 
			
		||||
    local ped = PlayerPedId()
 | 
			
		||||
    
 | 
			
		||||
    if QBCore.Functions.HasItem(Config.NVItem) then
 | 
			
		||||
        local currentGlasses = GetPedPropIndex(ped, 1)
 | 
			
		||||
        local gender = IsPedMale(ped) and "male" or "female"
 | 
			
		||||
        
 | 
			
		||||
        -- Prüfen, ob der Spieler eine der NV-Brillen trägt
 | 
			
		||||
        if Config.CheckHelmet then
 | 
			
		||||
            if GetPedPropIndex(PlayerPedId(), 0) == 116 then
 | 
			
		||||
            if currentGlasses == Config.Glasses[gender].up or currentGlasses == Config.Glasses[gender].down then
 | 
			
		||||
                canToggle = true
 | 
			
		||||
            else
 | 
			
		||||
                canToggle = false
 | 
			
		||||
| 
						 | 
				
			
			@ -15,31 +26,60 @@ RegisterCommand('toggleNV', function()
 | 
			
		|||
        end
 | 
			
		||||
 | 
			
		||||
        if canToggle then
 | 
			
		||||
            if mode == 0 then
 | 
			
		||||
                QBCore.Functions.Notify('Nightvision on!')
 | 
			
		||||
            -- Wenn die Brille hochgeklappt ist und Nachtsicht aktiviert wird, klappe sie runter
 | 
			
		||||
            if mode == 0 and currentGlasses == Config.Glasses[gender].up then
 | 
			
		||||
                SetPedPropIndex(ped, 1, Config.Glasses[gender].down, 0, true)
 | 
			
		||||
                QBCore.Functions.Notify('Nachtsicht aktiviert!')
 | 
			
		||||
                SetNightvision(true)
 | 
			
		||||
                mode = 1
 | 
			
		||||
            -- Wenn bereits im Nachtsichtmodus, wechsle zu Wärmesicht
 | 
			
		||||
            elseif mode == 1 then
 | 
			
		||||
                QBCore.Functions.Notify('Thermal vision on!')
 | 
			
		||||
                QBCore.Functions.Notify('Wärmesicht aktiviert!')
 | 
			
		||||
                SetSeethrough(true)
 | 
			
		||||
                mode = 2
 | 
			
		||||
            -- Wenn im Wärmesichtmodus, deaktiviere alles und klappe Brille hoch
 | 
			
		||||
            elseif mode == 2 then
 | 
			
		||||
                QBCore.Functions.Notify('Nightvision off!')
 | 
			
		||||
                SetPedPropIndex(ped, 1, Config.Glasses[gender].up, 0, true)
 | 
			
		||||
                QBCore.Functions.Notify('Nachtsicht deaktiviert!')
 | 
			
		||||
                SetNightvision(false)
 | 
			
		||||
                SetSeethrough(false)
 | 
			
		||||
                mode = 0
 | 
			
		||||
            end
 | 
			
		||||
        else
 | 
			
		||||
            QBCore.Functions.Notify('You are not wearing a nightvision helmet!', 'error')
 | 
			
		||||
            QBCore.Functions.Notify('Du trägst keine Nachtsichtbrille!', 'error')
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
end)
 | 
			
		||||
 | 
			
		||||
RegisterKeyMapping('toggleNV', 'Toggle nightvision', 'keyboard', Config.NVKey)
 | 
			
		||||
 | 
			
		||||
RegisterNetEvent('nightvision:toggleHelmet', function()
 | 
			
		||||
    if GetPedPropIndex(PlayerPedId(), 0) == 116 then
 | 
			
		||||
        SetPedPropIndex(PlayerPedId(), 0, 8, 0, true)
 | 
			
		||||
    else
 | 
			
		||||
        SetPedPropIndex(PlayerPedId(), 0, 116, 0, true)
 | 
			
		||||
-- Umbenannt für bessere Klarheit
 | 
			
		||||
RegisterNetEvent('nightvision:toggleGlasses', function()
 | 
			
		||||
    local ped = PlayerPedId()
 | 
			
		||||
    local currentGlasses = GetPedPropIndex(ped, 1)
 | 
			
		||||
    local gender = IsPedMale(ped) and "male" or "female"
 | 
			
		||||
    
 | 
			
		||||
    -- Wenn keine NV-Brille getragen wird, setze hochgeklappte Version auf
 | 
			
		||||
    if currentGlasses ~= Config.Glasses[gender].up and currentGlasses ~= Config.Glasses[gender].down then
 | 
			
		||||
        SetPedPropIndex(ped, 1, Config.Glasses[gender].up, 0, true)
 | 
			
		||||
        QBCore.Functions.Notify('Nachtsichtbrille aufgesetzt!')
 | 
			
		||||
    -- Wenn hochgeklappte NV-Brille getragen wird, klappe sie runter und aktiviere Nachtsicht
 | 
			
		||||
    elseif currentGlasses == Config.Glasses[gender].up then
 | 
			
		||||
        SetPedPropIndex(ped, 1, Config.Glasses[gender].down, 0, true)
 | 
			
		||||
        QBCore.Functions.Notify('Nachtsicht aktiviert!')
 | 
			
		||||
        SetNightvision(true)
 | 
			
		||||
        mode = 1
 | 
			
		||||
    -- Wenn runtergeklappte NV-Brille getragen wird, klappe sie hoch und deaktiviere Nachtsicht
 | 
			
		||||
    elseif currentGlasses == Config.Glasses[gender].down then
 | 
			
		||||
        SetPedPropIndex(ped, 1, Config.Glasses[gender].up, 0, true)
 | 
			
		||||
        QBCore.Functions.Notify('Nachtsicht deaktiviert!')
 | 
			
		||||
        SetNightvision(false)
 | 
			
		||||
        SetSeethrough(false)
 | 
			
		||||
        mode = 0
 | 
			
		||||
    end
 | 
			
		||||
end)
 | 
			
		||||
 | 
			
		||||
-- Behalte den alten Event-Namen für Kompatibilität
 | 
			
		||||
RegisterNetEvent('nightvision:toggleHelmet', function()
 | 
			
		||||
    TriggerEvent('nightvision:toggleGlasses')
 | 
			
		||||
end)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,5 +2,17 @@ Config = Config or {}
 | 
			
		|||
 | 
			
		||||
Config.CoreName = 'qb-core' -- Change this if you changed the core name.
 | 
			
		||||
Config.NVItem = 'nightvision' -- Item needed to use nightvision
 | 
			
		||||
Config.CheckHelmet = true -- Check if player has nightvision helmet (clothing)
 | 
			
		||||
Config.NVKey = 'N' -- The key you want to be pressed to toggle night/thermal vision (this is the default key, players can change this key in keybinds)
 | 
			
		||||
Config.CheckHelmet = true -- Umbenannt zu CheckGlasses wäre besser, aber für Kompatibilität belassen
 | 
			
		||||
Config.NVKey = 'N' -- The key you want to be pressed to toggle night/thermal vision
 | 
			
		||||
 | 
			
		||||
-- Neue Konfigurationsoptionen für die Brillen
 | 
			
		||||
Config.Glasses = {
 | 
			
		||||
    male = {
 | 
			
		||||
        up = 116,    -- ID für hochgeklappte NV-Brille (männlich) - Ändern Sie diese zu Ihrer tatsächlichen ID
 | 
			
		||||
        down = 117   -- ID für runtergeklappte NV-Brille (männlich) - Ändern Sie diese zu Ihrer tatsächlichen ID
 | 
			
		||||
    },
 | 
			
		||||
    female = {
 | 
			
		||||
        up = 70,    -- ID für hochgeklappte NV-Brille (weiblich) - Ändern Sie diese zu Ihrer tatsächlichen ID
 | 
			
		||||
        down = 73   -- ID für runtergeklappte NV-Brille (weiblich) - Ändern Sie diese zu Ihrer tatsächlichen ID
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue