Add player stats to scoreboard in sauerbraten/cube2

We all like sauerbraten, but I wanted a persistent look at my stats as I played. As such, I have written the following patch to display relevant info. Thanks to #sauerbraten for help.

This works against stable, “Trooper Edition”. There is a patch for SVN floating around out there somewhere, which includes flags captured as SVN has that variable implemented and I didn’t feel like backporting it. Hopefully there will be a release soon and it will be moot.

So, just apply this from sauerbraten/, not sauerbraten/src.

diff --git a/src/fpsgame/client.cpp b/src/fpsgame/client.cpp
index ca44789..35ff80d 100644
--- a/src/fpsgame/client.cpp
+++ b/src/fpsgame/client.cpp
@@ -1069,6 +1069,12 @@ namespace game
                        *actor = getclient(acn);
                 if(!actor) break;
                 actor->frags = frags;
+                //we should be able to get teamkills from the server somewhere
+                //because the server tracks them. right now we will track them ourselves.
+
+                if (actor==player1 && isteam(actor->team, victim->team)) {  player1->teamkills++; }
+                else if (actor==player1 && !isteam(actor->team, victim->team)) { player1->kills++; }
+
                 if(actor!=player1 && (!cmode || !cmode->hidefrags()))
                 {
                     defformatstring(ds)("@%d", actor->frags);
diff --git a/src/fpsgame/fps.cpp b/src/fpsgame/fps.cpp
index 5f82fe0..bbbfbbd 100644
--- a/src/fpsgame/fps.cpp
+++ b/src/fpsgame/fps.cpp
@@ -521,6 +521,8 @@ namespace game
             fpsent *d = players[i];
             d->frags = 0;
             d->deaths = 0;
+            d->teamkills = 0;
+            d->kills = 0;
             d->totaldamage = 0;
             d->totalshots = 0;
             d->maxhealth = 100;
diff --git a/src/fpsgame/game.h b/src/fpsgame/game.h
index f186418..a3e9bc6 100644
--- a/src/fpsgame/game.h
+++ b/src/fpsgame/game.h
@@ -465,7 +465,7 @@ struct fpsent : dynent, fpsstate
     int lasttaunt;
     int lastpickup, lastpickupmillis, lastbase, lastrepammo, flagpickup;
     int superdamage;
-    int frags, deaths, totaldamage, totalshots;
+    int frags, deaths, kills, teamkills, totaldamage, totalshots;
     editinfo *edit;
     float deltayaw, deltapitch, newyaw, newpitch;
     int smoothmillis;
@@ -477,7 +477,7 @@ struct fpsent : dynent, fpsstate

     vec muzzle;

-    fpsent() : weight(100), clientnum(-1), privilege(PRIV_NONE), lastupdate(0), plag(0), ping(0), lifesequence(0), respawned(-1), suicided(-1), lastpain(0), attacksound(-1), attackchan(-1), idlesound(-1), idlechan(-1), frags(0), deaths(0), totaldamage(0), totalshots(0), edit(NULL), smoothmillis(-1), playermodel(-1), ai(NULL), ownernum(-1), muzzle(-1, -1, -1)
+    fpsent() : weight(100), clientnum(-1), privilege(PRIV_NONE), lastupdate(0), plag(0), ping(0), lifesequence(0), respawned(-1), suicided(-1), lastpain(0), attacksound(-1), attackchan(-1), idlesound(-1), idlechan(-1), frags(0), deaths(0), kills(0), teamkills(0), totaldamage(0), totalshots(0), edit(NULL), smoothmillis(-1), playermodel(-1), ai(NULL), ownernum(-1), muzzle(-1, -1, -1)
     {
         name[0] = team[0] = info[0] = 0;
         respawn();
diff --git a/src/fpsgame/scoreboard.cpp b/src/fpsgame/scoreboard.cpp
index 3580b20..82c4aea 100644
--- a/src/fpsgame/scoreboard.cpp
+++ b/src/fpsgame/scoreboard.cpp
@@ -316,6 +316,14 @@ namespace game
                 }
             }
         }
+
+        g.textf("your stats", 0xFFFF80, "server");
+        g.pushlist();
+        g.textf("score: %d ", 0xFFFFDD, NULL, player1->frags);
+        g.textf("kills: %d ", 0xFFFFDD, NULL, player1->kills);
+        g.textf("deaths: %d ", 0xFFFFDD, NULL, player1->deaths);
+        g.textf("teamkills: %d", 0xFFFFDD, NULL, player1->teamkills);
+        g.poplist();
     }

     struct scoreboardgui : g3d_callback
0saves
If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.
This entry was posted in howto, software. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>