]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/gamemodes/sv_rules.qc
Merge branch 'terencehill/menu_quit_confirmation' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / gamemodes / sv_rules.qc
index 898ef3a4f581f0811828192b313495db0c8423e4..84d89909fe98274f47eb44e51999758f9371dbb6 100644 (file)
@@ -104,6 +104,25 @@ bool GameRules_scoring_is_vip(entity player)
     return player.m_GameRules_scoring_vip;
 }
 
+// Uses client.float_field to accumulate and consume float score and adds score to the player as int (rounded)
+// only when at least one unit of score has been accumulated. It works with negative score too
+// Float scores can't be used as score because they aren't supported by the QC score networking system
+// and online server browsers (e.g. qstat)
+float _GameRules_scoring_add_float2int(entity client, entity sp, float value, .float float_field, float score_factor)
+{
+       client.(float_field) += value;
+       float score_counter = client.(float_field) / score_factor;
+       if (score_counter >= -0.5 && score_counter < 0.5)
+               return 0;
+
+       // NOTE: this code works for subtracting score too
+       int points = floor(score_counter + 0.5);
+       client.(float_field) -= points * score_factor;
+       if (!points)
+               return 0;
+       return PlayerScore_Add(client, sp, points);
+}
+
 float _GameRules_scoring_add(entity client, entity sp, float value)
 {
     return PlayerScore_Add(client, sp, value);