-
Notifications
You must be signed in to change notification settings - Fork 1
How To: Ammo Counters On Weapons
Vuthakral edited this page Aug 28, 2019
·
1 revision
This is going to be kept short and to the point because I'm writing this at almost 3am aaaa
- Open the SWEP Construction Kit's Menu
- Set the viewmodel of your SWEP.
- Navigate to the "View Models" tab in the tool's menus.
- 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.
- Set the "Bone" to your weapon's bone.
- Position, rotate, and set the size of the Quad until it is where you need it to be.
- Press the "Copy view model table to clipboard" button.
- Open your SWEP's lua or shared.lua file
- 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}
}
- 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() )