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

New effect: Bumper Peds #276

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
53 changes: 53 additions & 0 deletions src/gtasa/effects/custom/ped/BumperPedsEffect.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include "util/EffectBase.h"
#include "util/hooks/HookMacros.h"

class BumperPedsEffect : public EffectBase
{
private:
static inline float zHeight = 0.0f;

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

void
OnTick (EffectInstance *inst) override
{
zHeight = inst->Random (0.01f, 0.2f);
}

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 = zHeight;
return;
}

cb ();
}
};

DEFINE_EFFECT (BumperPedsEffect, "effect_bumper_peds",
GROUP_GRAVITY | GROUP_HANDLING);
Loading