Advertisement
Noneatme

Untitled

Jul 18th, 2013
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.66 KB | None | 0 0
  1. -- #######################################
  2. -- ## Project:  Team Deathmatch 2.0 Res ##
  3. -- ## Name: Nametags.lua                    ##
  4. -- ## Author: Noneatme                  ##
  5. -- ## Version: 1.0                      ##
  6. -- ## License: See top Folder           ##
  7. -- #######################################
  8.  
  9. -- FUNCTIONS / METHODS --
  10.  
  11. local cFunc = {};       -- Local Functions
  12. local cSetting = {};    -- Local Settings
  13.  
  14. Nametags = {};
  15. Nametags.__index = Nametags;
  16.  
  17. --[[
  18.  
  19. ]]
  20.  
  21. -- ///////////////////////////////
  22. -- ///// New                //////
  23. -- ///// Returns: Object    //////
  24. -- ///////////////////////////////
  25.  
  26. function Nametags:New(...)
  27.     local obj = setmetatable({}, {__index = self});
  28.     if obj.Constructor then
  29.         obj:Constructor(...);
  30.     end
  31.     return obj;
  32. end
  33.  
  34. -- ///////////////////////////////
  35. -- ///// Render             //////
  36. -- ///// Returns: void      //////
  37. -- ///////////////////////////////
  38.  
  39. function Nametags:Render()
  40.     local x2, y2, z2 = getCameraMatrix()
  41.     for index, ped in pairs(getElementsByType("player", getRootElement(), true)) do
  42.         setPlayerNametagShowing(ped, false)
  43.         if(ped ~= localPlayer) then
  44.             local x, y, z = getElementPosition(ped)
  45.             local color = tocolor(0, 255, 0, 255)
  46.            
  47.             if(isLineOfSightClear(x, y, z, x2, y2, z2, true, true, false)) then
  48.                 local distance = getDistanceBetweenPoints3D(x2, y2, z2, x, y, z)
  49.                
  50.                 z = z+getElementDistanceFromCentreOfMassToBaseOfModel(ped)
  51.                 local sx, sy = getScreenFromWorldPosition(x, y, z);
  52.                 local sx2, sy2 = getScreenFromWorldPosition(x, y, z+0.25);
  53.                
  54.                 if(sx and sy) then
  55.                     -- Background
  56.                     local width = 256
  57.                    
  58.                     width = (width/distance)*5
  59.                    
  60.                     if(width >= 256) then
  61.                         width = 256;
  62.                     end
  63.                
  64.                     local height = width/2
  65.                    
  66.                     local width2 = 256/100*getElementHealth(ped)
  67.                     local width3 = width/100*getElementHealth(ped)
  68.                    
  69.                     local name = getPlayerName(ped)
  70.                    
  71.                    
  72.                     local scale = (self.scale/distance)*5
  73.                    
  74.                     if(scale >= self.scale) then
  75.                         scale = self.scale
  76.                     end
  77.                    
  78.                     if(sx2 and sy2) then
  79.                         -- NAME --
  80.                         dxDrawText(name, sx2, sy2, sx2, sy2, tocolor(255, 255, 255, 255), scale, self.font, "center", "center")
  81.                     end
  82.                     -- Background
  83.                     dxDrawImage(sx-width/2, sy-height/2, width, height, "files/images/hud_healthbar_bg.png", 0, 0, 0, tocolor(255, 255, 255, 255))
  84.                    
  85.                     -- Healthbar empty
  86.                    
  87.                     dxDrawImage(sx-width/2, sy-height/2, width, height, "files/images/hud_healthbar_empty.png", 0, 0, 0, color)
  88.                    
  89.                     -- White
  90.                     --dxDrawImage(sx-width/2, sy-height/2, width, height, "files/images/hud_healthbar_white.png", 0, 0, 0, color)
  91.                    
  92.                     local oldhealth = self.oldHealth[ped]
  93.    
  94.                     if(oldhealth) and (oldhealth-getElementHealth(ped) > 0) then   
  95.                         local width4 = width/100*oldhealth
  96.                    
  97.                         dxDrawImage((sx-width/2), sy-height/2, width4, height, "files/images/hud_healthbar_white.png", 0, 0, 0, tocolor(255, 255, 255, 150))
  98.                        
  99.                         if(self.reversed[ped] == true) then
  100.                             if(self.oldHealth[ped] >= getElementHealth(ped)) then
  101.                                 self.oldHealth[ped] = self.oldHealth[ped]-1.25
  102.                             end
  103.                         end
  104.                     end
  105.                     -- Health
  106.                     --dxDrawImageSection ( sx-width/2, sy-height/2, width, height, 50, 50, 50, 50, "picture.png" )
  107.                     --dxDrawImage(sx-width/2, sy-height/2, width2, height, "files/images/hud_healthbar_healthfull.png", 0, 0, 0, color)
  108.                     dxDrawImageSection ( sx-width/2, sy-height/2, width3, height, 0, 0, width2, 128, "files/images/hud_healthbar_healthfull.png", 0, 0, 0, color )
  109.                 end
  110.             end
  111.         end
  112.     end
  113. end
  114.  
  115.  
  116. -- ///////////////////////////////
  117. -- ///// Constructor        //////
  118. -- ///// Returns: void      //////
  119. -- ///////////////////////////////
  120.  
  121. function Nametags:Constructor(...)
  122.     self.renderFunc = function() self:Render() end
  123.     self.pedDamageFunc = function(_, _, _, loss)
  124.         local player = source;
  125.        
  126.         if not(self.oldHealth[player]) then
  127.             self.oldHealth[player] = getElementHealth(player);
  128.         end
  129.    
  130.         self.reversed[player] = false;
  131.         if(isTimer(self.updateTimer[player])) then
  132.             killTimer(self.updateTimer[player])
  133.         else
  134.             self.oldHealth[player] = getElementHealth(player)+loss;
  135.         end
  136.  
  137.  
  138.         self.updateTimer[player] = setTimer(function()
  139.         --  self.oldHealth[player] = getElementHealth(player)
  140.             self.reversed[player] = true;
  141.         end, 500, 1)
  142.        
  143.     end;
  144.    
  145.     self.oldHealth = {}
  146.     self.updateTimer = {}
  147.     self.reversed = {}
  148.    
  149.     self.scale = 0.3
  150.     self.font = dxCreateFont("files/fonts/chicken.ttf", 60)
  151.    
  152.     addEventHandler("onClientPreRender", getRootElement(), self.renderFunc)
  153.     addEventHandler("onClientPlayerDamage", getRootElement(), self.pedDamageFunc)
  154.  
  155.    
  156.     setPedTargetingMarkerEnabled(false)
  157.    
  158.     outputDebugString("[CALLING] Nametags: Constructor");
  159. end
  160.  
  161. -- EVENT HANDLER --
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement