GM:DrawPhysgunBeam
boolean GM:DrawPhysgunBeam( Player ply, Weapon physgun, boolean enabled, Entity target, number physBone, Vector hitPos )
Description
Allows you to override physgun beam drawing.
Arguments
5 number physBone
ID of the physics bone (PhysObj) we are grabbing at. Use Entity:TranslatePhysBoneToBone to translate to an actual bone.
Returns
Example
Example code that will draw a direct line from the physgun to the target.
hook.Add( "DrawPhysgunBeam", "test", function( ply, wep, enabled, target, bone, deltaPos )
-- Draw any physgun effects here that are not the beam.
-- Not "firing" the physgun? Don't draw anything.
if ( !enabled ) then return false end
local clr = Color( 255, 0, 0 )
-- White when not "firing" physgun, this will not work with the "if" above
if ( !enabled ) then clr = Color( 255, 255, 255, 255 ) end
local hitpos = ply:GetEyeTrace().HitPos
if ( IsValid( target ) ) then
local mt = target:GetBoneMatrix( bone )
if ( target:TranslatePhysBoneToBone( bone ) >= 0 ) then
mt = target:GetBoneMatrix( target:TranslatePhysBoneToBone( bone ) )
end
hitpos = LocalToWorld( deltaPos, Angle( 0, 0, 0 ), mt:GetTranslation(), mt:GetAngles() )
end
local srcPos = wep:GetAttachment( 1 ).Pos
if ( !ply:ShouldDrawLocalPlayer() ) then
srcPos = ply:GetViewModel():GetAttachment( 1 ).Pos
end
render.DrawLine( srcPos, hitpos, clr )
return false -- Hide original physics gun beam
end )