GM:HudPaint - Drawing A Crosshair, how?

What I am doing here with this code is drawing third person, and fixing the aim problem. My only problem now is I don’t know how to draw a crosshair :confused: How would I do so. Thanks, SLEAZY!

[lua]function GM:HUDPaint( )

local realshoot = ply:GetShootPos( );
local tracehit = ply:GetEyeTrace( ).HitPos;
local eyeangles = EyeAngles( );
local offset = realshoot +
(eyeangles:Right() * 50) +
(Angle(0,eyeangles.y,0):Forward() * -150) +
(Angle(0,0,eyeangles.z):Up() * 20)
local newshoot = offset;
local tracetable = { };
– trace code make newshoot startpos, tracehit endpos
local trace = util.TraceLine( tracetable );
local hitpos = trace.HitPos;
hitpos = hitpos:ToScreen( ); – turns into into x, y format for screen

– Where you draw the crosshair

end[/lua]

It depends, are you drawing a texture or a css style crosshair?

If you are drawing a texture then just use this:

[Lua] local mat = Material( “path/to/material” )// Make sure to set this out of the HUDPaint hook.
surface.SetTexture( mat )
surface.DrawTexturedRect( ( x ) - 32, ( y ) - 16, 64, 32 ) // x - half the width, y - half the height[/Lua]

If you are wanting a Css style one, then you would use something like this:

[Lua]
local x, y = ScrW() / 2, ScrH() / 2 // You can do local x, y = hitpos
local gap = 10 //If you want the crosshair to increase size, just increase the gap amount.
local length = gap + 10

surface.SetDrawColor( color_white )
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 )
[/Lua]