Customizable triggered HUD-message: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
{{TutPOV}}
This page from [http://www.sourcewiki.org/wiki/index.php/Creating_a_customizable_triggered_HUD-message sourceWiki]
This page from [http://www.sourcewiki.org/wiki/index.php/Creating_a_customizable_triggered_HUD-message 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.
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.
But it's missing one possibility which could 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.
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 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.
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.


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:
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 datadescription for '''CGameText''' and append this, the comments should be sufficient:
Find the end of the data description for '''CGameText''' and append this, the comments should be sufficient:
<pre>
<pre>
class CGSGameText : public CGameText
class CGSGameText : public CGameText
Line 44: Line 44:
</pre>
</pre>


To use the entity in hammer, you need to add the following definition to your fgd:
To use the entity in hammer, The following additions to your *.fdg need to be added:
<pre>
<pre>
@PointClass base(game_text) iconsprite("editor/game_text.vmt") = mm_game_text :  
@PointClass base(game_text) iconsprite("editor/game_text.vmt") = mm_game_text :  
Line 53: Line 53:
</pre>
</pre>


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.
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.






[[Category:Tutorials]][[Category:Programming]]
[[Category:Tutorials]][[Category:Programming]]

Revision as of 01:11, 15 March 2006

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 *.fdg 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.