Jump to content

(Solved) Health Bar "Aggror Script" for Leadwerks 4.0


Recommended Posts

Posted

Hey,

 

I've been trying to adapt as much scripts as possible to work with the 4.0 version, and I've come across some issues with the Health Bar script,

 

The color function doesn't work. The bars stay black.

 

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.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)

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)


--Draw overlay
if self.overlay ~= nil then
context:SetBlendMode(Blend.Alpha)
context:SetColor(1,1,1,1)
context:DrawImage(self.overlay, 0, context:GetHeight() - self.overlay:GetHeight())
context:SetBlendMode(Blend.Solid)
end
end

 

ROQc23x.png

 

Htll9SY.jpg

Posted

Hi Erika,

 

Leadwerks changed the API quite a while ago for the color settings. Colors no longer have to be divided by 255 in order for them to be processed correctly by Leadwerks.

 

so this:

self.backgroundColorFractioned = Vec4(c.x/255, c.y/255, c.z/255, c.w/255)

 

becomes:

self.backgroundColorFractioned = Vec4(c.x, c.y, c.z, c.w)

  • Upvote 3
Posted

Worked excellent, thank you, highly respect the video tutorials you've done on youtube, I hope to see many more!

 

I'm just getting back into it, its been over a year since 3.1 / 3.2 was out that I last made anything.

Posted

Welcome back Aggror.

 

There is a same problem with FlowGui the text colours are all back now. Any chance of an update biggrin.png

yes, i have an update for that. I want include some other fixes and features as well. When le 4.0 is out of beta I will release it.
  • Upvote 3

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...