]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/mutators/mutator/bloodloss/bloodloss.qc
c92a088693e4846dd40b7b4bc2c874fa8edf68fc
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mutators / mutator / bloodloss / bloodloss.qc
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
13 MUTATOR_HOOKFUNCTION(bloodloss, PlayerPreThink)
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))
22         {
23                 PHYS_INPUT_BUTTON_CROUCH(player) = true;
24
25                 if(time >= player.bloodloss_timer)
26                 {
27                         if(player.vehicle)
28                                 vehicles_exit(player.vehicle, VHEF_RELEASE); // TODO: boots player out of their vehicle each health rot tick!
29                         if(player.event_damage)
30                                 player.event_damage(player, player, player, 1, DEATH_ROT.m_id, DMG_NOWEP, player.origin, '0 0 0');
31                         player.bloodloss_timer = time + 0.5 + random() * 0.5;
32                 }
33         }
34 }
35
36 MUTATOR_HOOKFUNCTION(bloodloss, PlayerJump)
37 {
38         entity player = M_ARGV(0, entity);
39
40         if(GetResource(player, RES_HEALTH) <= autocvar_g_bloodloss)
41                 return true;
42 }
43
44 MUTATOR_HOOKFUNCTION(bloodloss, BuildMutatorsString)
45 {
46         M_ARGV(0, string) = strcat(M_ARGV(0, string), ":bloodloss");
47 }
48
49 MUTATOR_HOOKFUNCTION(bloodloss, BuildMutatorsPrettyString)
50 {
51         M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Blood loss");
52 }
53 #endif
54
55 #ifdef CSQC
56 MUTATOR_HOOKFUNCTION(bloodloss, PlayerJump)
57 {
58         if(STAT(HEALTH) <= STAT(BLOODLOSS))
59                 return true;
60 }
61 #endif
62
63 #endif