Hello,
I'm in the process of making a HUD and currently when people take damage the health/armour bar instantly depletes (sets to their new health - with colour) without any effect. I wanted to make it so that it decreases smoothly (hard to explain exactly, but i hope you understand what i mean) could someone please help me out?
Thanks!
I'd take the approach of using either Lerp or math.Approach.
Assuming this is done inside a panel, you'd want to do something like
function PANEL:Paint(w, h)
surface.SetDrawColor(255, 255, 255)
local curHealth = LocalPlayer():Health()
local maxHealth = LocalPlayer():GetMaxHealth()
local frac = curHealth / maxHealth
-- Uncomment this for smooth health
-- self.healthFrac = Lerp(FrameTime() * 8, self.healthFrac or 0, frac)
-- Uncomment for less smooth, linear-looking health
-- self.healthFrac = math.Approach(self.healthFrac or 0, frac, FrameTime() * 10)
-- change 10 as you desire. or do away with FrameTime and make it a constant
surface.DrawRect(0, 0, self.healthFrac * w, h)
end
Hello, thanks for the reply - I cannot seem to get it to work though :S
draw.RoundedBox(3, 1 + 2, ScrH() - 29, 250 - 4, 30 - 4, Color(75, 75, 75, 255))
function PANEL:Paint(146, 26)
surface.SetDrawColor(204, 0, 0, 255)
local curHealth = LocalPlayer():Health()
local maxHealth = LocalPlayer():GetMaxHealth()
local frac = curHealth / maxHealth
self.healthFrac = Lerp(FrameTime() * 8, self.healthFrac or 0, frac)
surface.DrawRect(3, ScrH()-29, self.healthFrac * 146, 26)
--if DrawHealth != 0 then
--surface.DrawRect(3, ScrH()-29, self.healthFrac * 146, 26)
--draw.RoundedBox(3, 1 + 2, ScrH() - 29, (250 - 4) * DrawHealth / 100, 30 - 4, Color(204, 0, 0, 255))
--end
end
I get the error:
[ERROR] addons/darkrpmodification-master/lua/darkrp_modules/customhud/cl_hud.lua:18: <name> or '...' expected near '146'
1. unknown - addons/darkrpmodification-master/lua/darkrp_modules/customhud/cl_hud.lua:0
In the console...
local function GunLicense()
if localplayer:getDarkRPVar("HasGunlicense") then
surface.SetMaterial(Page)
surface.SetDrawColor(255, 255, 255, 255)
surface.DrawTexturedRect(RelativeX + HUDWidth, Scrh - 34, 32, 32)
end
end
Can be found at 146 (using the default DarkRP Hud and editing it in darkrpmodifications folder).
Sorry if it's an easy fix, just trying to get my head around LUA.
if localplayer:getDarkRPVar("HasGunlicense") then
Change to
if LocalPlayer():getDarkRPVar("HasGunlicense") then
Don't just copy the cl_hud from Garry's Mod original hud because they did
local localplayer = LocalPlayer()
Did what you said, didn't fix anything :S
You didn't read zombines post properly, he said; If you're using a panel then you should use this. It won't work straight up assuming you're using a HUDPaint hook, however, the approach he went with is correct and does only require a bit of editing to work with the HUDPaint hook.
Sorry, you need to Log In to post a reply to this thread.