I'm having message problems of my own. I decided against the bsp reader,
since I just need to get one value. I set up a HUD element that would
keep track of the map type (the keyvalue info), so the HUD functions
that needed to know could hook into that.

However, now I'm having a problem where CHud::Init() will crash in
seemingly random places while running through all the hud elements init
functions. Generally one or more of them (m_Speed, m_AmmoSecondary,
etc.) will not be anything, but simply contain empty pointers and
whatnot, and the program will crash out with an access violation when it
tries to access the Init function.

The especially weird thing is that these objects worked before I put the
new message in and even if I remove the Init function for the new
object, it still crashes.

On the server-side:

In player.cpp:

int gmsgMapType = 0;

In LinkUserMessages():

        gmsgMapType = REG_USER_MSG( "MapType", 1 );

OK, now I think this is my problem, I really didn't know where to put
this:

I have in CBasePlayer::UpdateClientData():

        if (m_fInitHUD)
        {
                m_fInitHUD = FALSE;
                gInitHUD = FALSE;

                MESSAGE_BEGIN( MSG_ONE, gmsgResetHUD, NULL, pev );
                        WRITE_BYTE( 0 );
                MESSAGE_END();

                if ( !m_fGameHUDInitialized )
                {
                        MESSAGE_BEGIN( MSG_ONE, gmsgInitHUD, NULL, pev
);
                        MESSAGE_END();

                        g_pGameRules->InitHUD( this );
                        m_fGameHUDInitialized = TRUE;
                        if ( g_pGameRules->IsMultiplayer() )
                        {
                                FireTargets( "game_playerjoin", this,
this, USE_TOGGLE, 0 );
                        }
                }
                FireTargets( "game_playerspawn", this, this, USE_TOGGLE,
0 );

                CBaseEntity* pMapType = NULL;
                pMapType = UTIL_FindEntityByClassname( pMapType,
"hi_maptype" );


                MESSAGE_BEGIN( MSG_ONE, gmsgMapType, NULL, pev );
                        if( pMapType )
                                WRITE_BYTE(
((CMapType*)pMapType)->m_iMapType );
                        else
                                WRITE_BYTE( 5 ); // Otherwise any models
may be used.
                MESSAGE_END();
        }

On the client-side:

In hud.cpp:

        m_MapType.Init();

In hud.h:

class CHudMapType : public CHudBase
{
public:
        int m_iMapType;
        int Init( void );
        int MsgFunc_MapType( const char *pszName, int iSize, void* pbuf
);
};

In hud.h, in the definition of CHud:

        CHudMapType m_MapType;

Further down, same place:

        int      _cdecl MsgFunc_MapType( const char *pszName, int iSize,
void *pbuf );

In maptype.cpp:

DECLARE_MESSAGE( m_MapType, MapType );

int CHudMapType::Init( void )
{
        HOOK_MESSAGE( MapType );

        gHUD.AddHudElem( this );

        return 1;

}

int CHudMapType::MsgFunc_MapType( const char *pszName, int iSize, void*
pbuf )
{
        BEGIN_READ( pbuf, iSize );

        m_iMapType = READ_BYTE();

        return 1;

}




_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com

_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives, please visit:
http://list.valvesoftware.com/mailman/listinfo/hlcoders

Reply via email to