Xonotic
bloodloss.qc
Go to the documentation of this file.
1 #include "bloodloss.qh"
2 
3 #ifdef GAMEQC
4 #ifdef SVQC
5 REGISTER_MUTATOR(bloodloss, autocvar_g_bloodloss);
6 #elif defined(CSQC)
7 REGISTER_MUTATOR(bloodloss, true);
8 #endif
9 
10 #ifdef SVQC
11 .float bloodloss_timer;
12 
14 {
15  entity player = M_ARGV(0, entity);
16 
17  if(game_stopped)
18  return; // during intermission, the player's health changes to strange values for the engine, let's not cause damage during this phase!
19 
20  if(IS_PLAYER(player))
21  if(GetResource(player, RES_HEALTH) <= autocvar_g_bloodloss && !IS_DEAD(player) && time >= player.bloodloss_timer)
22  {
23  if(player.vehicle)
24  vehicles_exit(player.vehicle, VHEF_RELEASE); // TODO: boots player out of their vehicle each health rot tick!
25  if(player.event_damage)
26  player.event_damage(player, player, player, 1, DEATH_ROT.m_id, DMG_NOWEP, player.origin, '0 0 0');
27  player.bloodloss_timer = time + 0.5 + random() * 0.5;
28  }
29 }
30 
31 MUTATOR_HOOKFUNCTION(bloodloss, PlayerCanCrouch)
32 {
33  entity player = M_ARGV(0, entity);
34  if(GetResource(player, RES_HEALTH) <= autocvar_g_bloodloss)
35  M_ARGV(1, bool) = true; // do_crouch
36 }
37 
39 {
40  entity player = M_ARGV(0, entity);
41 
42  if(GetResource(player, RES_HEALTH) <= autocvar_g_bloodloss)
43  return true;
44 }
45 
46 MUTATOR_HOOKFUNCTION(bloodloss, BuildMutatorsString)
47 {
48  M_ARGV(0, string) = strcat(M_ARGV(0, string), ":bloodloss");
49 }
50 
51 MUTATOR_HOOKFUNCTION(bloodloss, BuildMutatorsPrettyString)
52 {
53  M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Blood loss");
54 }
55 #endif
56 
57 #ifdef CSQC
58 MUTATOR_HOOKFUNCTION(bloodloss, PlayerCanCrouch)
59 {
60  if(STAT(HEALTH) > 0 && STAT(HEALTH) <= STAT(BLOODLOSS))
61  M_ARGV(1, bool) = true; // do_crouch
62 }
64 {
65  if(STAT(HEALTH) > 0 && STAT(HEALTH) <= STAT(BLOODLOSS))
66  return true;
67 }
68 #endif
69 
70 #endif
#define REGISTER_MUTATOR(id, dependence)
Definition: base.qh:263
entity() spawn
void PlayerPreThink(entity this)
Definition: client.qc:2402
#define DMG_NOWEP
Definition: damage.qh:126
RES_HEALTH
Definition: ent_cs.qc:126
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
#define M_ARGV(x, type)
Definition: events.qh:17
#define IS_DEAD(s)
Definition: utils.qh:26
float GetResource(entity e, Resource res_type)
Returns the current amount of resource the given entity has.
Definition: cl_resources.qc:10
bool PlayerJump(entity this)
Definition: player.qc:330
void vehicles_exit(entity vehic, bool eject)
Definition: sv_vehicles.qc:788
#define MUTATOR_HOOKFUNCTION(...)
Definition: base.qh:310
float time
Definition: csprogsdefs.qc:16
#define IS_PLAYER(v)
Definition: utils.qh:9