Garry's Mod Wiki

GM:PostEntityFireBullets

  boolean GM:PostEntityFireBullets( Entity entity, table data )

Description

Called every time a bullet pellet (i.e. this hook is called multiple times for a shotgun shot) is fired from an entity. Notably this hook will have the final damage and aim direction for the bullet pellet.

See GM:EntityFireBullets if you wish to modify the bullets before they are fired.

This hook is called directly from Entity:FireBullets. Due to this, you cannot call Entity:FireBullets inside this hook or an infinite loop will occur crashing the game.

Arguments

1 Entity entity
The entity that fired the bullet
2 table with FiredBullet structure data
A table of data about the bullet that was fired.

See FiredBullet structure.

Returns

1 boolean
Return false to suppress the bullet.

Example

Shows client and server bullet traces/hitpos when developer 1 is enabled.

local bulletColor = SERVER and Color( 3, 169, 244, 100 ) or Color( 222, 169, 9, 100 ) local missColor = SERVER and Color( 137, 222, 255, 100 ) or Color( 255, 222, 102, 100 ) hook.Add( "PostEntityFireBullets", "ShowBulletTracers", function( ent, data ) if not ent:IsPlayer() then return end local tr = data.Trace local col = bulletColor if tr.Entity == game.GetWorld() then col = missColor end debugoverlay.Line( tr.StartPos, tr.HitPos, 10, col, true ) debugoverlay.Box( tr.HitPos, Vector( -1, -1, -1 ), Vector( 1, 1, 1 ), 10, col, true ) end )