Skip to content

Commit

Permalink
Add effect "Use the Force" (#3597)
Browse files Browse the repository at this point in the history
Makes all peds vehicles and props within 50 meters copy the player's changes in velocity

---------

Co-authored-by: pongo1231 <pongo1999712@gmail.com>
  • Loading branch information
Veloscocity and pongo1231 authored Oct 21, 2023
1 parent 51e9d59 commit b67e49b
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
1 change: 1 addition & 0 deletions ChaosMod/ChaosMod.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@
<ClCompile Include="Effects\db\Peds\PedsMinions.cpp" />
<ClCompile Include="Effects\db\Peds\PedsSpawnAngryJimmy.cpp" />
<ClCompile Include="Effects\db\Peds\PedsSpawnRoastingLamar.cpp" />
<ClCompile Include="Effects\db\Player\PlayerCopyForce.cpp" />
<ClCompile Include="Effects\db\Player\PlayerAFK.cpp" />
<ClCompile Include="Effects\db\Peds\PedsReflectiveDamage.cpp" />
<ClCompile Include="Effects\db\Peds\PedsToast.cpp" />
Expand Down
83 changes: 83 additions & 0 deletions ChaosMod/Effects/db/Player/PlayerCopyForce.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
//
// Effect by Veloscocity
//

#include <stdafx.h>

static Vector3 playerVelocity;

static void OnStart()
{
Ped playerPed = PLAYER_PED_ID();

if (IS_PED_IN_ANY_VEHICLE(playerPed, false))
{
playerVelocity = GET_ENTITY_VELOCITY(GET_VEHICLE_PED_IS_IN(playerPed, false));
}
else
{
playerVelocity = GET_ENTITY_VELOCITY(playerPed);
}
}

static void OnTick()
{
Ped playerPed = PLAYER_PED_ID();
Vector3 newVelocity;

if (IS_PED_IN_ANY_VEHICLE(playerPed, false))
{
newVelocity = GET_ENTITY_VELOCITY(GET_VEHICLE_PED_IS_IN(playerPed, false));
}
else
{
newVelocity = GET_ENTITY_VELOCITY(playerPed);
}
Vector3 newForce = newVelocity - playerVelocity;
playerVelocity = newVelocity;
std::vector<Entity> entities;

for (Ped ped : GetAllPeds())
{
if (ped != playerPed && !IS_PED_IN_ANY_VEHICLE(ped, false))
{
entities.push_back(ped);
}
}

for (Vehicle veh : GetAllVehs())
{
if (!IS_PED_IN_VEHICLE(playerPed, veh, false))
{
entities.push_back(veh);
}
}

for (Entity prop : GetAllProps())
{
entities.push_back(prop);
}

Vector3 playerCoord = GET_ENTITY_COORDS(playerPed, false);
for (Entity entity : entities)
{
Vector3 entityCoord = GET_ENTITY_COORDS(entity, false);
float distance = GET_DISTANCE_BETWEEN_COORDS(playerCoord.x, playerCoord.y, playerCoord.z, entityCoord.x,
entityCoord.y, entityCoord.z, true);
if (distance < 50)
{
Vector3 vel = GET_ENTITY_VELOCITY(entity) + newForce;
SET_ENTITY_VELOCITY(entity, vel.x, vel.y, vel.z);
}
}
}

// clang-format off
REGISTER_EFFECT(OnStart, nullptr, OnTick, EffectInfo
{
.Name = "Use The Force",
.Id = "player_copyforce",
.IsTimed = true,
.IsShortDuration = true
}
);
1 change: 1 addition & 0 deletions ConfigApp/Effects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ public enum EffectTimedType
{ "cocktail_shaker", new EffectInfo("Cocktail Shaker", EffectCategory.Misc, true, true) },
{ "screen_realfp", new EffectInfo("Real First Person", EffectCategory.Screen, true) },
{ "screen_hueshift", new EffectInfo("Hue Shift", EffectCategory.Screen, true) },
{ "player_copyforce", new EffectInfo("Use The Force", EffectCategory.Player, true, true) },
};
}
}

0 comments on commit b67e49b

Please sign in to comment.