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

216 lines
7.1 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
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'
}
}
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:16:40 +02:00
-- Verbesserte Feuerwerk-Funktion
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
-- 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
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
print("Countdown beendet, starte Feuerwerk mit Asset: " .. asset)
2025-07-02 16:16:40 +02:00
-- Verschiedene Höhen für verschiedene Effekte
local heights = {15.0, 20.0, 25.0, 30.0}
2025-06-22 17:32:14 +02:00
for i = 1, math.random(5, 10), 1 do
2025-06-07 08:51:21 +02:00
local firework = fireworkList[asset][math.random(1, #fireworkList[asset])]
2025-07-02 16:16:40 +02:00
local height = heights[math.random(1, #heights)]
2025-06-22 17:32:14 +02:00
2025-07-02 16:16:40 +02:00
print("Starte Feuerwerk-Effekt: " .. firework .. " auf Höhe: " .. height)
2025-06-22 17:32:14 +02:00
2025-07-02 16:16:40 +02:00
-- Stelle sicher, dass das Asset für jeden Effekt aktiviert wird
2025-06-07 08:51:21 +02:00
UseParticleFxAssetNextCall(asset)
2025-07-02 16:16:40 +02:00
-- 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))
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
2025-07-02 16:16:40 +02:00
-- Lade alle Assets beim Start
2025-06-07 08:51:21 +02:00
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]
2025-07-02 16:16:40 +02:00
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)
2025-06-07 08:51:21 +02:00
end
end
2025-06-22 17:32:14 +02:00
print("Alle Feuerwerk-Assets geladen")
2025-06-07 08:51:21 +02:00
end)
RegisterNetEvent('fireworks:client:UseFirework', function(itemName, assetName)
2025-06-22 17:32:14 +02:00
print("Feuerwerk-Event ausgelöst mit Item: " .. itemName .. " und Asset: " .. assetName)
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:19:35 +02:00
RegisterCommand('testeffect', function()
local playerPed = PlayerPedId()
local coords = GetEntityCoords(playerPed)
-- Einfacher, garantiert funktionierender Effekt
RequestNamedPtfxAsset("core")
while not HasNamedPtfxAssetLoaded("core") do
Wait(10)
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)
end)