The Place to Start


Dead Icon 
BoRiS
Intermediate


Dead Icon

In this tutorial I'm going to show you how to add a dead-icon to the scoreboard. Before you start, I recommend you to read 2's "HUD Graphics for Half-Life" tutorial over at Wavelength.


In MP.dll

- in the beginning of player.cpp
    int gmsgSetCurWeap = 0;
    int gmsgSayText = 0;
    int gmsgTextMsg = 0;
    int gmsgSetFOV = 0;
    int gmsgShowMenu = 0;

    int gmsgDeadIcon = 0; // dead-icon

   
LINK_ENTITY_TO_CLASS( player, CBasePlayer );

- in the middle of player.cpp:
    gmsgShake = REG_USER_MSG("ScreenShake", sizeof(ScreenShake));
    gmsgFade = REG_USER_MSG("ScreenFade", sizeof(ScreenFade));
    gmsgAmmoX = REG_USER_MSG("AmmoX", 2);

   
gmsgDeadIcon = REG_USER_MSG("DeadIcon", 2); // dead-icon

   if ( gInitHUD )

- in CBasePlayer::Killed
    // reset FOV
    m_iFOV = m_iClientFOV = 0;

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

    // dead-icon
    MESSAGE_BEGIN( MSG_ALL, gmsgDeadIcon);
        WRITE_BYTE( ENTINDEX(this->edict()) );
        WRITE_BYTE( 2 );
    MESSAGE_END();

- in CBasePlayer::Spawn
    m_lastx = m_lasty = 0;

    EnableControl(true);


    // dead-icon
    MESSAGE_BEGIN( MSG_ALL, gmsgDeadIcon);
        WRITE_BYTE( ENTINDEX(this->edict()) );
        WRITE_BYTE( 1 );
    MESSAGE_END();


    g_pGameRules->PlayerSpawn( this );


HUD.txt

In the top of HUD.txt there is a number. Add 2 to that number because we are going to use 2 new sprites. The unmodified number is 123 so replace it with 125.
Then add:
deadicon        320 laserdot      0    0    16    16
deadicon        640 laserdot    0      0    16    16
I don't have any icon for this so I'm using a red dot...


CLIENT.dll

- in hud.h, find "class CHudScoreboard: public CHudBase". Add "int dead;" in "struct extra_player_info_t", like this
    struct extra_player_info_t {
        short frags;
        short deaths;
        char teamname[MAX_TEAM_NAME];

        int dead;
    };

- a few lines later
   void GetAllPlayersInfo( void );

private:
    HSPRITE DeadSprite;
    wrect_t *DeadRect;


};

- in the top of scoreboard.cpp add this
    DECLARE_MESSAGE( m_Scoreboard, TeamInfo );
    DECLARE_MESSAGE( m_Scoreboard, TeamScore );

    DECLARE_MESSAGE( m_Scoreboard, DeadIcon ); // Dead-Icon message from mp.dll

- and this
    HOOK_MESSAGE( TeamScore );
    HOOK_MESSAGE( TeamInfo );

    HOOK_MESSAGE( DeadIcon );

- add this void where the other "MsgFunc"s are...
int CHudScoreboard :: MsgFunc_DeadIcon( const char *pszName, int iSize, void *pbuf )
{
    BEGIN_READ( pbuf, iSize );
    short cl = READ_BYTE();
    int dead = READ_BYTE();

    if ( cl > 0 && cl <= MAX_PLAYERS )
    {
        m_PlayerExtraInfo[cl].dead = dead;
    }

    return 1;
}

- ... and add this to the CHudScoreBoard class in hud.h
    int MsgFunc_DeadIcon( const char *pszName, int iSize, void *pbuf );

- Add this in CHudScoreBoard::VidInit
int CHudScoreboard :: VidInit( void )
{
    // Load sprites here

   
    int HUD_DeadSprite = gHUD.GetSpriteIndex( "deadicon" );
    DeadSprite = gHUD.GetSprite(HUD_DeadSprite);
    DeadRect = &gHUD.GetSpriteRect(HUD_DeadSprite);


    return 1;

- Finally in CHudScoreBoard::DrawPlayer
        else if ( pl_info->thisplayer ) // if it is their name, draw it a different color
        {
            // overlay the background in blue, then draw the score text over it
            FillRGBA( NAME_RANGE_MIN + xpos_rel - 5, ypos, PING_RANGE_MAX - 5, ROW_GAP, 0, 0, 255, 70 );
        }


        if (m_PlayerExtraInfo[best_player].dead == 2)
        {
            DeadSprite = LoadSprite("sprites/laserdot.spr");
            SPR_Set( DeadSprite, 255, 0, 0 );
            SPR_DrawAdditive( 0,xpos - 26 , ypos, DeadRect );
        }



OMG you killed Kenny, etc etc...

Any questions or suggestions should be sent to me: nexus@SoftHome.net