Customizable triggered HUD-message
This page from sourceWiki [modified for the Valve Developer Community to adhere to the Wiki standards]
There's an entity to display HUD-messages called game_text with various properties to define which, where and how to display text. But it's missing one possibility which could be very handy: you can't define the message via a triggered input.
That means, if several ingame-messages are needed, like "the door has opened", "someone shot the sheriff", etc which are triggered by entities via their outputs, many "game_text" entities need to be created. This can lead to a huge number of "game_text" entities which can only cause problems later on.
The class CGameText, to which the game_text-entity is linked, is defined in dlls/maprules.cpp. To enhance the CGameText, just inherit from it and add an additional input to it, providing the text to be shown. Usually one would include a header (maprules.h) in your cpp and define the new class there, but unfortenately it's empty, which makes it harder to enhance it in a clean way.
The easier way is to include the new class in maprules.cpp and hope it won't get changed too much by future SDK-updates:
Find the end of the data description for CGameText and append this, the comments should be sufficient:
class CGSGameText : public CGameText
{
public:
// that's right, we're inheriting from CGameText
DECLARE_CLASS(CGSGameText, CGameText);
DECLARE_DATADESC();
// this function handles the triggered input
void InputDisplayText( inputdata_t &inputdata );
};
// the entity is calles "mm_game_text"
LINK_ENTITY_TO_CLASS( mm_game_text, CGSGameText );
BEGIN_DATADESC( CGSGameText )
// the parameter of the input-function is a string
DEFINE_INPUTFUNC( FIELD_STRING, "DisplayText", InputDisplayText ),
END_DATADESC()
void CGSGameText::InputDisplayText( inputdata_t &inputdata )
{
// the baseclass already defines a memberfunction to set the
// message-text (CGameText::MessageSet), we just call it
MessageSet( STRING(inputdata.value.StringID()) );
// and show the message
Display( inputdata.pActivator );
}
To use the entity in hammer, The following additions to your *.fgd need to be added:
@PointClass base(game_text) iconsprite("editor/game_text.vmt") = mm_game_text :
"An entity that displays customized text on player's screens."
[
input DisplayText(string) : "Display this message text."
]
All that is needed is to create that entity (mm_game_text) in a map, customize it as though it were the entity game_text and link as many different outputs to it as needed.
