Advertisement
Extreemhost

Healthbar

Jul 11th, 2015
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.69 KB | None | 0 0
  1. Script.offset = Vec2(0,0) --Vec2 "Offset"
  2. Script.size = Vec2(160, 25) --Vec2 "Size"
  3. Script.backgroundColor = Vec4() --color "Background color"
  4. Script.healthbarColor = Vec4() --color "HealthBar color"
  5. Script.frontcolor = Vec4() --color "Front color"
  6. Script.overlayPath = "" -- path "Overlay" "Tex file (*tex):tex"
  7. Script.overlay = nil
  8. Script.player = nil
  9. Script.backgroundColorFractioned = nil
  10. Script.healthbarColorFractioned = nil
  11.  
  12. function Script:Start()
  13.     self.player = self.entity:GetParent()
  14.  
  15.     if self.overlayPath ~= "" then
  16.         self.overlay = Texture:Load(self.overlayPath)
  17.     end
  18.     --background
  19.     local c = self.backgroundColor
  20.     self.backgroundColorFractioned = Vec4(c.x/255, c.y/255, c.z/255, c.w/255)
  21.    
  22.     local c = self.healthbarColor
  23.     self.healthbarColorFractioned = Vec4(c.x/255, c.y/255, c.z/255, c.w/255)
  24. end
  25.  
  26. function Script:PostRender(context)
  27.     -- Background
  28.     context:SetColor(self.backgroundColorFractioned)
  29.     context:DrawRect(self.offset.x, context:GetHeight() - self.offset.y, self.size.x, self.size.y)
  30.  
  31.     -- Healthbar
  32.     context:SetColor(self.healthbarColorFractioned)
  33.     local healthFactor = self.player.script.health / self.player.script.maxHealth
  34.     context:DrawRect(self.offset.x,context:GetHeight() - self.offset.y, self.size.x * healthFactor, self.size.y)
  35.  
  36.     context:SetBlendMode(Blend.Alpha)
  37.     context:SetColor(self.frontcolor)
  38.     context:DrawText(healthFactor,self.offset.x,context:GetHeight())
  39.     context:SetBlendMode(Blend.Solid)
  40.    
  41.     --Draw overlay
  42.     if self.overlay ~= nil then
  43.         context:SetBlendMode(Blend.Alpha)
  44.         context:SetColor(self.frontcolor)
  45.         context:DrawImage(self.overlay, 0, context:GetHeight() - self.overlay:GetHeight())
  46.         context:SetBlendMode(Blend.Solid)
  47.     end
  48. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement