Without, when you shoot at a target, you have to take your ping time into account, and aim ahead of it accordingly. So if your ping is 100ms, you have to aim for where the target's head will be in 100ms, rather than where you see it right now.Clearly this is less than ideal, and so multiplayer Source games implement lag compensation, which when calculating whether a bullet hits or not, briefly adjusts the position of all players back by the shooter's ping, so that it calculates the bullet collision based upon exactly what the shooter saw when they fired. This effect is missing for NPCs, but can be duplicated from the player lag compensation code without too much trouble.This tutorial details all the changes required - while a lot of code is involved, 95% of it is duplicated from player lag compensation code. MLagTrack - Purge ; delete mLagTrack; player.cpp / player.hTo decide what should be lag compensated, the player class has a function, WantsLagCompensationOnEntity - which returns true or false. Unfortunately, its designed to only accept a player as its 'entity' parameter - but we want it to lag compensate NPCs too, so we'll change it from taking only a CBasePlayer pointer to taking a CBaseEntity.
Which could be a player, or an NPC.Find where the function WantsLagCompensationOnEntity is defined, and change the first parameter from const CBasePlayer.pPlayer to const CBaseEntity.pEntityNow in player.cpp, find this function at around line 682, and change the CBasePlayer parameter to CBaseEntity, as before. Replace all references to pPlayer ( only in this function!) to pEntity (assuming thats what you renamed the parameter), and then remove the line.
This only works if the server is allowing lag compensation (svunlag 1) and if the firing player is requesting lag compensation (cllc 1 - note that the player must. Svunlag Enable/disable lag compensation entirely. Svmaxunlag Number of seconds to store player positions for. Default (and maximum) is 1. Simply wrap whatever code you want lag compensated within two calls to the lagcompensation object.
Float maxspeed; CBasePlayer. pPlayer = ToBasePlayer (( CBaseEntity. ) pEntity ); if ( pPlayer ) maxspeed = pPlayer - MaxSpeed ; else maxspeed = 600; float maxDistance = 1.5. maxspeed. svmaxunlag. GetFloat ;That should do exactly the same for players, and something similar for NPCs.hl2mpplayer.cpp / hl2mpplayer.hThe same function exists, more or less identically, for hl2mpplayer.h & hl2mpplayer.cpp, so we'll have to fix that too. Open them both up.
First in the header, find where the function WantsLagCompensationOnEntity is defined (as with player.h), and change the first parameter from const CBasePlayer.pPlayer to const CBaseEntity.pEntity.Now in hl2mpplayer.cpp, find WantsLagCompensationOnEntity. Except for a check at the start, this actually does exactly the same as the player.cpp version, so just chop everything except the first if, and tell it to call the player.cpp version by using BaseClass.
![Sv unilag kac olmal Sv unilag kac olmal](/uploads/1/2/5/5/125509542/130815303.jpg)
Historic client hitboxes (red) versus rewound server hitboxes (blue).Lag compensation is the notion of the server using a player's latency to rewind time when processing a, in order to see what the player saw when the command was sent. In combination with, lag compensation can help to combat network latency to the point of almost eliminating it from the perspective of an attacker. For a more detailed explanation see the article.By default only players are rewound, and one second of location/animation history is kept. Contents.Configuration cllagcompensation Allows clients to tell the server that they don't want their own commands lag compensated. This is not a cheat.
Cllagcomperrorcheck Deprecated? In theory displays error information for the given player index, in practice is not referenced anywhere.
Svlagcompensationforcerestore Cheat. Disabling this causes the game to check if each entity can still occupy its rewind position in the current, un-rewound world. If it can't, it is rewound to the last valid position instead of the desired one. To do: Why would anyone want that to happen?
Svshowlagcompensation Cheat. Displays rewound whenever a player is lag compensated. This fills the role of the old svshowhitboxes command, only without the confusion caused by the hitboxes also being shown when compensation is not in effect.Developer server builds (those compiled with ALLOWDEVELOPMENTCVARS) have some extra commands:svunlag Enable/disable lag compensation entirely.
Svmaxunlag Number of seconds to store player positions for. Default (and maximum) is 1. InvocationSimply wrap whatever code you want lag compensated within two calls to the lagcompensation object.