diff --git a/resources/[qb]/qb-smallresources/client/fireworks.lua b/resources/[qb]/qb-smallresources/client/fireworks.lua index 70ea817e5..84bf7c25c 100644 --- a/resources/[qb]/qb-smallresources/client/fireworks.lua +++ b/resources/[qb]/qb-smallresources/client/fireworks.lua @@ -1,40 +1,146 @@ local QBCore = exports['qb-core']:GetCoreObject() local fireworkTime = 0 local fireworkLoc = nil -local fireworkList = { - ['proj_xmas_firework'] = { - 'scr_firework_xmas_ring_burst_rgw', - 'scr_firework_xmas_burst_rgw', - 'scr_firework_xmas_repeat_burst_rgw', - 'scr_firework_xmas_spiral_burst_rgw', - 'scr_xmas_firework_sparkle_spawn' - }, - ['scr_indep_fireworks'] = { - 'scr_indep_firework_sparkle_spawn', - 'scr_indep_firework_starburst', - 'scr_indep_firework_shotburst', - 'scr_indep_firework_trailburst', - 'scr_indep_firework_trailburst_spawn', - 'scr_indep_firework_burst_spawn', - 'scr_indep_firework_trail_spawn', - 'scr_indep_firework_fountain' - }, - ['proj_indep_firework'] = { - 'scr_indep_firework_grd_burst', - 'scr_indep_launcher_sparkle_spawn', - 'scr_indep_firework_air_burst', - 'proj_indep_flare_trail' - }, - ['proj_indep_firework_v2'] = { - 'scr_firework_indep_burst_rwb', - 'scr_firework_indep_spiral_burst_rwb', - 'scr_xmas_firework_sparkle_spawn', - 'scr_firework_indep_ring_burst_rwb', - 'scr_xmas_firework_burst_fizzle', - 'scr_firework_indep_repeat_burst_rwb' - } + +-- Liste der verfügbaren Feuerwerksraketen-Modelle +local fireworkProps = { + "ind_prop_firework_01", -- Standard-Feuerwerksrakete + "ind_prop_firework_02", -- Mittlere Feuerwerksrakete + "ind_prop_firework_03", -- Große Feuerwerksrakete + "ind_prop_firework_04" -- Feuerwerksraketen-Batterie } +-- Farben für die Feuerwerkseffekte +local colors = { + {r = 255, g = 0, b = 0}, -- Rot + {r = 0, g = 255, b = 0}, -- Grün + {r = 0, g = 0, b = 255}, -- Blau + {r = 255, g = 255, b = 0}, -- Gelb + {r = 255, g = 0, b = 255}, -- Magenta + {r = 0, g = 255, b = 255}, -- Cyan + {r = 255, g = 255, b = 255} -- Weiß +} + +-- Verbesserte Feuerwerk-Funktion mit sichtbaren Raketen +local function launchFirework(coords, type) + -- Wähle ein Feuerwerksmodell basierend auf dem Typ oder zufällig + local propModel = fireworkProps[type or math.random(1, #fireworkProps)] + local pedCoords = coords + + -- Lade das Modell + RequestModel(GetHashKey(propModel)) + while not HasModelLoaded(GetHashKey(propModel)) do + Wait(10) + end + + -- Erstelle die sichtbare Feuerwerksrakete + local prop = CreateObject(GetHashKey(propModel), + pedCoords.x, pedCoords.y, pedCoords.z, + true, true, false) + + -- Stelle sicher, dass die Rakete aufrecht steht + PlaceObjectOnGroundProperly(prop) + FreezeEntityPosition(prop, true) + + -- Warte kurz, damit die Rakete sichtbar ist + Wait(500) + + -- Füge einen Zündungseffekt hinzu + RequestNamedPtfxAsset("core") + while not HasNamedPtfxAssetLoaded("core") do + Wait(10) + end + + UseParticleFxAssetNextCall("core") + local ignitionEffect = StartParticleFxLoopedOnEntity("ent_amb_torch_fire", + prop, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.5, false, false, false) + + -- Zündungsgeräusch + PlaySoundFromEntity(-1, "DISTANT_FIREWORK_LAUNCH_01", prop, "dlc_sum20_beach_party_sounds", true, 20) + + -- Warte kurz für den Zündungseffekt + Wait(1000) + + -- Starte den Aufstiegseffekt + UseParticleFxAssetNextCall("core") + local upEffect = StartParticleFxLoopedOnEntity("ent_dst_gen_firework", + prop, 0.0, 0.0, 0.2, 0.0, 0.0, 0.0, 1.0, false, false, false) + + -- Stoppe den Zündungseffekt + StopParticleFxLooped(ignitionEffect, 0) + + -- Bewege die Rakete nach oben + local startTime = GetGameTimer() + local duration = 2500 -- 2.5 Sekunden Aufstieg + local height = math.random(30, 50) + local startZ = GetEntityCoords(prop).z + + -- Aufstiegsschleife + while GetGameTimer() - startTime < duration do + local progress = (GetGameTimer() - startTime) / duration + local newZ = startZ + (height * progress) + SetEntityCoords(prop, pedCoords.x, pedCoords.y, newZ) + Wait(0) + end + + -- Stoppe den Aufstiegseffekt + StopParticleFxLooped(upEffect, 0) + + -- Verstecke die Rakete + SetEntityVisible(prop, false, 0) + + -- Wähle eine zufällige Farbe + local color = colors[math.random(1, #colors)] + + -- Hauptexplosion + AddExplosion( + pedCoords.x, pedCoords.y, startZ + height, + 38, -- EXPLOSION_FIREWORK + 1.0, -- Schaden + true, -- isAudible + false, -- isInvisible + 0.0 -- Kamera-Shake + ) + + -- Füge mehrere Partikeleffekte für ein spektakuläres Feuerwerk hinzu + for i = 1, 5 do + -- Zufällige Positionen um den Explosionspunkt + local offsetX = math.random(-8, 8) + local offsetY = math.random(-8, 8) + local offsetZ = math.random(-4, 4) + + -- Verschiedene Explosionseffekte + local effects = { + "exp_grd_grenade", + "exp_air_molotov", + "exp_grd_petrol_pump", + "exp_grd_flare" + } + + UseParticleFxAssetNextCall("core") + StartParticleFxNonLoopedAtCoord( + effects[math.random(1, #effects)], + pedCoords.x + offsetX, + pedCoords.y + offsetY, + startZ + height + offsetZ, + 0.0, 0.0, 0.0, + math.random(15, 25) / 10, -- Zufällige Skalierung + false, false, false + ) + + -- Explosionsgeräusch + PlaySoundFromCoord(-1, "DISTANT_FIREWORK_BURST_0" .. math.random(1, 3), + pedCoords.x + offsetX, pedCoords.y + offsetY, startZ + height + offsetZ, + "dlc_sum20_beach_party_sounds", true, 50, false) + + Wait(math.random(100, 300)) + end + + -- Lösche die Rakete nach einer Weile + Wait(5000) + DeleteEntity(prop) +end + local function DrawText3D(x, y, z, text) SetTextScale(0.35, 0.35) SetTextFont(4) @@ -62,26 +168,11 @@ local function fireworkText() end) end --- Verbesserte Feuerwerk-Funktion +-- Verbesserte Feuerwerk-Startfunktion local function startFirework(asset, coords) fireworkTime = Config.Fireworks.delay fireworkLoc = { x = coords.x, y = coords.y, z = coords.z } - -- Stelle sicher, dass das Asset geladen ist - if not HasNamedPtfxAssetLoaded(asset) then - RequestNamedPtfxAsset(asset) - local timeout = 0 - while not HasNamedPtfxAssetLoaded(asset) and timeout < 100 do - Wait(10) - timeout = timeout + 1 - end - - if timeout >= 100 then - print("Fehler: Asset konnte nicht geladen werden: " .. asset) - return - end - end - CreateThread(function() fireworkText() while fireworkTime > 0 do @@ -89,82 +180,40 @@ local function startFirework(asset, coords) fireworkTime = fireworkTime - 1 end - print("Countdown beendet, starte Feuerwerk mit Asset: " .. asset) + print("Countdown beendet, starte spektakuläres Feuerwerk") - -- Verschiedene Höhen für verschiedene Effekte - local heights = {15.0, 20.0, 25.0, 30.0} + -- Bestimme den Feuerwerkstyp basierend auf dem Asset + local fireworkType = 1 -- Standard + if asset == "proj_xmas_firework" then + fireworkType = 2 + elseif asset == "scr_indep_fireworks" then + fireworkType = 3 + elseif asset == "proj_indep_firework_v2" then + fireworkType = 4 + end - for i = 1, math.random(5, 10), 1 do - local firework = fireworkList[asset][math.random(1, #fireworkList[asset])] - local height = heights[math.random(1, #heights)] + -- Starte mehrere Feuerwerke nacheinander + local numFireworks = math.random(3, 6) + for i = 1, numFireworks do + -- Leichte Variation in der Position + local offsetX = math.random(-3, 3) + local offsetY = math.random(-3, 3) + local newCoords = { + x = coords.x + offsetX, + y = coords.y + offsetY, + z = coords.z + } - print("Starte Feuerwerk-Effekt: " .. firework .. " auf Höhe: " .. height) - - -- Stelle sicher, dass das Asset für jeden Effekt aktiviert wird - UseParticleFxAssetNextCall(asset) - - -- Erhöhte Skalierung für bessere Sichtbarkeit - local scale = math.random() * 0.8 + 1.2 -- Zwischen 1.2 und 2.0 - - -- Starte den Effekt - local success = StartParticleFxNonLoopedAtCoord( - firework, - fireworkLoc.x, - fireworkLoc.y, - fireworkLoc.z + height, - 0.0, 0.0, 0.0, - scale, - false, false, false - ) - - if success then - print("Effekt erfolgreich gestartet") - else - print("Fehler beim Starten des Effekts") - end - - -- Füge einen Soundeffekt hinzu - PlaySoundFromCoord(-1, "firework_burst_01", fireworkLoc.x, fireworkLoc.y, fireworkLoc.z, "dlc_sum20_beach_party_sounds", true, 20.0, false) - - -- Variiere die Wartezeit zwischen den Effekten - Wait(math.random(200, 800)) + launchFirework(newCoords, fireworkType) + Wait(math.random(800, 1500)) -- Warte zwischen den Feuerwerken end fireworkLoc = nil end) end --- Lade alle Assets beim Start -CreateThread(function() - local assets = { - 'scr_indep_fireworks', - 'proj_xmas_firework', - 'proj_indep_firework_v2', - 'proj_indep_firework' - } - - for i = 1, #assets do - local asset = assets[i] - print("Lade Asset: " .. asset) - RequestNamedPtfxAsset(asset) - local timeout = 0 - while not HasNamedPtfxAssetLoaded(asset) and timeout < 500 do - Wait(10) - timeout = timeout + 1 - end - - if HasNamedPtfxAssetLoaded(asset) then - print("Asset erfolgreich geladen: " .. asset) - else - print("Fehler beim Laden des Assets: " .. asset) - end - end - - print("Alle Feuerwerk-Assets geladen") -end) - RegisterNetEvent('fireworks:client:UseFirework', function(itemName, assetName) - print("Feuerwerk-Event ausgelöst mit Item: " .. itemName .. " und Asset: " .. assetName) + print("Feuerwerk-Event ausgelöst mit Item: " .. itemName) QBCore.Functions.Progressbar('spawn_object', Lang:t('firework.place_progress'), 3000, false, true, { disableMovement = true, @@ -189,27 +238,15 @@ RegisterNetEvent('fireworks:client:UseFirework', function(itemName, assetName) QBCore.Functions.Notify(Lang:t('firework.canceled'), 'error') end) end) -RegisterCommand('testeffect', function() + +-- Test-Befehl zum direkten Auslösen von Feuerwerk +RegisterCommand('feuerwerk', function(source, args) local playerPed = PlayerPedId() local coords = GetEntityCoords(playerPed) - -- Einfacher, garantiert funktionierender Effekt - RequestNamedPtfxAsset("core") - while not HasNamedPtfxAssetLoaded("core") do - Wait(10) - end + -- Optional: Typ des Feuerwerks als Argument + local type = tonumber(args[1]) or math.random(1, 4) + if type < 1 or type > 4 then type = 1 end - UseParticleFxAssetNextCall("core") - local effect = StartParticleFxLoopedAtCoord("ent_sht_flame", - coords.x, coords.y, coords.z + 0.5, - 0.0, 0.0, 0.0, - 2.0, -- scale - false, false, false, false) - - print("Test-Effekt gestartet: " .. tostring(effect)) - - -- Effekt nach 5 Sekunden stoppen - Citizen.SetTimeout(5000, function() - StopParticleFxLooped(effect, 0) - end) + launchFirework(coords, type) end)