I am trying to render a beam that starts at the muzzle position of a weapon, and ends where the entity with the weapon is aiming. This is a bit difficult, since render.DrawBeam() is client sided only, so what I decided to do was send a net message to all clients that contained the entity that was firing the beam. I then went on and found the muzzle position of their weapon the only way I know how, and then I found the entity’s eye trace. I do that part in the “PostDrawOpaqueRenderables” hook, so the entity’s muzzle position and eye trace is found and drawn every single frame to make it as smooth as possible.
The issue with all this is that the beam only shows up for the entity firing it, even though it should be showing up for everyone, as far as I could tell. Can anyone help?
--[===[ In a SWEP ]===]-- alreadySent = false function SWEP:PrimaryAttack() if SERVER then if alreadySent then return end util.AddNetworkString("drawE") net.Start("drawE") net.WriteEntity( self:GetOwner() ) net.Broadcast() alreadySent = true end end --[===[ In cl_init ]===]-- net.Receive("drawE", function() local shootingent = net.ReadEntity() local matEl = Material( "cable/blue_elec" ) local viewm = shootingent:GetViewModel() local obj = viewm:LookupAttachment( "muzzle" ) hook.Add("PostDrawOpaqueRenderables", "drawF", function() local startpos = viewm:GetAttachment( obj ).Pos local endpos = shootingent:GetEyeTrace().HitPos render.SetMaterial( matEl ) render.DrawBeam( startpos , endpos , 20, 1 , 1 , Color(255,255,255) ) end) end)