The story is that I want to test LUA in singleplayer and I have alaready tested many stuff.
But I was wondering how do I make a crosshair? Since I have been searching all around Facepunch,Gmod lua wiki, google. I did found some crosshair but they dont appear.
Can I have a code for a crosshair? or a code for a Laser Crosshair what points out from the gunbarrel. (Example: Physgun has a blue beam/tracer coming out when doing a Left mouseclick.).


In the gamemode I’m making, I’m using the DrawHUD weapon hook on my weapon base(s) to draw a crosshair.

Here’s an example crosshair.

SWEP.CrosshairRadius = 25
SWEP.CrosshairColor = Color( 0, 255, 0, 255 )

function SWEP:DrawHUD()
    --Draw a circle crosshair at the center of the screen.
    --Probably a good crosshair for shotguns.
    surface.DrawCircle( ScrW() / 2, ScrH() / 2, self.CrosshairRadius, self.CrosshairColor )

That’s a really simple example. I use the surface.DrawLine function to draw a proper crosshair.

Sorry, but I need a client sided crosshair. And Im not making a SWEP. The main thing is to get a toggleable custom crosshair what is LUA based.

Ahh, I have one in one of my older scripts that will change color with your team color, Give me a minute to locate it on my drive

[editline]14th January 2012[/editline]
Toggle by using HZ_Crosshair, 1 or 0, (Feel free to change it)

local shouldDraw = true

local hzCross = CreateClientConVar("HZ_Crosshair","0",false)

function Crosshair1()
if hzCross:GetBool() then
surface.DrawLine(ScrW() / 2 - 10, ScrH() / 2, ScrW() / 2 + 11 , ScrH() / 2)
surface.DrawLine(ScrW() / 2 - 0, ScrH() / 2 - 10, ScrW() / 2 - 0 , ScrH() / 2 + 11)

EDIT: Thought i would add a picture of it, Its a basic one but it works. Changes with team color

paintball gun?

lol it was to show the crosshair, The paintball gun was a swep i found on and updated to work and incorperated it into a minigame of paintball, like 10 minutes of coding because i used fretta to do it… Just did it for a quick fun gamemode to play on a long boring day

Thanks! I needed a crosshair EXACTLY like that :slight_smile:

EDIT: It seems not to work? I tried it on singleplayer on the default “Sandbox” gamemode, and when I wrote in to the console: “HZ_Crosshair 1”, then nothing popped up. I also tried changing the color.


Whenever I enter the game then no LUA errors pop up or anything like that.


what’s LUA?

also did you release that paintball gamemode i thought i saw it somewhere.

Cool, Have fun with it

And no i never released it, However there is one out there floating around. I can try and find it for you if you want it

EDIT: Found the one thats out, heres the SVN link