Skip to content

Commit 07cc06e

Browse files
committed
Make cough effect less annoying
1 parent ec0e41e commit 07cc06e

File tree

1 file changed

+39
-17
lines changed

1 file changed

+39
-17
lines changed

src/gtasa/effects/custom/ped/CoughEffect.cpp

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ using namespace plugin;
88
class CoughEffect : public EffectBase
99
{
1010
private:
11-
int timer = 0;
12-
const int MIN_COUGH_TIME_SEC = 3;
13-
const int MAX_COUGH_TIME_SEC = 4;
14-
const int MAX_WAIT_TIME_SEC = 7;
15-
const int MIN_WAIT_TIME_SEC = 5;
16-
bool isPlayerOnly = false;
11+
int timer = 0;
12+
const int COUGH_TIME = 3000;
13+
const int MAX_WAIT_TIME_SEC = 8;
14+
const int MIN_WAIT_TIME_SEC = 6;
15+
bool isPlayerOnly = false;
1716

1817
public:
1918
CoughEffect (bool playerOnly) : isPlayerOnly (playerOnly) {}
@@ -60,27 +59,50 @@ class CoughEffect : public EffectBase
6059
if (!ped) return;
6160

6261
auto *vehicle = ped->m_pVehicle;
63-
if (vehicle && vehicle->m_pDriver == ped
64-
&& vehicle->m_vecMoveSpeed.Magnitude () > 0.15f)
62+
63+
if (vehicle)
64+
{
65+
const int vehicleId = vehicle->m_nModelIndex;
66+
auto vehicleType = CModelInfo::IsVehicleModelType (vehicleId);
67+
bool canSpin = false;
68+
switch (vehicleType)
69+
{
70+
case VEHICLE_AUTOMOBILE:
71+
case VEHICLE_BIKE: canSpin = true; break;
72+
default: break;
73+
}
74+
canSpin &= vehicle->m_pDriver == ped;
75+
canSpin &= vehicle->m_vecMoveSpeed.Magnitude () > 0.15f;
76+
canSpin &= inst->Random (0, 100000) % 2 == 0;
77+
78+
if (canSpin)
79+
{
80+
auto speed = (inst->Random (0, 1) ? 0.025f : -0.025f);
81+
vehicle->m_vecTurnSpeed.z += speed;
82+
}
83+
}
84+
85+
bool canPlayAnim = Command<Commands::IS_CHAR_ON_FOOT> (ped);
86+
canPlayAnim &= !ped->m_nPedFlags.bInVehicle;
87+
canPlayAnim &= !Command<Commands::IS_CHAR_IN_WATER> (ped);
88+
if (ped == FindPlayerPed ())
6589
{
66-
auto speed = vehicle->m_vecMoveSpeed.Magnitude ()
67-
* (inst->Random (0, 1) ? 0.12f : -0.12f);
68-
vehicle->m_vecTurnSpeed.z = speed;
90+
canPlayAnim &= !Command<Commands::IS_PLAYER_USING_JETPACK> (0);
91+
canPlayAnim &= GameUtil::IsPlayerSafe ();
6992
}
70-
if (!ped->m_nPedFlags.bInVehicle)
93+
94+
if (canPlayAnim)
7195
{
72-
int sec
73-
= inst->Random (MIN_COUGH_TIME_SEC, MAX_COUGH_TIME_SEC) * 1000;
7496
Command<eScriptCommands::COMMAND_TASK_PLAY_ANIM_NON_INTERRUPTABLE> (
75-
ped, "gas_cwr", "ped", 4.0, 1, 1, 1, 0, sec);
97+
ped, "gas_cwr", "ped", 4.0, 1, 1, 1, 0, COUGH_TIME);
7698
}
77-
ped->m_fHealth -= ped->m_fMaxHealth * 0.02f;
99+
ped->m_fHealth -= ped->m_fMaxHealth * 0.03f;
78100
ped->m_fHealth = std::max (0.0f, ped->m_fHealth);
79101

80102
int res = 0;
81103
int speechBank = 340;
82104
Command<eScriptCommands::COMMAND_SET_CHAR_SAY_CONTEXT_IMPORTANT> (
83-
ped, speechBank, 1, 1, 1 & res);
105+
ped, speechBank, 1, 1, 1, &res);
84106
}
85107
};
86108

0 commit comments

Comments
 (0)