Skip to content

How To: Ammo Counters On Weapons

Vuthakral edited this page Aug 28, 2019 · 1 revision

How to Add an Ammo Counter to Your SWEP Using the SCK

This is going to be kept short and to the point because I'm writing this at almost 3am aaaa


Setting up quads on your VElements

  1. Open the SWEP Construction Kit's Menu
  2. Set the viewmodel of your SWEP.
  3. Navigate to the "View Models" tab in the tool's menus.
  4. Click the dropdown box and select "Quad". Give it a name (I've named my example one "helpits3am") in the box to the left, then press add.
  5. Set the "Bone" to your weapon's bone.
  6. Position, rotate, and set the size of the Quad until it is where you need it to be.
  7. Press the "Copy view model table to clipboard" button.
  8. Open your SWEP's lua or shared.lua file
  9. At some point AFTER the line SWEP.Base & SWEP.Gun, paste your clipboard into the file. You should see something like this pop up:
SWEP.VElements = {
	["helpits3am"] = { type = "Quad", bone = "ValveBiped.square", rel = "", pos = Vector(0, -0.345, -5.415), angle = Angle(0, 0, 0), size = 0.05, draw_func = nil}
}
  1. At the VERY BOTTOM of your SWEP, add this bit of code:
    (Note: If you're coming here from Google, "DoCustomInitialize" is a function specific to my SWEP base. If you aren't working using my SWEP base, just use function SWEP:Initialize() instead. DO NOT USE IT IF YOU ARE WORKING WITH MY SWEP BASE YOU WILL OVERWRITE MY FUNCTION AND BREAK STUFF.)
function SWEP:DoCustomInitialize()
local ply = self:GetOwner()
	if CLIENT then
		self.VElements["helpits3am"].draw_func = function( weapon )
			draw.SimpleText(self:Clip1(), "HalfLife2", 8.5, 13.5, Color(255,0,0,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_BOTTOM)
		end
	end
end

To read up how to customize the text that is displayed, read up on the draw.SimpleText function here

"But what if I want my ammo counter to show the player's total ammo too?"

Easy adjustment. In the draw.SimpleText function change this: self:Clip1() to ply:GetAmmoCount( self:GetPrimaryAmmoType() )

Clone this wiki locally