Skip to content

Commit

Permalink
Make cough effect less annoying
Browse files Browse the repository at this point in the history
  • Loading branch information
gromchek committed Sep 9, 2024
1 parent ec0e41e commit 07cc06e
Showing 1 changed file with 39 additions and 17 deletions.
56 changes: 39 additions & 17 deletions src/gtasa/effects/custom/ped/CoughEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ using namespace plugin;
class CoughEffect : public EffectBase
{
private:
int timer = 0;
const int MIN_COUGH_TIME_SEC = 3;
const int MAX_COUGH_TIME_SEC = 4;
const int MAX_WAIT_TIME_SEC = 7;
const int MIN_WAIT_TIME_SEC = 5;
bool isPlayerOnly = false;
int timer = 0;
const int COUGH_TIME = 3000;
const int MAX_WAIT_TIME_SEC = 8;
const int MIN_WAIT_TIME_SEC = 6;
bool isPlayerOnly = false;

public:
CoughEffect (bool playerOnly) : isPlayerOnly (playerOnly) {}
Expand Down Expand Up @@ -60,27 +59,50 @@ class CoughEffect : public EffectBase
if (!ped) return;

auto *vehicle = ped->m_pVehicle;
if (vehicle && vehicle->m_pDriver == ped
&& vehicle->m_vecMoveSpeed.Magnitude () > 0.15f)

if (vehicle)
{
const int vehicleId = vehicle->m_nModelIndex;
auto vehicleType = CModelInfo::IsVehicleModelType (vehicleId);
bool canSpin = false;
switch (vehicleType)
{
case VEHICLE_AUTOMOBILE:
case VEHICLE_BIKE: canSpin = true; break;
default: break;
}
canSpin &= vehicle->m_pDriver == ped;
canSpin &= vehicle->m_vecMoveSpeed.Magnitude () > 0.15f;
canSpin &= inst->Random (0, 100000) % 2 == 0;

if (canSpin)
{
auto speed = (inst->Random (0, 1) ? 0.025f : -0.025f);
vehicle->m_vecTurnSpeed.z += speed;
}
}

bool canPlayAnim = Command<Commands::IS_CHAR_ON_FOOT> (ped);
canPlayAnim &= !ped->m_nPedFlags.bInVehicle;
canPlayAnim &= !Command<Commands::IS_CHAR_IN_WATER> (ped);
if (ped == FindPlayerPed ())
{
auto speed = vehicle->m_vecMoveSpeed.Magnitude ()
* (inst->Random (0, 1) ? 0.12f : -0.12f);
vehicle->m_vecTurnSpeed.z = speed;
canPlayAnim &= !Command<Commands::IS_PLAYER_USING_JETPACK> (0);
canPlayAnim &= GameUtil::IsPlayerSafe ();
}
if (!ped->m_nPedFlags.bInVehicle)

if (canPlayAnim)
{
int sec
= inst->Random (MIN_COUGH_TIME_SEC, MAX_COUGH_TIME_SEC) * 1000;
Command<eScriptCommands::COMMAND_TASK_PLAY_ANIM_NON_INTERRUPTABLE> (
ped, "gas_cwr", "ped", 4.0, 1, 1, 1, 0, sec);
ped, "gas_cwr", "ped", 4.0, 1, 1, 1, 0, COUGH_TIME);
}
ped->m_fHealth -= ped->m_fMaxHealth * 0.02f;
ped->m_fHealth -= ped->m_fMaxHealth * 0.03f;
ped->m_fHealth = std::max (0.0f, ped->m_fHealth);

int res = 0;
int speechBank = 340;
Command<eScriptCommands::COMMAND_SET_CHAR_SAY_CONTEXT_IMPORTANT> (
ped, speechBank, 1, 1, 1 & res);
ped, speechBank, 1, 1, 1, &res);
}
};

Expand Down

0 comments on commit 07cc06e

Please sign in to comment.