CRecipientFilter: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
No edit summary
 
Line 20: Line 20:
== Derived classes ==
== Derived classes ==


Several derived classes exist to automate the creation of common filters, with constructors set up to directly return an appropriately-configured filter.
Several derived classes exist to automate the creation of common filters, with constructors set up to directly return an appropriately-configured instance.


;<code>CBroadcastRecipientFilter()</code>
;<code>CBroadcastRecipientFilter()</code>
:All players.
:All players.
;<code>CLocalPlayerFilter()</code>
:The local player. Client-side only, needless to say! {{todo|Useful how?}}
;<code>CPASFilter([[origin]])</code>
;<code>CPASFilter([[origin]])</code>
:All players in the origin's [[PAS]].
:All players in the origin's [[PAS]].
Line 32: Line 30:
;<code>CSingleUserRecipientFilter([[CBasePlayer]])</code>
;<code>CSingleUserRecipientFilter([[CBasePlayer]])</code>
:A specific player.
:A specific player.
;<code>CLocalPlayerFilter()</code>
:The local player. Used as a dummy filter when calling functions requiring one on the client.


=== Example ===
=== Example ===

Revision as of 10:28, 16 May 2008

The CRecipientFilter class enables the server to pick and choose which clients it passes an item of data to. Most server-to-client communication supports it.

Alongside adding/removing clients individually or all at once, it can filter by:

Examples

CRecipientFilter MyFilter;
	MyFilter.AddRecipientsByPVS( GetAbsOrigin() );	// Origin of the host entity; clients within its PVS will be added.
	MyFilter.MakeReliable();			// All this does is make m_bReliable true! Best to use it anyway.
CRecipientFilter MyInverseFilter;
	MyInverseFilter.AddAllPlayers();
	MyInverseFilter.RemoveRecipientsByPVS( GetAbsOrigin() );	// Only players outside the PVS
	MyInverseFilter.MakeReliable();

Derived classes

Several derived classes exist to automate the creation of common filters, with constructors set up to directly return an appropriately-configured instance.

CBroadcastRecipientFilter()
All players.
CPASFilter(origin)
All players in the origin's PAS.
CPVSFilter(origin)
All players in the origin's PVS.
CSingleUserRecipientFilter(CBasePlayer)
A specific player.
CLocalPlayerFilter()
The local player. Used as a dummy filter when calling functions requiring one on the client.

Example

To make an entity produce a sound from another location:

EmitSound( CPASFilter(pPuppet->GetAbsOrigin()),pPuppet->entindex(),"Ventriloquist.Hello" );

See also

Tip.pngTip:You don't need to use the filter entities as a programmer - you already have direct access to the relevant data.