1
0
Fork 0
forked from Simnation/Main
Main/resources/[qb]/qb-smallresources/client/fireworks.lua

253 lines
8.3 KiB
Lua
Raw Normal View History

2025-06-07 08:51:21 +02:00
local QBCore = exports['qb-core']:GetCoreObject()
local fireworkTime = 0
local fireworkLoc = nil
2025-07-02 16:24:15 +02:00
-- 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ß
2025-06-07 08:51:21 +02:00
}
2025-07-02 16:24:15 +02:00
-- 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
2025-06-07 08:51:21 +02:00
local function DrawText3D(x, y, z, text)
SetTextScale(0.35, 0.35)
SetTextFont(4)
SetTextProportional(true)
SetTextColour(255, 255, 255, 215)
BeginTextCommandDisplayText('STRING')
SetTextCentre(true)
AddTextComponentSubstringPlayerName(text)
SetDrawOrigin(x, y, z, 0)
EndTextCommandDisplayText(0.0, 0.0)
local factor = (string.len(text)) / 370
DrawRect(0.0, 0.0 + 0.0125, 0.017 + factor, 0.03, 0, 0, 0, 75)
ClearDrawOrigin()
end
local function fireworkText()
CreateThread(function()
while true do
Wait(0)
if fireworkTime > 0 and fireworkLoc then
DrawText3D(fireworkLoc.x, fireworkLoc.y, fireworkLoc.z, Lang:t('firework.time_left') .. fireworkTime)
end
if fireworkTime <= 0 then break end
end
end)
end
2025-07-02 16:24:15 +02:00
-- Verbesserte Feuerwerk-Startfunktion
2025-06-07 08:51:21 +02:00
local function startFirework(asset, coords)
fireworkTime = Config.Fireworks.delay
fireworkLoc = { x = coords.x, y = coords.y, z = coords.z }
2025-07-02 16:16:40 +02:00
2025-06-07 08:51:21 +02:00
CreateThread(function()
fireworkText()
while fireworkTime > 0 do
Wait(1000)
2025-07-02 16:16:40 +02:00
fireworkTime = fireworkTime - 1
2025-06-07 08:51:21 +02:00
end
2025-06-22 17:32:14 +02:00
2025-07-02 16:24:15 +02:00
print("Countdown beendet, starte spektakuläres Feuerwerk")
2025-06-22 17:32:14 +02:00
2025-07-02 16:24:15 +02:00
-- 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
2025-07-02 16:16:40 +02:00
2025-07-02 16:24:15 +02:00
-- 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
}
2025-06-22 17:32:14 +02:00
2025-07-02 16:24:15 +02:00
launchFirework(newCoords, fireworkType)
Wait(math.random(800, 1500)) -- Warte zwischen den Feuerwerken
2025-06-07 08:51:21 +02:00
end
2025-07-02 16:16:40 +02:00
2025-06-07 08:51:21 +02:00
fireworkLoc = nil
end)
end
RegisterNetEvent('fireworks:client:UseFirework', function(itemName, assetName)
2025-07-02 16:24:15 +02:00
print("Feuerwerk-Event ausgelöst mit Item: " .. itemName)
2025-06-22 17:32:14 +02:00
2025-06-07 08:51:21 +02:00
QBCore.Functions.Progressbar('spawn_object', Lang:t('firework.place_progress'), 3000, false, true, {
disableMovement = true,
disableCarMovement = true,
disableMouse = false,
disableCombat = true,
}, {
animDict = 'anim@narcotics@trash',
anim = 'drop_front',
flags = 16,
}, {}, {}, function() -- Done
StopAnimTask(PlayerPedId(), 'anim@narcotics@trash', 'drop_front', 1.0)
TriggerServerEvent('consumables:server:UseFirework', itemName)
TriggerEvent('qb-inventory:client:ItemBox', QBCore.Shared.Items[itemName], 'remove')
local pos = GetEntityCoords(PlayerPedId())
2025-06-22 17:32:14 +02:00
print("Starte Feuerwerk an Position: " .. pos.x .. ", " .. pos.y .. ", " .. pos.z)
2025-06-07 08:51:21 +02:00
startFirework(assetName, pos)
end, function() -- Cancel
StopAnimTask(PlayerPedId(), 'anim@narcotics@trash', 'drop_front', 1.0)
QBCore.Functions.Notify(Lang:t('firework.canceled'), 'error')
end)
end)
2025-07-02 16:24:15 +02:00
-- Test-Befehl zum direkten Auslösen von Feuerwerk
RegisterCommand('feuerwerk', function(source, args)
2025-07-02 16:19:35 +02:00
local playerPed = PlayerPedId()
local coords = GetEntityCoords(playerPed)
2025-07-02 16:24:15 +02:00
-- 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
2025-07-02 16:19:35 +02:00
2025-07-02 16:24:15 +02:00
launchFirework(coords, type)
2025-07-02 16:19:35 +02:00
end)