Private Hud "Ammo

Well we have coded a new hud for our server. And now i’ wondering how to code a ammunition hud if there’s a tutorial cn you pleas link in comments

And what do you mean by “ammo HUD”?

like when you pull your gun out it makes a hud at the right hand corner because the default one is the hl2 one

First, something to know about huds and painting in general. If you insert a variable into the width, height, or position. Whenever that variable changes, the element will change directly with it (With HUDPaint that is).

In my example I’m going to use **[Draw.RoundedBox](**.

local ammo_clip = ply:GetActiveWeapon():Clip1() or 0
local ammo_max = ply:GetActiveWeapon().Primary.ClipSize or 0
draw.RoundedBox(4, 20, ScrH() - 35, 200 * ammo_clip / ammo_max, 15, Color(255,255,255,255))

In the above example, the key part is within the Width argument. Notice how we have ( 200 * ammo_clip / ammo_max ). That is a simple formula to calculate the scale of a bar in ratio to the max. It’s a simple as dividing what we have now, by what the max is. (This is the right to left effect you get when draining your ammo)

If you want to have this draw ONLY when you have a weapon out, then do something like this!

if client:GetActiveWeapon().Primary then
       --Put all your ammo stuff in here

This pretty much means, if the player has an active weapon in his active weapon slot, this HUD will appear.

All of this kinda varies on what you are doing. This is mostly from a TTT hud I’ve configured for myself. However, the same method is used when scaling a bar. If you’ve made your Health bar, it works in the same fashion (assuming you made a generic bar using vgui).

EDIT: And another edit, since I don’t think I fully understood your question maybe?

You can use this to disable the default hud in order to continue to paint your own.

local hud = {"CHudHealth", "CHudBattery", "CHudAmmo", "CHudSecondaryAmmo"}
function GM:HUDShouldDraw(name)
   for k, v in pairs(hud) do
      if name == v then return false end

   return true

This goes in cl_hud for 2.5 right?

Why not say at first post this is for DarkRP. This should have been DarkRP help thread instead

Just because he’s using it in a DarkRP server, doesn’t mean it has anything to do with DarkRP.
It’s not DarkRP related and shouldn’t be in the DarkRP thread.