forked from Simnation/Main
edit
This commit is contained in:
parent
a306f1926d
commit
5f1be0d938
2 changed files with 146 additions and 0 deletions
|
@ -1,6 +1,8 @@
|
|||
local QBCore = exports[Config.CoreName]:GetCoreObject()
|
||||
local nvMode = 0
|
||||
local thermalMode = 0
|
||||
local flashlightActive = false
|
||||
local flashlightObject = nil
|
||||
|
||||
-- Funktion zum Prüfen des Charaktergeschlechts
|
||||
local function IsPedMale(ped)
|
||||
|
@ -15,6 +17,17 @@ local function IsWearingGlasses(ped, glassesConfig)
|
|||
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)
|
||||
|
@ -28,6 +41,101 @@ local function DisableAllVisionModes()
|
|||
thermalMode = 0
|
||||
end
|
||||
|
||||
-- Funktion zum Aktivieren der Helm-Lampe
|
||||
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
|
||||
|
||||
if flashlightActive then
|
||||
-- Deaktiviere die Lampe
|
||||
if DoesEntityExist(flashlightObject) then
|
||||
DeleteEntity(flashlightObject)
|
||||
flashlightObject = nil
|
||||
end
|
||||
flashlightActive = false
|
||||
QBCore.Functions.Notify('Helm-Lampe ausgeschaltet!')
|
||||
else
|
||||
-- Aktiviere die Lampe
|
||||
local boneIndex = GetPedBoneIndex(ped, 31086) -- Kopf-Knochen
|
||||
|
||||
-- Erstelle ein Licht-Objekt
|
||||
local coords = GetEntityCoords(ped)
|
||||
flashlightObject = CreateObject(GetHashKey("prop_cs_police_torch"), coords.x, coords.y, coords.z, true, true, true)
|
||||
|
||||
-- Mache das Objekt unsichtbar, aber behalte das Licht
|
||||
SetEntityVisible(flashlightObject, false, 0)
|
||||
SetEntityCollision(flashlightObject, false, false)
|
||||
|
||||
-- Befestige das Objekt am Kopf
|
||||
AttachEntityToEntity(
|
||||
flashlightObject,
|
||||
ped,
|
||||
boneIndex,
|
||||
Config.Flashlight.offset.x,
|
||||
Config.Flashlight.offset.y,
|
||||
Config.Flashlight.offset.z,
|
||||
0.0, 0.0, 0.0,
|
||||
true, true, false, true, 0, true
|
||||
)
|
||||
|
||||
-- Erstelle ein Licht
|
||||
local c = Config.Flashlight.color
|
||||
local range = Config.Flashlight.range
|
||||
local intensity = Config.Flashlight.intensity
|
||||
|
||||
-- Verwende natives Licht-System
|
||||
SetEntityLights(flashlightObject, false)
|
||||
|
||||
flashlightActive = true
|
||||
QBCore.Functions.Notify('Helm-Lampe eingeschaltet!')
|
||||
end
|
||||
end
|
||||
|
||||
-- Thread für das Licht-Update
|
||||
Citizen.CreateThread(function()
|
||||
while true do
|
||||
Citizen.Wait(0)
|
||||
|
||||
if flashlightActive and DoesEntityExist(flashlightObject) 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
|
||||
if DoesEntityExist(flashlightObject) then
|
||||
DeleteEntity(flashlightObject)
|
||||
flashlightObject = nil
|
||||
end
|
||||
flashlightActive = false
|
||||
QBCore.Functions.Notify('Helm-Lampe ausgeschaltet, da der Helm abgenommen wurde!', 'error')
|
||||
Citizen.Wait(500)
|
||||
else
|
||||
local pos = GetEntityCoords(ped)
|
||||
local forwardVector = GetEntityForwardVector(ped)
|
||||
local c = Config.Flashlight.color
|
||||
local range = Config.Flashlight.range
|
||||
local intensity = Config.Flashlight.intensity
|
||||
|
||||
-- Zeichne das Licht in Blickrichtung
|
||||
DrawSpotLight(
|
||||
pos.x, pos.y, pos.z + 1.0,
|
||||
forwardVector.x, forwardVector.y, forwardVector.z,
|
||||
c.r, c.g, c.b,
|
||||
range, intensity,
|
||||
0.0, 1.0, 1.0
|
||||
)
|
||||
end
|
||||
else
|
||||
Citizen.Wait(500) -- Längere Wartezeit, wenn keine Lampe aktiv ist
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
-- Nachtsicht-Befehl
|
||||
RegisterCommand('toggleNV', function()
|
||||
local ped = PlayerPedId()
|
||||
|
@ -134,9 +242,15 @@ RegisterCommand('toggleThermal', function()
|
|||
end
|
||||
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)
|
||||
|
@ -204,3 +318,16 @@ end)
|
|||
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 und entferne Objekte
|
||||
DisableAllVisionModes()
|
||||
|
||||
if DoesEntityExist(flashlightObject) then
|
||||
DeleteEntity(flashlightObject)
|
||||
flashlightObject = nil
|
||||
end
|
||||
end)
|
||||
|
|
|
@ -39,3 +39,22 @@ Config.Glasses = {
|
|||
}
|
||||
}
|
||||
|
||||
-- Flashlight configuration
|
||||
Config.Flashlight = {
|
||||
color = {r = 255, g = 255, b = 255}, -- Farbe des Lichts (weiß)
|
||||
range = 30.0, -- Reichweite des Lichts
|
||||
intensity = 8.0, -- Intensität des Lichts
|
||||
offset = {x = 0.0, y = 0.3, z = 0.0} -- Position des Lichts relativ zum Kopf
|
||||
}
|
||||
|
||||
-- Helm-Konfiguration für die Lampe
|
||||
Config.FlashlightHelmet = {
|
||||
male = {
|
||||
drawable = 117, -- ID des Helms mit Lampe (männlich)
|
||||
texture = 0 -- Textur des Helms mit Lampe (männlich)
|
||||
},
|
||||
female = {
|
||||
drawable = 283, -- ID des Helms mit Lampe (weiblich)
|
||||
texture = 1 -- Textur des Helms mit Lampe (weiblich)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue