Difference between revisions of "Valve Developer And Community Tidbits"

From Valve Developer Community
Jump to: navigation, search
m (Using external libarys with source: mailto:yahn@valvesoftware.com)
m
Line 10: Line 10:
 
the Init/Shutdown methods (see IGameSystem.h and numerous examples in
 
the Init/Shutdown methods (see IGameSystem.h and numerous examples in
 
the game and client .dlls).</dd></dl>
 
the game and client .dlls).</dd></dl>
 +
 +
==Finding Entities On The Client==
 +
From steven_m64
 +
 +
This is a nice little function that will search the current clientside entitys for the specified class name.
 +
 +
C_BaseEntity *GetEntFromClassname( const char *searchent )
 +
{
 +
  C_BaseEntityIterator iterator;
 +
  C_BaseEntity *pEnt = iterator.Next();
 +
  while ( pEnt != NULL )
 +
  {
 +
      if ( FStrEq( searchent, pEnt->GetClassname() ) )
 +
      {
 +
        return pEnt;
 +
      }
 +
      else
 +
      {
 +
            iterator.Next();
 +
      }
 +
  }
 +
  return pEnt;
 +
}
 +
==Vector To Screen Space==
 +
While trying to "put" a graphic on the screen while only having the entities vectors available I needed a function to convert vector space to screen space. I got a bunch of great answers but this is from Robin Walker.
 +
 +
If you have a clientside entity that you'd like to position a hud
 +
element around, use these utility functions in cdll_util.cpp:
 +
      bool GetTargetInScreenSpace( C_BaseEntity *pTargetEntity, int& iX, int& iY, Vector *vecOffset );
 +
And
 +
      bool GetVectorInScreenSpace( Vector pos, int& iX, int& iY,Vector *vecOffset );
 +
They'll return true if the target/vector is onscreen, and fill out the
 +
iX, iY with the screen X/Y position.
  
 
==Useful Forum Threads==
 
==Useful Forum Threads==
 
* [http://www.chatbear.com/board.plm?a=viewthread&b=4991&t=898,1122330204,23151&s=20&id=897291#27 Chatbear: Crashing when spawning a client]
 
* [http://www.chatbear.com/board.plm?a=viewthread&b=4991&t=898,1122330204,23151&s=20&id=897291#27 Chatbear: Crashing when spawning a client]
 
* [http://www.swallowbush.com/forum/viewtopic.php?t=294&sid=5b402dbd9cb0babca4107da5864d21a4 SwallowBush: Notes]
 
* [http://www.swallowbush.com/forum/viewtopic.php?t=294&sid=5b402dbd9cb0babca4107da5864d21a4 SwallowBush: Notes]

Revision as of 21:11, 10 April 2006

Use this page to post any information from Valve developers made on mailing lists, forums, or emails. This information should also be sorted into specific pages.

Using external libarys with source

Q: Mailing List
In order to do certain things in my mod I need to use some third-party libraries which need to do some initialization/termination work. Is there a certain place where I can call these functions as the mod is loaded?
A: Yahn Bernier
Anyway, you are free to add a DllMain to the server or client .dlls. In addition, you might look at dlls/GameInterface.cpp at DllInit(...) and put your init code in there. I believe there is a corresponding shutdown section. The other possibility is to create a new CAutoGameSystem and implement the Init/Shutdown methods (see IGameSystem.h and numerous examples in the game and client .dlls).

Finding Entities On The Client

From steven_m64

This is a nice little function that will search the current clientside entitys for the specified class name.

C_BaseEntity *GetEntFromClassname( const char *searchent )
{
  C_BaseEntityIterator iterator;
  C_BaseEntity *pEnt = iterator.Next();
  while ( pEnt != NULL )
  {
     if ( FStrEq( searchent, pEnt->GetClassname() ) )
     {
        return pEnt;
     }
     else
     {
           iterator.Next();
     }
  }
  return pEnt;
}

Vector To Screen Space

While trying to "put" a graphic on the screen while only having the entities vectors available I needed a function to convert vector space to screen space. I got a bunch of great answers but this is from Robin Walker.

If you have a clientside entity that you'd like to position a hud element around, use these utility functions in cdll_util.cpp:

      bool GetTargetInScreenSpace( C_BaseEntity *pTargetEntity, int& iX, int& iY, Vector *vecOffset );

And

      bool GetVectorInScreenSpace( Vector pos, int& iX, int& iY,Vector *vecOffset );

They'll return true if the target/vector is onscreen, and fill out the iX, iY with the screen X/Y position.

Useful Forum Threads