Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Script.offset = Vec2(0,0) --Vec2 "Offset"
- Script.size = Vec2(160, 25) --Vec2 "Size"
- Script.backgroundColor = Vec4() --color "Background color"
- Script.healthbarColor = Vec4() --color "HealthBar color"
- Script.frontcolor = Vec4() --color "Front color"
- Script.overlayPath = "" -- path "Overlay" "Tex file (*tex):tex"
- Script.overlay = nil
- Script.player = nil
- Script.backgroundColorFractioned = nil
- Script.healthbarColorFractioned = nil
- function Script:Start()
- self.player = self.entity:GetParent()
- if self.overlayPath ~= "" then
- self.overlay = Texture:Load(self.overlayPath)
- end
- --background
- local c = self.backgroundColor
- self.backgroundColorFractioned = Vec4(c.x/255, c.y/255, c.z/255, c.w/255)
- local c = self.healthbarColor
- self.healthbarColorFractioned = Vec4(c.x/255, c.y/255, c.z/255, c.w/255)
- end
- function Script:PostRender(context)
- -- Background
- context:SetColor(self.backgroundColorFractioned)
- context:DrawRect(self.offset.x, context:GetHeight() - self.offset.y, self.size.x, self.size.y)
- -- Healthbar
- context:SetColor(self.healthbarColorFractioned)
- local healthFactor = self.player.script.health / self.player.script.maxHealth
- context:DrawRect(self.offset.x,context:GetHeight() - self.offset.y, self.size.x * healthFactor, self.size.y)
- context:SetBlendMode(Blend.Alpha)
- context:SetColor(self.frontcolor)
- context:DrawText(healthFactor,self.offset.x,context:GetHeight())
- context:SetBlendMode(Blend.Solid)
- --Draw overlay
- if self.overlay ~= nil then
- context:SetBlendMode(Blend.Alpha)
- context:SetColor(self.frontcolor)
- context:DrawImage(self.overlay, 0, context:GetHeight() - self.overlay:GetHeight())
- context:SetBlendMode(Blend.Solid)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement