Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.1 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Simple entity to transmit message to the client
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. class CGameMessageEntity : public CLogicalEntity
  8. {
  9. public:
  10. DECLARE_CLASS( CGameMessageEntity, CLogicalEntity );
  11. DECLARE_DATADESC();
  12. CGameMessageEntity( void ) {};
  13. void InputDisplayMessage( inputdata_t &data );
  14. string_t m_strText;
  15. };
  16. LINK_ENTITY_TO_CLASS( logic_game_message, CGameMessageEntity );
  17. BEGIN_DATADESC( CGameMessageEntity )
  18. DEFINE_KEYFIELD( m_strText, FIELD_STRING, "text" ),
  19. DEFINE_INPUTFUNC( FIELD_VOID, "DisplayMessage", InputDisplayMessage ),
  20. END_DATADESC()
  21. void CGameMessageEntity::InputDisplayMessage( inputdata_t &data )
  22. {
  23. // Only send this message the local player
  24. CSingleUserRecipientFilter user( UTIL_PlayerByIndex(1) );
  25. user.MakeReliable();
  26. // Start the message block
  27. UserMessageBegin( user, "GameMessage" );
  28. // Send our text to the client
  29. WRITE_STRING( STRING( m_strText ) );
  30. // End the message block
  31. MessageEnd();
  32. }