Garry's Mod Wiki

Revision Difference

Entity:FireBullets#549133

<function name="FireBullets" parent="Entity" type="classfunc"> <description> Fires a bullet. When used in a hook such as <page>WEAPON:Think</page> or <page>WEAPON:PrimaryAttack</page>, it will use <page>Player:LagCompensation</page> internally. <note>Lag compensation will not work if this function is called in a timer, regardless if the timer was made in a hook.</note>⤶ <note>Due to how FireBullets is set up internally, bullet tracers will always originate from attachment 1.</note> <note>Lag compensation will not work if this function is called in a timer, regardless if the timer was made in a hook.⤶ Due to how FireBullets is set up internally, bullet tracers will always originate from attachment 1.</note> </description> <realm>Shared</realm> <args> <arg name="bulletInfo" type="table">The bullet data to be used. See the <page>Structures/Bullet</page>.</arg> <arg name="suppressHostEvents" type="boolean" default="false">Has the effect of encasing the FireBullets call in <page>Global.SuppressHostEvents</page>, only works in multiplayer.</arg> </args> </function> ⤶ <example>⤶ <description>You can use this function in PrimaryAttack on custom SWEP </description>⤶ <code>⤶ function SWEP:PrimaryAttack()⤶ local bullet = {} // declare table⤶ bullet.Attacker = ply // You specify the player who shoot⤶ bullet.Num = 1 //The amount of bullets to fire⤶ bullet.Src = ply:GetShootPos() // The position to fire the bullets from⤶ bullet.Dir = ply:GetAimVector() // The fire direction⤶ bullet.Spread = Vector(0.1,0,0) // The spread, only x and y are needed⤶ bullet.Tracer = 1 // Show tracer for every x bullets⤶ bullet.TracerName = "Tracer" // The tracer name or effect You want ⤶ bullet.Force = 1 // The force of the bullets⤶ bullet.Damage = 10 // damage off bullet⤶ bullet.AmmoType = "<empty string>" // The ammunition name you can specify them ⤶ bullet.Callback = function(attacker, tr, dmginfo) // Function to be called after the bullet was fired⤶ if tr.HitGroup == HITGROUP_HEAD then // if i hit the head ⤶ dmginfo:ScaleDamage(2)⤶ end⤶ end⤶ self:FireBullets(bullet) // self its the weapon ⤶ end⤶ </code>⤶ </example>⤶