Clientside laser

What I want to know is how do I make a laser beam come out of any gunbarrel? Ive tried this for ages, but never got it right.
I also want to use this in servers due to my friend is hosting a little server, where he needs a little hand from me. He actually came on the idea to get a laser beam pointing out to the crosshair.
I think I need to use ply:GetActiveWeapon() because it needs to work on any gun I take out/equip.
So please, could anyone help me with this?

[lua]
function DrawLazors()

local Weapons = LocalPlayer():GetViewModel()
if Weapons and ValidEntity(LocalPlayer():GetActiveWeapon()) then
local AttMent = Weapons:LookupAttachment(“1”)

if AttMent == 0 then

AttMent = Weapons:LookupAttachment(“muzzle”)
end

local Trace = util.GetPlayerTrace(LocalPlayer())
local TraceLine = util.TraceLine(Trace)

if Weapons:GetAttachment(AttMent) then

cam.Start3D(EyePos(),EyeAngles())
render.SetMaterial(Material(“cable/hydra”))
render.DrawBeam(Weapons:GetAttachment(AttMent).Pos, TraceLine.HitPos,5,0,0,Color(255,255,255,255))
cam.End3D()

end
end
end

hook.Add(“HUDPaint”,“Lazors”,DrawLazors)
[/lua]

You are welcome.

Just exactly what I wanted. Thanks!

Also, if you want to draw it “behind” the gun, use this hook.
[lua]
function DrawLazors()

local Weapons = LocalPlayer():GetViewModel()
if Weapons and ValidEntity(LocalPlayer():GetActiveWeapon()) then
local AttMent = Weapons:LookupAttachment(“1”)

if AttMent == 0 then

AttMent = Weapons:LookupAttachment(“muzzle”)
end

local Trace = util.GetPlayerTrace(LocalPlayer())
local TraceLine = util.TraceLine(Trace)

if Weapons:GetAttachment(AttMent) then

cam.Start3D(EyePos(),EyeAngles())
render.SetMaterial(Material(“cable/hydra”))
render.DrawBeam(Weapons:GetAttachment(AttMent).Pos, TraceLine.HitPos,5,0,0,Color(255,255,255,255))
cam.End3D()

end
end
end

hook.Add(“PostDrawOpaqueRenderables”,“Lazors”,DrawLazors)

[/lua]