GM/DrawPhysgunBeam

From Garry's Mod
Jump to: navigation, search
 GM:DrawPhysgunBeam( )

Contents

Description

Allows you to override physgun beam drawing.

BUG

This is still called when physgun_drawbeams is disabled.

Issue Tracker: #3294

Arguments

Player ply

Physgun owner

Arguments

Weapon physgun

The physgun

Arguments

boolean enabled

Is the beam enabled

Arguments

Entity target

Entity we are grabbing. This will be NULL if nothing is being held

Arguments

number physBone

ID of the physics bone (PhysObj) we are grabbing at. Use Entity:TranslatePhysBoneToBone to translate to an actual bone.

Arguments

Vector hitPos

Beam hit position relative to the physics bone (PhysObj) we are grabbing.

Returns

boolean

Return false to hide default beam

Examples

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 )


Personal tools
Navigation