Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local sx,sy = guiGetScreenSize();
- local zoom = 1
- local fh = 2048
- if sx < fh then
- zoom = math.min(2,fh/sx)
- end
- local hud = {};
- hud.tick = false;
- hud.health = getElementHealth(localPlayer);
- hud.oldHealth = 0;
- hud.money = getPlayerMoney(localPlayer);
- hud.oldMoney = 0;
- local textures = {};
- textures['avatar'] = dxCreateTexture('images/avatar.png','argb',true,'clamp');
- textures['pasek'] = dxCreateTexture('images/pasek.png','argb',true,'clamp');
- textures['pasekp'] = dxCreateTexture('images/pasek2.png','argb',true,'clamp');
- local font = false;
- text=function(text,x,y,w,h,color,scale,alX)
- return dxDrawText(text,x,y,w+x,h+y,color,1,font,alX or 'center','center',false,false,false,false,false);
- end
- hud.render=function()
- local alpha = interpolateBetween(0,0,0,255,0,0,(getTickCount()-hud.tick)/300,'OutQuad');
- local health = interpolateBetween(hud.oldHealth,0,0,hud.health,0,0,(getTickCount()-hud.healthTick)/1000,'OutQuad');
- dxDrawImage(sx-550/zoom,30/zoom,150/zoom,150/zoom,textures['avatar'],0,0,0,tocolor(255,255,255,alpha));
- dxDrawImage(sx-380/zoom,60/zoom,336/zoom,34/zoom,textures['pasekp'],0,0,0,tocolor(255,255,255,alpha));
- 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));
- local money = interpolateBetween(hud.oldMoney,0,0,hud.money,0,0,(getTickCount()-hud.moneyTick)/1500,'Linear');
- local moneyReverse = interpolateBetween(math.abs((hud.oldMoney-hud.money)),0,0,0,0,0,(getTickCount()-hud.moneyTick)/1500,'Linear');
- text(math.floor(money)..'$',sx-380/zoom,100/zoom,336/zoom,34/zoom,tocolor(255,255,255,alpha),3/zoom,'left');
- if (getTickCount()-hud.moneyTick) <= 2000 then
- local znak = hud.oldMoney > hud.money and '-' or '+';
- text(znak..' '..math.floor(moneyReverse)..'$',sx-380/zoom,150/zoom,336/zoom,34/zoom,tocolor(255,255,255,alpha),3/zoom,'left');
- end
- end
- setPlayerHudComponentVisible('all',false);
- hud.init = function()
- hud.tick = getTickCount();
- hud.moneyTick = getTickCount();
- hud.healthTick = getTickCount();
- hud.health = getElementHealth(localPlayer);
- hud.oldHealth = 0;
- hud.money = getPlayerMoney(localPlayer);
- hud.oldMoney = 0;
- addEventHandler('onClientRender',root,hud.render);
- end
- hud.onChange = function(type,oldValue,newValue)
- if type == 'money' then
- hud.moneyTick = getTickCount();
- hud.oldMoney = oldValue;
- hud.money = newValue;
- elseif type == 'health' then
- hud.healthTick = getTickCount();
- hud.oldHealth = oldValue;
- hud.health = newValue;
- end
- end
- addEvent('init:hud',true)
- addEventHandler('init:hud',root,function()
- hud.init();
- font = exports['lrpg-dxGui']:dxGetFont('normal')
- end)
- -- oldMoneyEvent
- local oldMoney = getPlayerMoney();
- local oldHealth = getElementHealth(localPlayer);
- function renderMoney()
- newMoney = getPlayerMoney();
- if ( tonumber(newMoney) ~= tonumber(oldMoney) ) then
- triggerEvent("onClientMoneyChange",localPlayer,oldMoney,newMoney);
- oldMoney = newMoney;
- end
- newHealth = getElementHealth(localPlayer);
- if ( tonumber(newHealth) ~= tonumber(oldHealth) ) then
- triggerEvent("onClientHealthChange",localPlayer,oldHealth,newHealth);
- oldHealth = newHealth;
- end
- end
- addEventHandler("onClientRender",root,renderMoney)
- addEvent("onClientMoneyChange",true)
- addEventHandler("onClientMoneyChange",root,
- function (old, new)
- local znak = old > new and 'Zabrano z ' or 'Dodano do ';
- outputConsole('[INFO] '..znak..'portfela '..math.abs((old-new))..''..'$');
- hud.onChange('money',old,new);
- end)
- addEvent("onClientHealthChange",true)
- addEventHandler("onClientHealthChange",root,
- function (old, new)
- hud.onChange('health',old,new);
- end)
- addEventHandler('onClientResourceStart',resourceRoot,function()
- if getElementData(localPlayer,'player:logged') then
- hud.init();
- font = exports['lrpg-dxGui']:dxGetFont('normal')
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement