Difference between revisions of "UTIL SayTextFilter"

From Valve Developer Community
Jump to: navigation, search
m (Category.)
m (Cleanup)
 
Line 2: Line 2:
  
 
==Usage==
 
==Usage==
void UTIL_SayTextFilter(IRecipientFilter& filter, const char *pText, CBasePlayer *pPlayer, bool bChat)
+
<source lang=cpp>
 +
void UTIL_SayTextFilter( IRecipientFilter& filter, const char *pText, CBasePlayer *pPlayer, bool bChat )
 +
</source>
  
 
==Example==
 
==Example==
  
 
The code tells all players visible from an entity that it can see them.
 
The code tells all players visible from an entity that it can see them.
 +
<source lang=cpp>
 +
    // Collect all visible players
 +
    CRecipientFilter MyFilter;
 +
    MyFilter.AddRecipientsByPVS( GetAbsOrigin() );
 +
    MyFilter.MakeReliable();
  
// Collect all visible players
+
    // Tell visible players that I can see them
CRecipientFilter MyFilter;
+
    CBasePlayer *pPlayer = UTIL_GetCommandClient();
MyFilter.AddRecipientsByPVS( GetAbsOrigin() );
+
    if ( pPlayer )
MyFilter.MakeReliable();
+
    {
// Tell visible players that I can see them.
+
        char *pszCanSeeMsg = "";
CBasePlayer *player = UTIL_GetCommandClient();
+
        V_snprintf( pszCanSeeMsg, sizeof(pszCanSeeMsg), "%s can see you!", pPlayer->GetPlayerName() );
if (player) {
+
        UTIL_SayTextFilter( MyFilter, pszCanSeeMsg, UTIL_GetCommandClient() );
char* CanSeeMsg="";
+
    }
V_snprintf(CanSeeMsg, sizeof(CanSeeMsg), "%s can see you!", player->GetPlayerName());
+
</source>
UTIL_SayTextFilter(MyFilter, CanSeeMsg, UTIL_GetCommandClient());
 
}
 
  
 
[[Category:UTIL]]
 
[[Category:UTIL]]

Latest revision as of 13:25, 29 July 2021

A UTIL function that sends a message to players that match a filter. This function is the base function for the other UTIL_Say functions.

Usage

void UTIL_SayTextFilter( IRecipientFilter& filter, const char *pText, CBasePlayer *pPlayer, bool bChat )

Example

The code tells all players visible from an entity that it can see them.

    // Collect all visible players
    CRecipientFilter MyFilter;
    MyFilter.AddRecipientsByPVS( GetAbsOrigin() );
    MyFilter.MakeReliable();

    // Tell visible players that I can see them
    CBasePlayer *pPlayer = UTIL_GetCommandClient();
    if ( pPlayer )
    {
        char *pszCanSeeMsg = "";
        V_snprintf( pszCanSeeMsg, sizeof(pszCanSeeMsg), "%s can see you!", pPlayer->GetPlayerName() );
        UTIL_SayTextFilter( MyFilter, pszCanSeeMsg, UTIL_GetCommandClient() );
    }