Scope for a swep?

Well I’m making a swep that needs a scope and I have no clue how to make it. Can someone help me?

Have a function that toggles in and out of scope then set the FOV of the owner to the new FOV (i.e. 20)

Remember to call your function for secondary attack, and remember to turn off your scope on holster.

Can you give me an example? (for a func that toggles in and out of scope)

EDIT: Actually I used the realistic swep base and it worked, it zooms in but the overlay doesn’t show up.


function SWEP:DrawHUD()

if(ScopeLevel > 0) then
		local ScW, ScH, ScopeId

		ScW = surface.ScreenWidth()
		ScH = surface.ScreenHeight()

		ScopeId = surface.GetTextureID("weapons/scopes/scope2")
		QuadTable = {}
		QuadTable.texture 	= ScopeId
		QuadTable.color		= Color( 255, 255, 255, 255 )
		QuadTable.x = 0
		QuadTable.y = 0
		QuadTable.w = ScW
		QuadTable.h = ScH	
		draw.TexturedQuad( QuadTable )

That’s the cl_init.lua file. I don’t know what’s wrong with it.

Just search for tetina bonita’s realistic SWEP base. It’s not so realistic, but is really good to learn how to script SWEP’s.