Garry's Mod Wiki

Player:LagCompensation

Player:LagCompensation( boolean lagCompensation )

Description

This allows the server to mitigate the lag of the player by moving back all the entities that can be lag compensated to the time the player attacked with his weapon.

This technique is most commonly used on things that hit other entities instantaneously, such as traces.

Entity:FireBullets calls this function internally.

Lag compensation only works for players and entities that have been enabled with Entity:SetLagCompensated

Despite being defined shared, it can only be used server-side.

This function NEEDS to be disabled after you're done with it or it will break the movement of the entities affected!
Lag compensation does not support pose parameters.

Arguments

1 boolean lagCompensation
The state of the lag compensation, true to enable and false to disable.

Example

Do a crowbar-like melee trace, enabling lag compensation before doing so.

function SWEP:PrimaryAttack() local tracedata = {} tracedata.start = self.Owner:GetShootPos() tracedata.endpos = self.Owner:GetShootPos() + self.Owner:GetAimVector() * 75 tracedata.filter = self.Owner tracedata.mins = Vector( -8 , -8 , -8 ) tracedata.maxs = Vector( 8 , 8 , 8 ) -- It is recommended to use an IsPlayer check in case the weapon is being used by an NPC. if ( self.Owner:IsPlayer() ) then self.Owner:LagCompensation( true ) end local tr = util.TraceHull( tracedata ) if ( self.Owner:IsPlayer() ) then self.Owner:LagCompensation( false ) end if tr.Hit then print( tr.Entity ) --your code here end self:SetNextPrimaryFire( CurTime() + 0.5 ) end

Page Links


Special Pages


Wikis

?

Render Time: 30ms

DB GetPage 3
Generate Html 5
SaveChanges (1) 8
Render Body 0
Render Sidebar 11