TeeworldsCN / ddnet-pvp

DDNet based server designed for PvP
Other
10 stars 9 forks source link

[mini-project] General purpose stats collection interface #20

Open TsFreddie opened 3 years ago

TsFreddie commented 3 years ago

In many fng mods, stats is a common feature. We should provide a interface to let mods register and count their stats.

e.g.

// Register function provides headers/text for the stat id
Stats()->Register("Shots", STAT_SHOTS, STATTYPE_COUNT);
Stats()->Register("KPM", STAT_KILLSPERMINUTES, STATTYPE_PERMINUTES);
Stats()->Register("SPREE", STAT_SPREE, STATTYPE_MAX);

// Increase the stats or clear it
Stats()->Increase(pPlayer,  STAT_SHOTS, 1);
Stats()->Increase(pPlayer,  STAT_KILLSPERMINUTES, 1);
Stats()->Increase(pPlayer,  STAT_SPREE, 1);
Stats()->Reset(pPlayer,  STAT_SPREE); // To reset the counter to 0
Stats()->Clear(pPlayer,  STAT_SPREE); // To clear out the stats so the player no longer has a spree record