Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- #######################################
- -- ## Project: Team Deathmatch 2.0 Res ##
- -- ## Name: Nametags.lua ##
- -- ## Author: Noneatme ##
- -- ## Version: 1.0 ##
- -- ## License: See top Folder ##
- -- #######################################
- -- FUNCTIONS / METHODS --
- local cFunc = {}; -- Local Functions
- local cSetting = {}; -- Local Settings
- Nametags = {};
- Nametags.__index = Nametags;
- --[[
- ]]
- -- ///////////////////////////////
- -- ///// New //////
- -- ///// Returns: Object //////
- -- ///////////////////////////////
- function Nametags:New(...)
- local obj = setmetatable({}, {__index = self});
- if obj.Constructor then
- obj:Constructor(...);
- end
- return obj;
- end
- -- ///////////////////////////////
- -- ///// Render //////
- -- ///// Returns: void //////
- -- ///////////////////////////////
- function Nametags:Render()
- local x2, y2, z2 = getCameraMatrix()
- for index, ped in pairs(getElementsByType("player", getRootElement(), true)) do
- setPlayerNametagShowing(ped, false)
- if(ped ~= localPlayer) then
- local x, y, z = getElementPosition(ped)
- local color = tocolor(0, 255, 0, 255)
- if(isLineOfSightClear(x, y, z, x2, y2, z2, true, true, false)) then
- local distance = getDistanceBetweenPoints3D(x2, y2, z2, x, y, z)
- z = z+getElementDistanceFromCentreOfMassToBaseOfModel(ped)
- local sx, sy = getScreenFromWorldPosition(x, y, z);
- local sx2, sy2 = getScreenFromWorldPosition(x, y, z+0.25);
- if(sx and sy) then
- -- Background
- local width = 256
- width = (width/distance)*5
- if(width >= 256) then
- width = 256;
- end
- local height = width/2
- local width2 = 256/100*getElementHealth(ped)
- local width3 = width/100*getElementHealth(ped)
- local name = getPlayerName(ped)
- local scale = (self.scale/distance)*5
- if(scale >= self.scale) then
- scale = self.scale
- end
- if(sx2 and sy2) then
- -- NAME --
- dxDrawText(name, sx2, sy2, sx2, sy2, tocolor(255, 255, 255, 255), scale, self.font, "center", "center")
- end
- -- Background
- dxDrawImage(sx-width/2, sy-height/2, width, height, "files/images/hud_healthbar_bg.png", 0, 0, 0, tocolor(255, 255, 255, 255))
- -- Healthbar empty
- dxDrawImage(sx-width/2, sy-height/2, width, height, "files/images/hud_healthbar_empty.png", 0, 0, 0, color)
- -- White
- --dxDrawImage(sx-width/2, sy-height/2, width, height, "files/images/hud_healthbar_white.png", 0, 0, 0, color)
- local oldhealth = self.oldHealth[ped]
- if(oldhealth) and (oldhealth-getElementHealth(ped) > 0) then
- local width4 = width/100*oldhealth
- dxDrawImage((sx-width/2), sy-height/2, width4, height, "files/images/hud_healthbar_white.png", 0, 0, 0, tocolor(255, 255, 255, 150))
- if(self.reversed[ped] == true) then
- if(self.oldHealth[ped] >= getElementHealth(ped)) then
- self.oldHealth[ped] = self.oldHealth[ped]-1.25
- end
- end
- end
- -- Health
- --dxDrawImageSection ( sx-width/2, sy-height/2, width, height, 50, 50, 50, 50, "picture.png" )
- --dxDrawImage(sx-width/2, sy-height/2, width2, height, "files/images/hud_healthbar_healthfull.png", 0, 0, 0, color)
- dxDrawImageSection ( sx-width/2, sy-height/2, width3, height, 0, 0, width2, 128, "files/images/hud_healthbar_healthfull.png", 0, 0, 0, color )
- end
- end
- end
- end
- end
- -- ///////////////////////////////
- -- ///// Constructor //////
- -- ///// Returns: void //////
- -- ///////////////////////////////
- function Nametags:Constructor(...)
- self.renderFunc = function() self:Render() end
- self.pedDamageFunc = function(_, _, _, loss)
- local player = source;
- if not(self.oldHealth[player]) then
- self.oldHealth[player] = getElementHealth(player);
- end
- self.reversed[player] = false;
- if(isTimer(self.updateTimer[player])) then
- killTimer(self.updateTimer[player])
- else
- self.oldHealth[player] = getElementHealth(player)+loss;
- end
- self.updateTimer[player] = setTimer(function()
- -- self.oldHealth[player] = getElementHealth(player)
- self.reversed[player] = true;
- end, 500, 1)
- end;
- self.oldHealth = {}
- self.updateTimer = {}
- self.reversed = {}
- self.scale = 0.3
- self.font = dxCreateFont("files/fonts/chicken.ttf", 60)
- addEventHandler("onClientPreRender", getRootElement(), self.renderFunc)
- addEventHandler("onClientPlayerDamage", getRootElement(), self.pedDamageFunc)
- setPedTargetingMarkerEnabled(false)
- outputDebugString("[CALLING] Nametags: Constructor");
- end
- -- EVENT HANDLER --
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement