Are there any huds with these requirements?

I’m currently trying to expand my knowledge in LUA and I am best taught by reading and understanding the code. At the moment I’m troubled with how to make a custom Weapon selection system, aswell as a hud pickup draw.

So that leaves me at my question, are there any free huds out there where I can read through the code to get an understanding on how it was done? (Hopefully some simple code, that is easy to understand)

There’s a lot of custom (and free) HUDs on the darkrp forums. They are made for darkrp, but some of them are really well made and give a great insight in HUD creation.

Well i’m specificly looking for Weapon selection and Pickup drawing.

I suggest you take a look on the darkrp forums for a HUD that meets those requirements…
Please don’t expect me to look through pages uppon pages of HUDs for a HUD that meets your requirements.

Are you looking for one or are you looking to create one? If you want some pointers, take a look at TTT…

If you’re looking to write your own you’ll need to do several things… PlayerBindPress, detect mouse wheel up and down ( ie invnext and invprev ) and return true to prevent anything else from using it ( the default weapon selector which will still come up if GMod is not in focus but you scroll mouse while hovering over the edge of the window ). The logic behind wheel up and down is simple… Add 1 to a count or subtract one and use mod ( % ) for the number of weapons the player has. This value is necessary to highlight the proper element.

You’ll also need to detect +attack and +attack2 and return true ONLY IF the menu is open. +attack should call a function to select the weapon while +attack2 should close the menu…

You can do what TTT Did if you want fade out by using Tick or Think hook ( better would be to only activate the hook when necessary and remove it when finished like my rewrite of notification system ) when the menu is active ( you’ll need to keep track of the time the menu was opened OR the last time the client manipulated something in the menu so that you can fade in / out or auto-close… If you only want auto-close without any effects you can use a timer.Create( “LastWeaponSelectAccess”, 3, 1, function( ) … close the menu … end ); which, when called if it already exists will overwrite itself so that is a simple way to close the menu after a time.

For drawing the bar, it’s just a matter of how you want to do it. You can create a vgui / panel and draw in paint or you can use HUDPaint. To simplify the math ( depending on where you want it offset; assuming bottom right ) you can output weapons in reverse order by using for number_of_weapons, 1, -1 do … end so you can use ScrH( ) - offset * ( number_of_weapons - i ) in addition to using - ( x ) * buffer… although the math won’t change a lot if you start at max offset…

The logic is pretty straight forward, but here’s the TTT version in a single file ( should work but it’s old code and I haven’t messed with it recently )

I’ve extracted it to 1 file and fixed a few things ( or rather made it work without ttt weapon base ):

Don’t forget to hide the weapon selection hud:

Thank you for the detailed answer. Hopefully it will help me figure something out :slight_smile: