![]() |
HOWTO: display HUD messages with your server plugin
Thanks to some tips I found at the SourceMod.net forums, I have devised out a simple way to print HUD messages in server plugins.
You certainly know how to print messages to console (using Msg()), and how to print hint messages and dialog boxes (thanks to the examples provided by Valve in the empty server plugin .cpp file), but printing real HUD messages using SayText network messages like in HL1 was problematic: 1. Because Valve doesn't provide server plugins with an interface for knowing about user message IDs and names, and 2. Because in order to send a user message you need to include a recipient filter class and there is no simple way to include the SDK one in a plugin. To solve 1, the SourceMod guys (I think it was VanceLorgin) found out that the SayText user message ID is 3. Since the code in the SDK that deals with user messages is located in "game_shared", we can without many risk assume that this value will remain constant between most if not all game DLLs. To solve 2, you'll have to write your own recipient filter class. It doesn't need to be very complicated. A "recipient filter" is a structure that tells the Source engine about the recipients of a particular network message. This is usually a list of entity indices (such as player indices). Here's the one I made: Code:
// helper class As you can see, this class is derived from IRecipientFilter. As a result, don't forget to #include "IRecipientFilter.h" in your project, because that's where this parent class is defined. Now, you also need to know how to send network messages. Contrarily to HL1, in Source the network message can be a stream of bits, and not bytes. This is obviously to save on bandwidth. All the data must pass through a serialization and deserialization interface when they are sent and received. This is why network messages have their own class for writing and reading bits and bytes: bf_read and bf_write. The WriteString(), WriteByte() etc. functions you know from the HL1 enginefuncs have been moved into the bf_write class, which is the one we are interested in here (since we want to WRITE a SayText message). To use them, you must #include "bitbuf.h" in your project files. We are ready to send our message now. Code:
void HUD_printf (char *string, edict_t *pPlayerEdict) *edit* fixed typo, added to wiki |
Re: HOWTO: display HUD messages with your server plugin
good one, PMB.
I was looking for something like this. |
Re: HOWTO: display HUD messages with your server plugin
the wiki version is much more documented
http://wiki.bots-united.com/index.ph...er%20plugin%3F please contribute to our wiki as soon as you find something useful guys :) |
Re: HOWTO: display HUD messages with your server plugin
pmb, you do realize you code with C++ now do ya? ;)
very nicely done! :D |
Re: HOWTO: display HUD messages with your server plugin
Quote:
|
All times are GMT +2. The time now is 03:25. |
Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.