Weapon Prediction

From Valve Developer Community
Jump to navigation Jump to search

Weapons in the Source Source can be 'predicted', which in this context means that the game expects effects and temporary entities to be generated on the client-side (i.e. the client will predict them). While weapon prediction is turned on for a player, the server will suppress any temporary entities or other special effects which are created during that player's simulation tick, and not transmit them to the client, in the expectation that the client has already accurately predicted and created these effects.

Where it doesn't work

If your client doesn't have sufficient knowledge about the world to accurately predict effects, weapon prediction will not work - typically you'll find effects not appearing on the client when they should.

In particular, if the effect is triggered or relies on a server event, the client will not be able to predict it. Also bear in mind that the effect creation code will have to exist client-side (in the client DLL)!

Toggling weapon prediction

In CBasePlayer (dlls/player.cpp) there is a simple boolean flag, m_bPredictWeapons. By default this is set to true, meaning that server weapon effects will be suppressed during the CBasePlayer::PhysicsSimulate call. GetSuppressHost() will return a pointer to the CBasePlayer during this time, and NULL normally (when no effect suppression is going on).

Examples

[Todo]