1
+ #include " util/EffectBase.h"
2
+ #include " util/GenericUtil.h"
3
+
4
+ #include < extensions/ScriptCommands.h>
5
+
6
+ using namespace plugin ;
7
+
8
+ class CoughEffect : public EffectBase
9
+ {
10
+ 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 ;
17
+
18
+ public:
19
+ CoughEffect (bool playerOnly) : isPlayerOnly (playerOnly) {}
20
+
21
+ void
22
+ OnStart (EffectInstance *inst) override
23
+ {
24
+ timer = inst->Random (MIN_WAIT_TIME_SEC, MAX_WAIT_TIME_SEC) * 1000 ;
25
+ }
26
+
27
+ void
28
+ OnTick (EffectInstance *inst) override
29
+ {
30
+ timer -= int (GenericUtil::CalculateTick ());
31
+ if (timer > 0 ) return ;
32
+
33
+ timer = inst->Random (MIN_WAIT_TIME_SEC, MAX_WAIT_TIME_SEC) * 1000 ;
34
+ GameUtil::SetVehiclesToRealPhysics ();
35
+
36
+ if (isPlayerOnly)
37
+ {
38
+ DoCoughEffect (FindPlayerPed (), inst);
39
+ }
40
+ else
41
+ {
42
+ for (CPed *ped : CPools::ms_pPedPool)
43
+ {
44
+ if (inst->Random (0 , 100000 ) % 3 == 0 ) continue ;
45
+
46
+ DoCoughEffect (ped, inst);
47
+ }
48
+ }
49
+ }
50
+
51
+ void
52
+ DoCoughEffect (CPed *ped, EffectInstance *inst)
53
+ {
54
+ if (!ped) return ;
55
+
56
+ auto *vehicle = ped->m_pVehicle ;
57
+ if (vehicle && vehicle->m_pDriver == ped
58
+ && vehicle->m_vecMoveSpeed .Magnitude () > 0 .15f )
59
+ {
60
+ auto speed = vehicle->m_vecMoveSpeed .Magnitude ()
61
+ * (inst->Random (0 , 1 ) ? 0 .12f : -0 .12f );
62
+ vehicle->m_vecTurnSpeed .z = speed;
63
+ }
64
+ if (!ped->m_nPedFlags .bInVehicle )
65
+ {
66
+ int sec
67
+ = inst->Random (MIN_COUGH_TIME_SEC, MAX_COUGH_TIME_SEC) * 1000 ;
68
+ Command<eScriptCommands::COMMAND_TASK_PLAY_ANIM_NON_INTERRUPTABLE> (
69
+ ped, " gas_cwr" , " ped" , 4.0 , 1 , 1 , 1 , 0 , sec);
70
+ }
71
+ ped->m_fHealth -= ped->m_fMaxHealth * 0 .02f ;
72
+ ped->m_fHealth = std::max (0 .0f , ped->m_fHealth );
73
+
74
+ int res = 0 ;
75
+ int speechBank = 340 ;
76
+ Command<eScriptCommands::COMMAND_SET_CHAR_SAY_CONTEXT_IMPORTANT> (
77
+ ped, speechBank, 1 , 1 , 1 & res);
78
+ }
79
+ };
80
+
81
+ DEFINE_EFFECT (CoughEffect, " effect_cough_player" ,
82
+ GROUP_HEALTH | GROUP_CONTROLS, true );
83
+ DEFINE_EFFECT (CoughEffect, " effect_cough_everyone" ,
84
+ GROUP_HEALTH | GROUP_CONTROLS, false );
0 commit comments