Improved Deathmatch Scoreboard


Very simple & very efficient. Also shows more than 12 people!

This tutorial lets you replace the current 12 player max scoreboard with a much more efficient and better looking design. This tutorial is based off of the "Deathmatch Scoreboard" tutorial by Druid. This version fixes a few bugs and lets it work perfectly with the 3.20 version of the source code.

Let's get started!
Add in the
blue code.
This is pretty simple.  Just replace your DeathmatchScoreboardMessage function in p_hud.c with this one:

/*
==================
DeathmatchScoreboardMessage

==================
*/
void DeathmatchScoreboardMessage (edict_t *ent, edict_t *killer)
{
    char    entry[1024];
    char    string[1400];
    int        stringlength;
    int        i, j, k;
    int        sorted[MAX_CLIENTS];
    int         sortedscores[MAX_CLIENTS];
    int        score, total;
    int        picnum;
    int        x, y;
    gclient_t    *cl;
    edict_t        *cl_ent;
    char    *tag;

    // sort the clients by score
    total = 0;
    for (i=0 ; i<game.maxclients ; i++)
    {
        cl_ent = g_edicts + 1 + i;
        if (!cl_ent->inuse)
            continue;
        score = game.clients[i].resp.score;
        for (j=0 ; j<total ; j++)
        {
            if (score > sortedscores[j])
                break;
        }
        for (k=total ; k>j ; k--)
        {
            sorted[k] = sorted[k-1];
            sortedscores[k] = sortedscores[k-1];
        }
        sorted[j] = i;
        sortedscores[j] = score;
        total++;
    }

    // print level name and exit rules
    string[0] = 0;

    stringlength = strlen(string);
        // Deathmatch scoreboard
        // make a header for the data
        Com_sprintf(entry, sizeof(entry),
        "xv 32 yv 16 string2 \"Player\" "
        "xv 168 yv 16 string2 \"Frags\" "
        "xv 216 yv 16 string2 \"Ping\" "
        "xv 256 yv 16 string2 \"Time\" "
        "xv 32 yv 24 string2 \"--------------------------------\" ");
   
        j = strlen(entry);
       
        if (stringlength + j < 1024)
        {
            strcpy (string + stringlength, entry);
            stringlength += j;
        }
   
        if (total > 25)
        total = 25;
       
        // add the clients in sorted order
   
        for (i=0 ; i<total ; i++)
        {
            cl = &game.clients[sorted[i]];
            cl_ent = g_edicts + 1 + sorted[i];
   
            picnum = gi.imageindex ("i_fixme");
   
            x = 32;
            y = 32 + 8 * i;
   
            if (cl_ent == ent)
            tag = "-->";
            else if (cl_ent == killer)
            tag = "--X";
            else
            tag = NULL;
   
            if (tag)
            {
                Com_sprintf (entry, sizeof(entry),
                "xv 8 yv %i string \"%s\" ",
                y, tag);
                j = strlen(entry);
   
                if (stringlength + j > 1024)
                    break;
                strcpy (string + stringlength, entry);
                stringlength += j;
            }
   
            // send the layout
            Com_sprintf(entry, sizeof(entry),
            "xv 32 yv %i string \"%s\" "
            "xv 152 yv %i string \"%7i %4i %4i\" ",
            y, cl->pers.netname,
            y, cl->resp.score,
            cl->ping,
            (level.framenum - cl->resp.enterframe)/600);
   
            j = strlen(entry);
   
            if (stringlength + j > 1024)
                break;
   
            strcpy (string + stringlength, entry);
            stringlength += j;
        }
    gi.WriteByte (svc_layout);
    gi.WriteString (string);
}

If you look through the code it puts everything into a CTF format that can handle many more than 12 people.  It also shows your position with a "-->",  and "--X" denotes the person that last killed you.
That's it! You're done! Simple, no?

Tutorial by Willi
Quake Style - Tutorials