Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.13 KB | None | 0 0
  1. local sx,sy = guiGetScreenSize();
  2.  
  3. local zoom = 1
  4. local fh = 2048
  5. if sx < fh then
  6. zoom = math.min(2,fh/sx)
  7. end
  8.  
  9. local hud = {};
  10.  
  11. hud.tick = false;
  12. hud.health = getElementHealth(localPlayer);
  13. hud.oldHealth = 0;
  14. hud.money = getPlayerMoney(localPlayer);
  15. hud.oldMoney = 0;
  16.  
  17. local textures = {};
  18.  
  19. textures['avatar'] = dxCreateTexture('images/avatar.png','argb',true,'clamp');
  20. textures['pasek'] = dxCreateTexture('images/pasek.png','argb',true,'clamp');
  21. textures['pasekp'] = dxCreateTexture('images/pasek2.png','argb',true,'clamp');
  22.  
  23. local font = false;
  24.  
  25. text=function(text,x,y,w,h,color,scale,alX)
  26. return dxDrawText(text,x,y,w+x,h+y,color,1,font,alX or 'center','center',false,false,false,false,false);
  27. end
  28.  
  29. hud.render=function()
  30.  
  31. local alpha = interpolateBetween(0,0,0,255,0,0,(getTickCount()-hud.tick)/300,'OutQuad');
  32.  
  33. local health = interpolateBetween(hud.oldHealth,0,0,hud.health,0,0,(getTickCount()-hud.healthTick)/1000,'OutQuad');
  34.  
  35. dxDrawImage(sx-550/zoom,30/zoom,150/zoom,150/zoom,textures['avatar'],0,0,0,tocolor(255,255,255,alpha));
  36. dxDrawImage(sx-380/zoom,60/zoom,336/zoom,34/zoom,textures['pasekp'],0,0,0,tocolor(255,255,255,alpha));
  37. dxDrawImageSection(sx-380/zoom,60/zoom,(336 * (health/100) )/zoom,34/zoom,sx-380/zoom,60/zoom,(336 * (health/100) )/zoom,34/zoom,textures['pasek'],0,0,0,tocolor(255,255,255,alpha));
  38.  
  39. local money = interpolateBetween(hud.oldMoney,0,0,hud.money,0,0,(getTickCount()-hud.moneyTick)/1500,'Linear');
  40. local moneyReverse = interpolateBetween(math.abs((hud.oldMoney-hud.money)),0,0,0,0,0,(getTickCount()-hud.moneyTick)/1500,'Linear');
  41.  
  42. text(math.floor(money)..'$',sx-380/zoom,100/zoom,336/zoom,34/zoom,tocolor(255,255,255,alpha),3/zoom,'left');
  43. if (getTickCount()-hud.moneyTick) <= 2000 then
  44.  
  45. local znak = hud.oldMoney > hud.money and '-' or '+';
  46.  
  47. text(znak..' '..math.floor(moneyReverse)..'$',sx-380/zoom,150/zoom,336/zoom,34/zoom,tocolor(255,255,255,alpha),3/zoom,'left');
  48. end
  49.  
  50. end
  51.  
  52. setPlayerHudComponentVisible('all',false);
  53.  
  54. hud.init = function()
  55.  
  56. hud.tick = getTickCount();
  57. hud.moneyTick = getTickCount();
  58. hud.healthTick = getTickCount();
  59. hud.health = getElementHealth(localPlayer);
  60. hud.oldHealth = 0;
  61. hud.money = getPlayerMoney(localPlayer);
  62. hud.oldMoney = 0;
  63.  
  64. addEventHandler('onClientRender',root,hud.render);
  65.  
  66. end
  67.  
  68. hud.onChange = function(type,oldValue,newValue)
  69.  
  70. if type == 'money' then
  71. hud.moneyTick = getTickCount();
  72. hud.oldMoney = oldValue;
  73. hud.money = newValue;
  74. elseif type == 'health' then
  75. hud.healthTick = getTickCount();
  76. hud.oldHealth = oldValue;
  77. hud.health = newValue;
  78. end
  79.  
  80. end
  81.  
  82. addEvent('init:hud',true)
  83. addEventHandler('init:hud',root,function()
  84. hud.init();
  85. font = exports['lrpg-dxGui']:dxGetFont('normal')
  86. end)
  87.  
  88. -- oldMoneyEvent
  89.  
  90. local oldMoney = getPlayerMoney();
  91. local oldHealth = getElementHealth(localPlayer);
  92.  
  93. function renderMoney()
  94. newMoney = getPlayerMoney();
  95. if ( tonumber(newMoney) ~= tonumber(oldMoney) ) then
  96. triggerEvent("onClientMoneyChange",localPlayer,oldMoney,newMoney);
  97. oldMoney = newMoney;
  98. end
  99. newHealth = getElementHealth(localPlayer);
  100. if ( tonumber(newHealth) ~= tonumber(oldHealth) ) then
  101. triggerEvent("onClientHealthChange",localPlayer,oldHealth,newHealth);
  102. oldHealth = newHealth;
  103. end
  104. end
  105. addEventHandler("onClientRender",root,renderMoney)
  106.  
  107. addEvent("onClientMoneyChange",true)
  108. addEventHandler("onClientMoneyChange",root,
  109. function (old, new)
  110. local znak = old > new and 'Zabrano z ' or 'Dodano do ';
  111. outputConsole('[INFO] '..znak..'portfela '..math.abs((old-new))..''..'$');
  112. hud.onChange('money',old,new);
  113. end)
  114.  
  115. addEvent("onClientHealthChange",true)
  116. addEventHandler("onClientHealthChange",root,
  117. function (old, new)
  118. hud.onChange('health',old,new);
  119. end)
  120.  
  121. addEventHandler('onClientResourceStart',resourceRoot,function()
  122. if getElementData(localPlayer,'player:logged') then
  123. hud.init();
  124. font = exports['lrpg-dxGui']:dxGetFont('normal')
  125. end
  126. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement