Customizable triggered HUD-message
This page from sourceWiki
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 possibillity which I think would be very handy: you can't define the message via a triggered input.
That means, if you need several ingame-messages like "the door has opened", "someone shot the sheriff", etc which are triggered by entities via their outputs, you need to create that many game_text-entities to assign each source-output to it. Too many unneeded entities in my opinion.
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 you'd include a header (maprules.h) in your cpp and define the new class there, but unfortenately it's empty, which makes it's harder to enhance it in a clean way.
I went the shortest way, by including the new class in maprules.cpp and I hope it won't get changed to much by future SDK-updates:
Find the end of the datadescription 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, you need to add the following definition to your fgd:
@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's left to do is, creating that entity (mm_game_text) in your map, customize it as you would do with the entity game_text and link as many different outputs to it as you want.