From 6e0bacdab6928712fdbc0a2fa0591e1ae6acc136 Mon Sep 17 00:00:00 2001 From: Mario Date: Mon, 6 Jan 2020 22:29:58 +1000 Subject: [PATCH] Fix crouching not being applied while in bloodloss --- qcsrc/common/mutators/events.qh | 8 +++++ .../mutators/mutator/bloodloss/bloodloss.qc | 29 ++++++++++++------- qcsrc/common/physics/player.qc | 3 ++ 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/qcsrc/common/mutators/events.qh b/qcsrc/common/mutators/events.qh index cf8584870..6ee9574d0 100644 --- a/qcsrc/common/mutators/events.qh +++ b/qcsrc/common/mutators/events.qh @@ -112,3 +112,11 @@ MUTATOR_HOOKABLE(WeaponSound, EV_WeaponSound); /**/ o(string, MUTATOR_ARGV_1_string) \ /**/ MUTATOR_HOOKABLE(WeaponModel, EV_WeaponModel); + +/** decides whether a player can crouch or not */ +#define EV_PlayerCanCrouch(i, o) \ + /** player */ i(entity, MUTATOR_ARGV_0_entity) \ + /** do_crouch */ i(bool, MUTATOR_ARGV_1_bool) \ + /**/ o(bool, MUTATOR_ARGV_1_bool) \ + /**/ +MUTATOR_HOOKABLE(PlayerCanCrouch, EV_PlayerCanCrouch); diff --git a/qcsrc/common/mutators/mutator/bloodloss/bloodloss.qc b/qcsrc/common/mutators/mutator/bloodloss/bloodloss.qc index c92a08869..2a0ebec45 100644 --- a/qcsrc/common/mutators/mutator/bloodloss/bloodloss.qc +++ b/qcsrc/common/mutators/mutator/bloodloss/bloodloss.qc @@ -18,21 +18,23 @@ MUTATOR_HOOKFUNCTION(bloodloss, PlayerPreThink) return; // during intermission, the player's health changes to strange values for the engine, let's not cause damage during this phase! if(IS_PLAYER(player)) - if(GetResource(player, RES_HEALTH) <= autocvar_g_bloodloss && !IS_DEAD(player)) + if(GetResource(player, RES_HEALTH) <= autocvar_g_bloodloss && !IS_DEAD(player) && time >= player.bloodloss_timer) { - PHYS_INPUT_BUTTON_CROUCH(player) = true; - - if(time >= player.bloodloss_timer) - { - if(player.vehicle) - vehicles_exit(player.vehicle, VHEF_RELEASE); // TODO: boots player out of their vehicle each health rot tick! - if(player.event_damage) - player.event_damage(player, player, player, 1, DEATH_ROT.m_id, DMG_NOWEP, player.origin, '0 0 0'); - player.bloodloss_timer = time + 0.5 + random() * 0.5; - } + if(player.vehicle) + vehicles_exit(player.vehicle, VHEF_RELEASE); // TODO: boots player out of their vehicle each health rot tick! + if(player.event_damage) + player.event_damage(player, player, player, 1, DEATH_ROT.m_id, DMG_NOWEP, player.origin, '0 0 0'); + player.bloodloss_timer = time + 0.5 + random() * 0.5; } } +MUTATOR_HOOKFUNCTION(bloodloss, PlayerCanCrouch) +{ + entity player = M_ARGV(0, entity); + if(GetResource(player, RES_HEALTH) <= autocvar_g_bloodloss) + M_ARGV(1, bool) = true; // do_crouch +} + MUTATOR_HOOKFUNCTION(bloodloss, PlayerJump) { entity player = M_ARGV(0, entity); @@ -53,6 +55,11 @@ MUTATOR_HOOKFUNCTION(bloodloss, BuildMutatorsPrettyString) #endif #ifdef CSQC +MUTATOR_HOOKFUNCTION(bloodloss, PlayerCanCrouch) +{ + if(STAT(HEALTH) <= STAT(BLOODLOSS)) + M_ARGV(1, bool) = true; // do_crouch +} MUTATOR_HOOKFUNCTION(bloodloss, PlayerJump) { if(STAT(HEALTH) <= STAT(BLOODLOSS)) diff --git a/qcsrc/common/physics/player.qc b/qcsrc/common/physics/player.qc index 5ba6e8268..9f7ddab50 100644 --- a/qcsrc/common/physics/player.qc +++ b/qcsrc/common/physics/player.qc @@ -145,6 +145,9 @@ void PM_ClientMovement_UpdateStatus(entity this) do_crouch = false; } + MUTATOR_CALLHOOK(PlayerCanCrouch, this, do_crouch); + do_crouch = M_ARGV(1, bool); + if (do_crouch) { if (!IS_DUCKED(this)) { SET_DUCKED(this); -- 2.39.2