-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |