Skip to content

Commit

Permalink
New effect: Cough (#285)
Browse files Browse the repository at this point in the history
  • Loading branch information
gromchek authored Jan 26, 2024
1 parent b834f18 commit 418e2c6
Showing 1 changed file with 84 additions and 0 deletions.
84 changes: 84 additions & 0 deletions src/gtasa/effects/custom/ped/CoughEffect.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#include "util/EffectBase.h"
#include "util/GenericUtil.h"

#include <extensions/ScriptCommands.h>

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;

public:
CoughEffect (bool playerOnly) : isPlayerOnly (playerOnly) {}

void
OnStart (EffectInstance *inst) override
{
timer = inst->Random (MIN_WAIT_TIME_SEC, MAX_WAIT_TIME_SEC) * 1000;
}

void
OnTick (EffectInstance *inst) override
{
timer -= int (GenericUtil::CalculateTick ());
if (timer > 0) return;

timer = inst->Random (MIN_WAIT_TIME_SEC, MAX_WAIT_TIME_SEC) * 1000;
GameUtil::SetVehiclesToRealPhysics ();

if (isPlayerOnly)
{
DoCoughEffect (FindPlayerPed (), inst);
}
else
{
for (CPed *ped : CPools::ms_pPedPool)
{
if (inst->Random (0, 100000) % 3 == 0) continue;

DoCoughEffect (ped, inst);
}
}
}

void
DoCoughEffect (CPed *ped, EffectInstance *inst)
{
if (!ped) return;

auto *vehicle = ped->m_pVehicle;
if (vehicle && vehicle->m_pDriver == ped
&& vehicle->m_vecMoveSpeed.Magnitude () > 0.15f)
{
auto speed = vehicle->m_vecMoveSpeed.Magnitude ()
* (inst->Random (0, 1) ? 0.12f : -0.12f);
vehicle->m_vecTurnSpeed.z = speed;
}
if (!ped->m_nPedFlags.bInVehicle)
{
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->m_fHealth -= ped->m_fMaxHealth * 0.02f;
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);
}
};

DEFINE_EFFECT (CoughEffect, "effect_cough_player",
GROUP_HEALTH | GROUP_CONTROLS, true);
DEFINE_EFFECT (CoughEffect, "effect_cough_everyone",
GROUP_HEALTH | GROUP_CONTROLS, false);

0 comments on commit 418e2c6

Please sign in to comment.