PapitoEUS

Untitled

Aug 21st, 2021
501
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.73 KB | None | 0 0
  1. local sx, sy = guiGetScreenSize()
  2.  
  3. local tick
  4.  
  5. local font = dxCreateFont('medium.ttf', 13/1920*sx, true);
  6.  
  7. local colors = {
  8.     error = tocolor(252, 3, 3),
  9.     info = tocolor(252, 186, 3),
  10.     success = tocolor(69, 219, 46),
  11. }
  12.  
  13. local notifications = {};
  14.  
  15. function anim(startTick, startValue, stopValue, time, type)
  16.     local anim = interpolateBetween(startValue, 0, 0, stopValue, 0, 0, (getTickCount() - startTick) / time, type)
  17.  
  18.     if (getTickCount() - startTick) > time then
  19.         return anim, false
  20.     else
  21.         return anim, true
  22.     end
  23. end
  24.  
  25. function renderNoti()
  26.     for index, value in pairs(notifications) do
  27.  
  28.         noti = anim(tick, 1800, 1493, 2000, 'Linear')
  29.  
  30.         if getTickCount() > value[3] + (value[4] + 500) then
  31.             table.remove(notifications, 1)
  32.             if (#notifications == 0) then
  33.                 removeEventHandler('onClientRender', root, renderNoti);
  34.             end
  35.         end
  36.  
  37.         local addY = 100 * (index - 1);
  38.         dxDrawRectangle(noti, 340 + addY, 417, 93, tocolor(34, 35, 66, 255), false)
  39.         dxDrawText(value[2], 1493, 339 + addY, 1910, 430 + addY, tocolor(255, 255, 255, 255), 1, font, 'center', 'center', false, true, true);
  40.     end
  41. end
  42.  
  43. function createAlert(type, text)
  44.     if not type then type = 'info' end
  45.  
  46.     tick = getTickCount
  47.     table.insert(notifications, { type, text, getTickCount(), 5000});
  48.     outputConsole('['..type..'] '..text);
  49.     if (#notifications == 1) then
  50.         addEventHandler('onClientRender', root, renderNoti);
  51.     end
  52.     if (#notifications > 5) then
  53.         table.remove(notifications, 1);
  54.     end
  55. end
  56.  
  57. addEvent("createAlert", true)
  58. addEventHandler("createAlert", resourceRoot,
  59.     function(...)
  60.         createAlert(...)
  61.     end
  62. )
  63.  
  64. addCommandHandler("createAlert1", function()
  65.     createAlert("success", "Pomyślnie się zalogowałeś!")
  66. end)
Advertisement
Add Comment
Please, Sign In to add comment