Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make cough effect less annoying #307

Open
wants to merge 1 commit into
base: 3.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading