Garry's Mod Wiki

GM:DrawPhysgunBeam

  boolean GM:DrawPhysgunBeam( Player ply, Weapon physgun, boolean enabled, Entity target, number physBone, Vector hitPos )

Description

Allows you to override physgun effects rendering.

This is still called when physgun_drawbeams is set to 0, because this hook is also capable of overriding physgun sprite effects, while the convar does not.

Arguments

1 Player ply
Physgun owner
2 Weapon physgun
The physgun
3 boolean enabled
Is the beam enabled
4 Entity target
Entity we are grabbing. This will be NULL if nothing is being held
5 number physBone
ID of the physics bone (PhysObj) we are grabbing at. Use Entity:TranslatePhysBoneToBone to translate to an actual bone.
6 Vector hitPos
Beam hit position relative to the physics bone (PhysObj) we are grabbing.

Returns

1 boolean
Return false to hide default effects

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 )