Description
This hook allows you to draw on screen while this weapon is in use.
If you want to draw a custom crosshair, consider using WEAPON:DoDrawCrosshair instead.
Example
Weapon:DrawHud() as defined in weapon_cs_base, with more notes
function SWEP:
DrawHUD()
if ( self.
Weapon:
GetNWBool(
"Ironsights" ) )
then return end
local x, y
if (
self:
GetOwner()
== LocalPlayer()
&& self:
GetOwner():
ShouldDrawLocalPlayer() )
then
local tr
= util.
GetPlayerTrace(
self:
GetOwner() )
tr.mask
= ( CONTENTS_SOLID
+CONTENTS_MOVEABLE
+CONTENTS_MONSTER
+CONTENTS_WINDOW
+CONTENTS_DEBRIS
+CONTENTS_GRATE
+CONTENTS_AUX )
local trace
= util.
TraceLine( tr )
local coords
= trace.
HitPos:
ToScreen()
x, y
= coords.x, coords.y
else
x, y
= ScrW()
/ 2.0,
ScrH()
/ 2.0
end
local scale
= 10 * self.Primary.Cone
local LastShootTime
= self.
Weapon:
GetNWFloat(
"LastShootTime",
0 )
scale
= scale
* (
2 - math.
Clamp( (
CurTime()
- LastShootTime)
* 5,
0.0,
1.0 ))
surface.
SetDrawColor(
0,
255,
0,
255 )
local gap
= 40 * scale
local length
= gap
+ 20 * scale
surface.
DrawLine( x
- length, y, x
- gap, y )
surface.
DrawLine( x
+ length, y, x
+ gap, y )
surface.
DrawLine( x, y
- length, x, y
- gap )
surface.
DrawLine( x, y
+ length, x, y
+ gap )
end Output: Draws 4 lines for crosshairs