• 2 Hud problems
    13 replies, posted
Hi, I'm having problems with my hud. This is an edited version of simple hud v1 [URL]http://www.garrysmod.org/downloads/?a=view&id=100766[/URL] I have 2 problems, [B]The ammo bar doesn't hide when I switch to a weapon without ammo, like the physgun.[/B] [B]Weapons without primary ammo make the bar disappear and makes the primary ammo go to 0. [/B] I want to make it so when I take out an rpg or grenade, the extra ammo acts like primary ammo or something. Here's the code: [code]function myhud() if !ValidEntity(LocalPlayer()) then return end local client = LocalPlayer() draw.RoundedBox(0, 35, ScrH()-45, math.Clamp(client:Health(),0,100)*1.8,25, Color(0,180,0,255)) surface.SetDrawColor(0,0,0,200) surface.DrawOutlinedRect( 35, ScrH()-45,180,25) draw.SimpleText(client:Health(), "HUDFont", 105, ScrH()-45, Color(220, 220, 220, 255), 0, 0) surface.CreateFont( "ScoreboardText", 24, 500, true, true, "HUDFont" ) if !ValidEntity(client:GetActiveWeapon()) then return end local mag_left = client:GetActiveWeapon():Clip1() local mag_extra = client:GetAmmoCount(client:GetActiveWeapon():GetPrimaryAmmoType()) local secondary_ammo = client:GetAmmoCount(client:GetActiveWeapon():GetSecondaryAmmoType()) MaxAmmo={} MaxAmmo["weapon_crowbar"]=0 MaxAmmo["weapon_physcannon"]=0 MaxAmmo["weapon_physgun"]=0 MaxAmmo["weapon_pistol"]=18 MaxAmmo["weapon_357"]=6 MaxAmmo["weapon_smg1"]=45 MaxAmmo["weapon_ar2"]=30 MaxAmmo["weapon_crossbow"]=1 MaxAmmo["weapon_frag"]=-1 MaxAmmo["weapon_rpg"]=-1 if mag_left == -1 then mag_left = 0 hasPrim = 0 else hasprim = 1 end if(client:GetActiveWeapon().Primary)then ammobar=mag_left/client:GetActiveWeapon().Primary.ClipSize*180 else ammobar=mag_left/MaxAmmo[client:GetActiveWeapon():GetClass()]*180 end draw.RoundedBox(0, 1235, ScrH()-40, ammobar, 25, Color(0,120,255,250*hasprim), 0, 0) surface.SetDrawColor(0,0,0,200*hasprim) surface.DrawOutlinedRect( 1235, ScrH()-40,180,25) draw.SimpleText(mag_left , "HUDFont", 1250, ScrH()-40, Color(220,220,220,255*hasprim), 0, 0) draw.SimpleText(mag_extra , "HUDFont", 1390, ScrH()-40, Color(220,220,220,255*hasprim), 0, 0) end hook.Add("HUDPaint", "huddie", myhud) function hidehud(name) for k, v in pairs{"CHudHealth", "CHudBattery", "CHudAmmo", "CHudSecondaryAmmo"} do if name == v then return false end end end hook.Add("HUDShouldDraw", "hidehud", hidehud) [/code]
I fixed my problems, but then I got 2 more problems. edited the op
[code] if client:GetActiveWeapon():GetClass() != "weapon_physgun" then draw.RoundedBox(0, 1235, ScrH()-40, ammobar, 25, Color(0,120,255,250*hasprim), 0, 0) surface.SetDrawColor(0,0,0,200*hasprim) surface.DrawOutlinedRect( 1235, ScrH()-40,180,25) draw.SimpleText(mag_left , "HUDFont", 1250, ScrH()-40, Color(220,220,220,255*hasprim), 0, 0) draw.SimpleText(mag_extra , "HUDFont", 1390, ScrH()-40, Color(220,220,220,255*hasprim), 0, 0) end[/code]
wait what does that do and where do I put it :P
It goes in the client file, since it's a clientside function?
yeah, but like does it have to be in a specific place or do i need to replace anything? lolnvm I figured it out. But I want it so that the ammo bar doesn't show up for any weapon without ammo.
[code]if client:GetActiveWeapon():GetClass() != "weapon_physgun" or client:GetActiveWeapon():GetClass() != "weapon_gravgun" then [/code]
[QUOTE=Cubar;25358888][code]if client:GetActiveWeapon():GetClass() != "weapon_physgun" or client:GetActiveWeapon():GetClass() != "weapon_gravgun" then [/code][/QUOTE] [code]if(client:GetActiveWeapon():GetClass() != "weapon_physgun" && client:GetActiveWeapon():GetClass() != "weapon_physcannon") then [/code]
I was gonna use and but then changed it, changing 1 thing doesn't make me dumb, it makes you dumb. :v:
and and or are quite different :v:
if 1 and 2 then continue end if 1 or 2 then continue end and if they have 1 but don't have 2 do nothing, or if they don't have 1 but have 2 then continue.
What about crowbar? What about other non ammo SWEPs? [lua] if IsValid(LocalPlayer():GetActiveWeapon()) and LocalPlayer():GetActiveWeapon():Clip1() != -1 then [/lua]
^ best way, if you don't want to waste your time on adding more sweps with -1 ammo. :v:
What do i do with those pieces of code? Do I need to replace anything and where does the end go?
Sorry, you need to Log In to post a reply to this thread.