Drawing a HUD on a custom weep help.

Hey guys. I need to rush on this thread. I don’t have much time right now. So I have a problem where I need to draw a HUD on top of a custom swep that moves with the swep. My code goes as follows. I have the code which I have on my PC at home. I’ll reply to this with it. But my problem is that I have cam.start3D2D and cam.end3D2D and my box that I’m trying to make will not show up xD. I’m drawing it in shared.lua


Here’s what the code sort of looks like:

function HUDAmmo()

       draw.RoundedBox( 5, ScrW() - 500, ScrH() - 500, 50, 50, Color( 255, 255, 255, 255 ) )


hook.Add("HUDPaint", "GUNAmmo", HUDAmmo)

Any help is appreciated.


Alright, So I believe I shouldn’t have posted this in school xD But I have looked everywhere and I hacve yet to find out what the problem is.

By the way, I know it’s cam.Start3D2D( Vector pos, Angle angles, number scale ). I just had no time to type it all out…

Please actually help me. It’s annoying to see how this forum just laughs at you if you need help :\

if CLIENT then
function SWEP:ViewModelDrawn()
      cam.Start3D2D(your vector, your angle, your scale)

       draw.RoundedBox( 5, ScrW() - 500, ScrH() - 500, 50, 50, Color( 255, 255, 255, 255 ) )


Your syntax is a little off, just paste this below your weapons code and edit it to your needs.

I should have been a little bit more specific. I’m trying to get a Box to draw next to my gun and follow it. Fortune’s post works but it doesn’t appear next to my gun and it doesn’t follow the gun when I move my screen. If you know how to do this fortune, please tell me :slight_smile:


-snip im stupid and dont like to read correctly :v:

That is because you didn’t change the code at all. You need to start the 3D2D camera attached the weapons position. Try something like this:

if CLIENT then
 function SWEP:ViewModelDrawn()
  local muzzle_angpos = vm:GetAttachment(1)
  local vm_ang = muzzle_angpos.Ang
      local cpos = muzzle_angpos.Pos + (vm_ang:Up() * -8) + (vm_ang:Forward() * -5.5) +    (vm_ang:Right() * 0)
      local cang = vm:GetAngles()
      cang:RotateAroundAxis(cang:Forward(), 90)
      cang:RotateAroundAxis(cang:Right(), 90)
      cang:RotateAroundAxis(cang:Up(), 90)

  cam.Start3D2D(cpos, cang, 0.05)
      surface.SetDrawColor(255, 10, 10, 170)
      surface.DrawRect(1, 1, sz, 13)


Yah alright so, _Jacob’s method works just I cant get it to sync up with the gun movement. OF course, Fortunes method works, but the box is all jumpy and seems to go with my player and not my weapon xD Im still trying. I had to add some code into Fortunes since it was showing errors In the console.


I forgot to define VM, just add vm = LocalPlayer():GetViewModel().

Lol. It works!! Thank you so much for your help, both you and Jacob. Now I have one more question. I can’t create text xD I tried surface.DrawText but it just made the map invisible and glitchy. Any idea on this?

What was the error?

Don’t comment on my profile and stop being butt hurt over ratings.

All the things you’re asking can be done by yourself, stop being lazy and figure it out.

The members in this forum aren’t here to spoon feed you.

[editline]19th March 2014[/editline]

He didn’t end the cam functions.

You don’t have to spoon feed me. You can give me hints or make the code and put intentional errors in it to let me figure out in my own. You’re sitting there saying go find it yourself when I have no idea where and no idea how once I do find it. I sat at my computer staring at cam.Start3D2D not knowing what to do next. I figured out how to get it to attach to an object on the world but not on my gun. Fortunes the only one who’s been help here…and a little bit from Jacob


Just because you’re the “Oh-So-Mighty-Coder” doesn’t mean you can go around laughing at new coders on the forums. Ugh. I’ll just TRY and figure out how to make the text appear on my own…

He’s not laughing at you. He’s telling you to do it yourself instead of relying on people- which is better and more independent.

Nobody here is the “Oh-So-Mighty-Coder”, even if they wish/think they are.
They just tell you what you need to do- Learn, help you, but ultimately it’s up to you to do the code- not them, that is what we call “Spoon-Feeding” code.
Most of the people here taught themselves (Including myself), so why not you too.

P.S. The GMod Wiki is a big help. And so is maurits’ GMDump Wiki which covers some undocumented functions (But largely out of date).

Thank you :). This is a good answer I was looking for. I will favorite both sites and check me out. Again, thanks for your help.

Sign your name one more fucking time please.

Why are you using ScrW() If you are adding this to the actual gun like the morbus sweps then it wont work.

The fuck you gonna do If I sign it again?



I forgot about that :stuck_out_tongue: