From b67e49b1a38e6c4c13b1632e3a9a570491ebdafc Mon Sep 17 00:00:00 2001 From: Veloscocity <134974775+Veloscocity@users.noreply.github.com> Date: Sat, 21 Oct 2023 14:15:44 -0400 Subject: [PATCH] Add effect "Use the Force" (#3597) Makes all peds vehicles and props within 50 meters copy the player's changes in velocity --------- Co-authored-by: pongo1231 --- ChaosMod/ChaosMod.vcxproj | 1 + .../Effects/db/Player/PlayerCopyForce.cpp | 83 +++++++++++++++++++ ConfigApp/Effects.cs | 1 + 3 files changed, 85 insertions(+) create mode 100644 ChaosMod/Effects/db/Player/PlayerCopyForce.cpp diff --git a/ChaosMod/ChaosMod.vcxproj b/ChaosMod/ChaosMod.vcxproj index ff98c027d..63fbda73f 100644 --- a/ChaosMod/ChaosMod.vcxproj +++ b/ChaosMod/ChaosMod.vcxproj @@ -151,6 +151,7 @@ + diff --git a/ChaosMod/Effects/db/Player/PlayerCopyForce.cpp b/ChaosMod/Effects/db/Player/PlayerCopyForce.cpp new file mode 100644 index 000000000..30c293bc5 --- /dev/null +++ b/ChaosMod/Effects/db/Player/PlayerCopyForce.cpp @@ -0,0 +1,83 @@ +// +// Effect by Veloscocity +// + +#include + +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 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 + } +); \ No newline at end of file diff --git a/ConfigApp/Effects.cs b/ConfigApp/Effects.cs index 2b021b11e..b03e5efe6 100644 --- a/ConfigApp/Effects.cs +++ b/ConfigApp/Effects.cs @@ -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) }, }; } }