Hi guys. I just started working on a project and I am trying to make an enemy health bar.
I attach the script to a pivot and make it a child of the enemy. And it works fine. What I need help with is for my if statement with the and condition. I
want to do some kind of check against the FPS script as an extra and condition. To say if monster is within an amount of distance to the cross hair then draw to screen.
--Player Enemy Health Bar--
Script.player = nil
Script.EnemybarColor = Vec4() --color "Enemybar Color"
Script.size = Vec2(0,0) --Vec2 "Size"
Script.offset = Vec2(0,0) --Vec2 "Offset"
function Script:Start()
self.player = self.entity:GetParent()
--Staminabar Fractioned
local c = self.EnemybarColor
self.EnemyColorFractioned = Vec4(c.x/255, c.y/255, c.z/255, c.w/255)
end
function Script:PostRender(context)
if (self.player.script.health < self.player.script.maxhealth) and (self.player.script.health > 0) then
--redefine values to make the script cleaner
local a = self.player.script.health
local b = self.player.script.maxhealth
local c = self.EnemybarColor
local e = a / b
local ox = self.offset.x
local oy = self.offset.y
local sx = self.size.x
local sy = self.size.y
local p0 = self.player:GetPosition(true)
--Background Bar
context:SetBlendMode(1)
context:SetColor(1,1,1,.25)
context:DrawRect (context:GetWidth() - (context:GetWidth() / 2) + ox, (context:GetHeight() - (context:GetHeight() / 2)) + oy,sx,sy)
--Draw the Enemybar
context:SetBlendMode(0)
context:SetColor(c)
context:DrawRect (context:GetWidth() - (context:GetWidth() / 2) + ox, (context:GetHeight() - (context:GetHeight() / 2)) + oy, sx * e, sy)
end
end
-- x axis use -(number) to offset, y axis use a positive number above 0