When I try to make a ammo count bar (Like a health bar) I'm having trouble with it.
Code:
[CODE]
local clip = LocalPlayer():GetActiveWeapon():Clip1() or ""
draw.RoundedBox(0, ScrW() - 230, ScrH() - 30, (733) * clip / 100, 20, mHUD.AmmoBarColor)
[/CODE]
I know how this code works, Im asking just how I can edit it to make the bar fit for all weapons
Now it is full when the clip has 30 rounds in it (Like the weapon has a max of 30 rounds per clip)
But if I use a weapon that can only hold 1 shot per clip (Half Life Crossbow)
And last if the clip can hold more that 30 rounds in the clip is goes over the ammo display (Half Life SMG)
[IMG]http://i.imgur.com/T4924n6.png[/IMG]
[IMG]http://i.imgur.com/1J4ZO6w.png[/IMG]
[IMG]http://i.imgur.com/fZQCrFj.png[/IMG]
GetMaxClip1 will get you the max amount of ammo the clip can hold so you can scale your bar with that. Also, change your clip variable to this instead to prevent errors:
[code]local weapon = LocalPlayer():GetActiveWeapon()
if (weapon:IsValid()) then
local clip = weapon:Clip1()
-- Draw code
end[/code]
[QUOTE=code_gs;51741219]GetMaxClip1 will get you the max amount of ammo the clip can hold so you can scale your bar with that. Also, change your clip variable to this instead to prevent errors:
[code]local weapon = LocalPlayer():GetActiveWeapon()
if (weapon:IsValid()) then
local clip = weapon:Clip1()
-- Draw code
end[/code][/QUOTE]
Does this look rigth?
This is my entire code for the ammo display
[CODE]
local function DrawAmmo()
local weapon = LocalPlayer():GetActiveWeapon()
if (weapon:IsValid()) then
if (not table.HasValue(mHUD.WeaponsNotDraw, weapon:GetClass())) then
local clip = weapon:Clip1() or ""
local extra = LocalPlayer():GetAmmoCount(LocalPlayer():GetActiveWeapon():GetPrimaryAmmoType()) or ""
// Base
draw.RoundedBox(0, ScrW() - 230, ScrH() - 130, 220, 120, Color(35,35,35,255))
draw.SimpleText(clip, "hudFont50", ScrW() - 175, ScrH() - 105, Color(255,255,255,255), center)
draw.RoundedBox(0, ScrW() - 120, ScrH() - 120, 4, 80, Color(255,255,255,255))
draw.SimpleText(extra, "hudFont50", ScrW() - 63, ScrH() - 105, Color(255,255,255,255), center)
draw.SimpleText("Clip", "hudFont22Alt", ScrW() - 175, ScrH() - 65, Color(255,255,255,255), center)
draw.SimpleText("Extra", "hudFont22Alt", ScrW() - 63, ScrH() - 65, Color(255,255,255,255), center)
if (mHUD.AmmoCountBar == true) then
draw.RoundedBox(0, ScrW() - 230, ScrH() - 30, 220, 20, Color(82,82,82,255))
draw.RoundedBox(0, ScrW() - 230, ScrH() - 30, (220) * clip / 100, 20, mHUD.AmmoBarColor)
else
draw.RoundedBox(0, ScrW() - 120, ScrH() - 120, 4, 100, Color(255,255,255,255))
end
end
end
end
[/CODE]
You're still doing "weapon:Clip1() or """, don't do that. Also, use weapon instead of LocalPlayer():GetActiveWeapon() in your "extra" declaration.
[QUOTE=code_gs;51741417]You're still doing "weapon:Clip1() or """, don't do that. Also, use weapon instead of LocalPlayer():GetActiveWeapon() in your "extra" declaration.[/QUOTE]
When I do weapon:GetMaxClip1() it makes it so the bar does not move at all
[QUOTE=Moat;51741684]You should be dividing Clip1() by GetMaxClip1() and multiplying that number by the max length of the bar.
[code]
local bar_length = 200
local clip = wep:Clip1() / wep:GetMaxClip1()
bar_length = bar_length * clip
[/code]
Then use the bar length var to set the width of the rounded box.[/QUOTE]
Works great thank you so much
Sorry, you need to Log In to post a reply to this thread.