render.DrawBeam()

Is anyone familiar with this? If you are, can you point me in the right direction,

i basically want a beam from my gun to where im aiming. I tried doing this but failed and have nothing now.

Here is an example from wiki;



local LASER = Material( 'cable/redlaser' )
function SWEP:ViewModelDrawn( viewmodel )
	if ( self:GetNWBool( "Active" ) then
		local attachmentIndex = viewmodel:LookupAttachment( "muzzle" )
		render.SetMaterial( LASER )
		render.DrawBeam( viewmodel:GetAttachment( attachmentIndex ).Pos, self.Owner:GetEyeTrace().HitPos, 2, 0, 12.5, Color( 255, 0, 0, 255 ) )
	end
end




local laserLine = Material("trails/laser")
local laserDot = Material("sprites/glow04_noz")
function SWEP:ViewModelDrawn(viewModel)
   local owner = self.Owner
   if !IsValid(owner) or !IsValid(viewModel) then return end
   
   if self.Laser then
      local attID = viewModel:LookupAttachment("muzzle")
      if attID == 0 then attID = 1 end
      
      local attPos = viewModel:GetAttachment(attID).Pos
      local wepTr = util.QuickTrace(attPos, viewModel:GetAngles():Forward()* 999, self)
      local randomDotSize = math.random() * 2.25
      
      cam.Start3D(EyePos(), EyeAngles())
         render.SetMaterial(laserLine)
         render.DrawBeam(wepTr.StartPos, wepTr.HitPos, 6, 6, 12.5, Color(255,0,0,255))
         render.SetMaterial(laserDot)
         render.DrawQuadEasy(wepTr.HitPos, wepTr.HitNormal, randomDotSize, randomDotSize, Color(255, 0, 0, 255), 0)
      cam.End3D()
   end
end


It’s not for a SWEP thou, would this still work?

Edit:

http://puu.sh/c8bsa/e870552ee3.jpg

It would draw a beam from any gun i have to my crosshair(middle of the screen)

Use a SWEP base

A SWEP base, hmm. Mind elaborating?

M9K Base
FA:S 2 Base
Sleek Weapon Base (CoderHire/ScriptFodder)

(Don’t really use M9K though unless you want your weapon to be mediocre)

I don’t know if im stupid or I perhaps didnt explain it good enough.

So i want to draw a beam from ANY gun ANY weapon base, no matter what weapon it is. From the gun, only i would be able to see it, Get the active weapon in my hand, then draw a beam that goes straight.
I appreciate all the help ive got.

Here is something that should help you, it’s bugged and I can’t find the right calculations to make it work on all FOV values so here it is anyway:



if CLIENT then
	local material = Material( "cable/redlaser" )
	hook.Add( "PreDrawTranslucentRenderables", "DrawLaserSight",
		function()
			local viewmodel = LocalPlayer():GetViewModel()
			local attachmentId = viewmodel:LookupAttachment( "muzzle" )
			local attachment = viewmodel:GetAttachment( attachmentId == 0 and 1 or attachmentId )
			if attachment then
				local trace = util.QuickTrace( attachment.Pos, attachment.Ang:Forward()*5000, viewmodel )
				render.SetMaterial( material )
				render.DrawBeam( attachment.Pos, trace.HitPos, 2, 0, 12.5, Color( 255, 0, 0, 255 ) )
			end
		end
	)
end


Kinda got it to work, had to mix both of yours code, atleast now it works with the basic gmod weapons. Thanks