Motd (Metamod:Source)

From AlliedModders Wiki
Jump to: navigation, search

Message of the Day (MOTD)

Showing a MOTD Panel

To show a MOTD, you'll need to add this code to your project. You'll also need to include an MRecipientFilter class. You may want to make it part of a class instance in your program, but this will work as an example.

First add this to AllPluginsLoaded:

mVGUIMenu = UserMessageIndex("VGUIMenu");

Then add this to your project:

void ShowMOTD(int index, char *title, char *msg, int type, char *cmd) {
   bf_write *buffer;
   MRecipientFilter filter;
   buffer = engine->UserMessageBegin(&filter, mVGUIMenu);
   if(cmd != NULL)
   switch(type) {
      case TYPE_TEXT:
         buffer->WriteString("0"); //TYPE_TEXT = 0, just display this plain text
      case TYPE_INDEX:
         buffer->WriteString("1"); //TYPE_INDEX, lookup text & title in stringtable
      case TYPE_URL:
         buffer->WriteString("2"); //TYPE_URL, show this URL
      case TYPE_FILE:
         buffer->WriteString("3"); //TYPE_FILE, show this local file
   buffer->WriteString(msg); // msg must not be greater than 192 characters
   if(cmd != NULL) {
      buffer->WriteString(cmd); // exec this command if panel closed
   return ;

Displaying Your Info in the MOTD Panel

The types of MOTD available are:

TYPE_TEXT = 0  // just display this plain text
TYPE_INDEX = 1 // lookup text & title in stringtable
TYPE_URL = 2   // show this URL
TYPE_FILE = 3  // show this local file

For example: To show a website

ShowMOTD( pEdict, "", " !", TYPE_URL, NULL )

To show some text

ShowMOTD( pEdict, "Some Text", "A Title", TYPE_TEXT, NULL )

Using TYPE_INDEX to Send More Than 255 Characters

TYPE_TEXT is limited to 255 characters. To send a longer piece of info, we need to create an entry in the StringTables and reference that using TYPE_INDEX.

First, we need to have a NetworkStringTableContainer:

INetworkStringTableContainer *m_NetworkStringtable;

Then, using the FIND_IFACE macro from the sample_mm plugin, we need to get the INetworkStringTable interface in Load():

	FIND_IFACE(engineFactory, m_NetworkStringtable, num, iface_buffer, INetworkStringTableContainer *);

Next, we can setup our string table entry:

	char msg[4096];
	// copy your info into msg
	// if you add any html tags, your msg will be formatted as html (for example <b>bold text</b>)
	INetworkStringTable *pInfoPanel = m_NetworkStringtable->FindTable("InfoPanel");
	if (pInfoPanel)
		bool save = m_Engine->LockNetworkStringTables(false);
		int StrIdx = pInfoPanel->AddString("myinfo");
		pInfoPanel->SetStringUserData(StrIdx, 4096, msg);

NOTE: 4096 characters is the max length, you should use the smallest size that your string data will fit into.

Finally you can show the MOTD panel with the info you added to the string tables:

ShowMOTD( EntityIndex, "myinfo", "My MOTD Window Title", 1, "" );

NOTE: I've tested this using html formatted text. I assume that the maximum length for standard text would also be 4096 characters. --L. Duke 00:45, 18 March 2006 (EST)