.:: Bots United ::.

.:: Bots United ::. (http://forums.bots-united.com/index.php)
-   Half-Life 2 SDK (http://forums.bots-united.com/forumdisplay.php?f=62)
-   -   stuff that helps (http://forums.bots-united.com/showthread.php?t=3472)

Pierre-Marie Baty 24-01-2005 14:41

stuff that helps
 
stick this
Code:

void CPlugin::FireGameEvent (KeyValues *event)
{
  KeyValues *pKey;
  int data_type;
 
  // do we want to display game events on the fly ?
  if (hook_events.GetInt () > 0)
  {
          ServerConsole_printf ("PMTools: Got event \"%s\"\n", event->GetName ()); // event name
          ServerConsole_printf ("{\n"); // print the open brace
 
          // display the whole key/value tree for this event
          for (pKey = event->GetFirstSubKey (); pKey; pKey = pKey->GetNextKey ())
          {
                data_type = pKey->GetDataType (); // get the data type
 
                // given the data type, print out the data
                if (data_type == KeyValues.TYPE_NONE)
                        ServerConsole_printf ("  \"%s\" = no value (TYPE_NONE)\n", pKey->GetName ());
                else if (data_type == KeyValues.TYPE_STRING)
                        ServerConsole_printf ("  \"%s\" = \"%s\" (TYPE_STRING)\n", pKey->GetName (), pKey->GetString ());
                else if (data_type == KeyValues.TYPE_INT)
                        ServerConsole_printf ("  \"%s\" = %d (TYPE_INT)\n", pKey->GetName (), pKey->GetInt ());
                else if (data_type == KeyValues.TYPE_FLOAT)
                        ServerConsole_printf ("  \"%s\" = %f (TYPE_FLOAT)\n", pKey->GetName (), pKey->GetFloat ());
                else if (data_type == KeyValues.TYPE_PTR)
                {
                        if (pKey->GetPtr () == NULL) ServerConsole_printf ("  \"%s\" = NULL (TYPE_PTR)\n", pKey->GetName ());
                        else ServerConsole_printf ("  \"%s\" = 0x%x (TYPE_PTR)\n", pKey->GetName (), pKey->GetPtr ());
                }
                else if (data_type == KeyValues.TYPE_WSTRING)
                        ServerConsole_printf ("  \"%s\" = \"%s\" (TYPE_WSTRING)\n", pKey->GetName (), pKey->GetString ());
                else if (data_type == KeyValues.TYPE_COLOR)
                        ServerConsole_printf ("  \"%s\" = #%x%x%x, alpha 0x%x (TYPE_WSTRING)\n", pKey->GetName (), (pKey->GetInt () & 0xFF000000) >> 24, (pKey->GetInt () & 0x00FF0000) >> 16, (pKey->GetInt () & 0x0000FF00) >> 8, (pKey->GetInt () & 0x000000FF) >> 0);
                else if (data_type == KeyValues.TYPE_NUMTYPES)
                        ServerConsole_printf ("  \"%s\" = termination marker (TYPE_NUMTYPES)\n", pKey->GetName ());
          }
 
          ServerConsole_printf ("}\n"); // print the closing brace
  }
 
  return; // finished
}

in your Source plugin. Don't forget to declare a CVAR named "hook_events". Fire up a game, and enjoy.

That'll be in PMTools:Source ;).

Pierre-Marie Baty 24-01-2005 14:42

Re: stuff that helps
 
note: ServerConsole_printf() roughly equals msg().

dub 24-01-2005 16:04

Re: stuff that helps
 
Great work Pierre-Marie, I was wondering if you were going to add an option to dump KeyValues ;).


All times are GMT +2. The time now is 02:44.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.