return true;
}
-MUTATOR_HOOKFUNCTION(ca, ClientConnect)
-{
- entity player = M_ARGV(0, entity);
- player.ca_damage_counter = 0;
-}
MUTATOR_HOOKFUNCTION(ca, ClientDisconnect)
{
}
if (scorer)
- {
- // assign damage score in units (rounded) to avoid bugs with float score
- scorer.ca_damage_counter += scorer_damage;
- float score_counter = scorer.ca_damage_counter / autocvar_g_ca_damage2score;
- if (score_counter >= -0.5 && score_counter < 0.5)
- return;
- // NOTE: this code works for subtracting score too
- int points = floor(score_counter + 0.5);
- GameRules_scoring_add(scorer, SCORE, points);
-
- scorer.ca_damage_counter -= points * autocvar_g_ca_damage2score;
- }
+ GameRules_scoring_add_float2int(scorer, SCORE, scorer_damage, ca_damage_counter, autocvar_g_ca_damage2score);
}
MUTATOR_HOOKFUNCTION(ca, CalculateRespawnTime)
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);
void GameRules_scoring_vip(entity player, bool value);
bool GameRules_scoring_is_vip(entity player);
+#define GameRules_scoring_add_float2int(client, fld, value, float_field, score_factor) \
+ _GameRules_scoring_add_float2int(client, SP_##fld, value, float_field, score_factor)
+float _GameRules_scoring_add_float2int(entity client, entity sp, float value, .float field, float score_factor);
#define GameRules_scoring_add(client, fld, value) _GameRules_scoring_add(client, SP_##fld, value)
float _GameRules_scoring_add(entity client, entity sp, float value);
#define GameRules_scoring_add_team(client, fld, value) _GameRules_scoring_add_team(client, SP_##fld, ST_##fld, value)