Skip to content

Commit

Permalink
New effect: Concrete Peds
Browse files Browse the repository at this point in the history
  • Loading branch information
gromchek committed Nov 30, 2023
1 parent 5b1d3c3 commit a2c48b2
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions src/gtasa/effects/custom/ped/ConcretePedsEffect.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include "util/EffectBase.h"
#include "util/hooks/HookMacros.h"

class ConcretePedsEffect : public EffectBase
{
private:
static inline std::array<float, 5> zFactor
= {0.2f, 0.15f, 0.25f, 0.15f, 0.3f};
static inline unsigned int idx = 0;

public:
void
OnStart (EffectInstance *inst) override
{
HOOK_METHOD_ARGS (inst, Hooked_CPed_KillPedWithCar,
void (CPed *, CVehicle *, float, bool), 0x54C5CC,
0x54C642, 0x60461F, 0x60491B, 0x604A0D);
idx = 0;
}

static void
Hooked_CPed_KillPedWithCar (auto &&cb, CPed *thisPed, CVehicle *car,
float arg1, bool arg2)
{
if (car && (thisPed != FindPlayerPed ()))
{
auto diff = car->GetPosition () - thisPed->GetPosition ();
diff.Normalise ();

float pushFactor = 0.25f;
if (CModelInfo::IsVehicleModelType (car->m_nModelIndex)
!= VEHICLE_AUTOMOBILE)
{
pushFactor *= 0.5f;
}

car->m_vecMoveSpeed.x
= std::clamp (diff.x, -pushFactor, pushFactor);
car->m_vecMoveSpeed.y
= std::clamp (diff.y, -pushFactor, pushFactor);
car->m_vecMoveSpeed.z = zFactor[idx++ % zFactor.size ()];

return;
}

cb ();
}
};

DEFINE_EFFECT (ConcretePedsEffect, "effect_concrete_peds",
GROUP_GRAVITY | GROUP_HANDLING);

0 comments on commit a2c48b2

Please sign in to comment.