local imgui = require 'mimgui'
local showMessage = false
local startTime = 0
local alpha = 0
local fadeDuration = 0.5
local displayDuration = 3
local windowWidth, windowHeight = 300, 100
local soundPath = 'moonloader/sounds/notification.mp3'
imgui.OnFrame(function() return showMessage and not isGamePaused() end, function()
local screenWidth, screenHeight = getScreenResolution()
imgui.SetNextWindowPos(imgui.ImVec2(screenWidth - windowWidth - 20, screenHeight - windowHeight - 20), imgui.Cond.Always, imgui.ImVec2(1, 1))
imgui.SetNextWindowSize(imgui.ImVec2(windowWidth, windowHeight), imgui.Cond.Always)
imgui.PushStyleVarFloat(imgui.StyleVar.Alpha, alpha)
imgui.Begin('Notification', nil, imgui.WindowFlags.NoMove + imgui.WindowFlags.NoDecoration + imgui.WindowFlags.AlwaysAutoResize)
imgui.Text('Привет')
imgui.End()
imgui.PopStyleVar()
end).HideCursor = true
function playSound(path)
local handle = loadAudioStream(path)
if handle then
setAudioStreamState(handle, 1)
else
print("Ошибка: Невозможно загрузить звук по пути " .. path)
end
end
function showTemporaryMessage()
showMessage = true
startTime = os.clock()
playSound(soundPath)
end
function main()
if not doesFileExist(soundPath) then
print("Файл звука не найден: " .. soundPath)
end
while true do
wait(0)
if showMessage then
local elapsed = os.clock() - startTime
if elapsed < fadeDuration then
alpha = elapsed / fadeDuration
elseif elapsed < displayDuration - fadeDuration then
alpha = 1
elseif elapsed < displayDuration then
alpha = 1 - (elapsed - (displayDuration - fadeDuration)) / fadeDuration
else
showMessage = false
alpha = 0
end
end
end
end
sampRegisterChatCommand('showmsg', function()
showTemporaryMessage()
end)