Oto zmodyfikowany skrypt z automatycznym respawnem po zakończeniu efektu blur:
-- KONFIGURACJA
local CONFIG = {
blurPath = "img/blur.png", -- Ścieżka do grafiki blur
fadeInTime = 1000, -- Czas pojawiania się (ms)
fadeOutTime = 2000, -- Czas znikania (ms)
maxAlpha = 200, -- Maksymalna przezroczystość (0-255)
stayTime = 3000, -- Czas trwania pełnego efektu (ms)
-- USTAWIENIA RESPAWNU
respawnDelay = 500, -- Opóźnienie respawnu po zniknięciu blur (ms)
spawnX = 0, -- Pozycja X spawnu (0 = domyślna)
spawnY = 0, -- Pozycja Y spawnu (0 = domyślna)
spawnZ = 0, -- Pozycja Z spawnu (0 = domyślna)
useDefaultSpawn = true, -- Użyj domyślnego spawnu (true/false)
}
-- ZMIENNE
local blurStartTime = 0
local isBlurActive = false
local currentAlpha = 0
local blurPhase = "none" -- "fadeIn", "stay", "fadeOut", "none"
local respawnTimer = nil
-- FUNKCJA RENDERUJĄCA BLUR
local function renderBlur()
if not isBlurActive then return end
local now = getTickCount()
local elapsed = now - blurStartTime
-- Obliczanie alphy w zależności od fazy
if blurPhase == "fadeIn" then
currentAlpha = (elapsed / CONFIG.fadeInTime) * CONFIG.maxAlpha
if elapsed >= CONFIG.fadeInTime then
blurPhase = "stay"
blurStartTime = now
end
elseif blurPhase == "stay" then
currentAlpha = CONFIG.maxAlpha
if elapsed >= CONFIG.stayTime then
blurPhase = "fadeOut"
blurStartTime = now
end
elseif blurPhase == "fadeOut" then
currentAlpha = CONFIG.maxAlpha * (1 - elapsed / CONFIG.fadeOutTime)
if elapsed >= CONFIG.fadeOutTime then
stopBlur()
scheduleRespawn()
return
end
end
-- Ograniczenie alphy
currentAlpha = math.max(0, math.min(255, currentAlpha))
-- Pobieranie rozmiaru ekranu
local screenW, screenH = guiGetScreenSize()
-- Rysowanie obrazka blur na całym ekranie
dxDrawImage(
0, 0, -- Pozycja X, Y
screenW, screenH, -- Szerokość, Wysokość
CONFIG.blurPath, -- Ścieżka do obrazka
0, 0, 0, -- Rotacja, rotCenterX, rotCenterY
tocolor(255, 255, 255, currentAlpha) -- Kolor z alphą
)
end
-- FUNKCJA STARTUJĄCA BLUR
local function startBlur()
if isBlurActive then return end
isBlurActive = true
blurPhase = "fadeIn"
blurStartTime = getTickCount()
currentAlpha = 0
-- Anuluj respawn timer jeśli istnieje
if isTimer(respawnTimer) then
killTimer(respawnTimer)
respawnTimer = nil
end
addEventHandler("onClientRender", root, renderBlur)
end
-- FUNKCJA ZATRZYMUJĄCA BLUR
function stopBlur()
isBlurActive = false
blurPhase = "none"
currentAlpha = 0
removeEventHandler("onClientRender", root, renderBlur)
end
-- FUNKCJA PLANUJĄCA RESPAWN
function scheduleRespawn()
-- Anuluj poprzedni timer jeśli istnieje
if isTimer(respawnTimer) then
killTimer(respawnTimer)
end
-- Ustaw nowy timer respawnu
respawnTimer = setTimer(function()
triggerServerEvent("onPlayerRequestRespawn", localPlayer, CONFIG)
respawnTimer = nil
end, CONFIG.respawnDelay, 1)
end
-- EVENT: ŚMIERĆ GRACZA
addEventHandler("onClientPlayerWasted", localPlayer, function()
startBlur()
end)
-- EVENT: SPAWN GRACZA (opcjonalne - usuwa blur przy respawnie)
addEventHandler("onClientPlayerSpawn", localPlayer, function()
if isBlurActive then
stopBlur()
end
-- Anuluj timer respawnu jeśli istnieje
if isTimer(respawnTimer) then
killTimer(respawnTimer)
respawnTimer = nil
end
end)
-- KOMENDY DO TESTOWANIA (opcjonalne)
addCommandHandler("testblur", function()
startBlur()
end)
addCommandHandler("stopblur", function()
stopBlur()
end)
-- CZYSZCZENIE PRZY WYŁĄCZENIU ZASOBU
addEventHandler("onClientResourceStop", resourceRoot, function()
if isTimer(respawnTimer) then
killTimer(respawnTimer)
end
end)