From 385a28178172c344b82b9f89b6d78daaaaf17d01 Mon Sep 17 00:00:00 2001 From: OnlyRealNubs <91900600+OnlyRealNubs@users.noreply.github.com> Date: Wed, 1 Jun 2022 12:56:09 -0400 Subject: [PATCH 1/4] Added "Pulsating Gravity" effect Every 2 seconds the effect alternates between being idle (doing nothing), pushing objects away from the player, and pulling objects towards the player. #### The cycle goes: ``` Pull Idle Push ``` ## - Removed unused variables from "Gravity Field" effect, and switched to a single iteration to get the entities. - switched to a single iteration to get the entities. "Forcefield" --- ChaosMod/ChaosMod.vcxproj | 1 + .../Effects/db/Player/PlayerForcefield.cpp | 31 ++--- .../Effects/db/Player/PlayerHasGravity.cpp | 33 +++-- ChaosMod/PlayerMagnetGravity.cpp | 114 ++++++++++++++++++ ChaosMod/Util/EntityIterator.h | 14 +++ ConfigApp/Effects.cs | 1 + 6 files changed, 162 insertions(+), 32 deletions(-) create mode 100644 ChaosMod/PlayerMagnetGravity.cpp diff --git a/ChaosMod/ChaosMod.vcxproj b/ChaosMod/ChaosMod.vcxproj index c6cc7cdf9..2f91a8be7 100644 --- a/ChaosMod/ChaosMod.vcxproj +++ b/ChaosMod/ChaosMod.vcxproj @@ -367,6 +367,7 @@ + Create Create diff --git a/ChaosMod/Effects/db/Player/PlayerForcefield.cpp b/ChaosMod/Effects/db/Player/PlayerForcefield.cpp index 66b5fb16a..ca3011003 100644 --- a/ChaosMod/Effects/db/Player/PlayerForcefield.cpp +++ b/ChaosMod/Effects/db/Player/PlayerForcefield.cpp @@ -1,5 +1,5 @@ /* - Effect by Last0xygen + Effect by Last0xygen, modified */ #include @@ -11,27 +11,28 @@ static void OnTick() Ped player = PLAYER_PED_ID(); std::vector entities; - for (Ped ped : GetAllPeds()) + for (Entity ent : GetAllEntitiesArray()) { - if (ped != player) + if (IS_ENTITY_A_PED(ent)) { - entities.push_back(ped); + if (ent != player) + { + entities.push_back(ent); + } } - } - - for (Vehicle veh : GetAllVehs()) - { - if (!IS_PED_IN_VEHICLE(player, veh, false)) + else if (IS_ENTITY_A_VEHICLE(ent)) + { + if (!IS_PED_IN_VEHICLE(player, ent, false)) + { + entities.push_back(ent); + } + } + else { - entities.push_back(veh); + entities.push_back(ent); } } - for (Entity prop : GetAllProps()) - { - entities.push_back(prop); - } - Vector3 playerCoord = GET_ENTITY_COORDS(player, false); for (Entity entity : entities) { diff --git a/ChaosMod/Effects/db/Player/PlayerHasGravity.cpp b/ChaosMod/Effects/db/Player/PlayerHasGravity.cpp index e489ed603..8dff0d0ed 100644 --- a/ChaosMod/Effects/db/Player/PlayerHasGravity.cpp +++ b/ChaosMod/Effects/db/Player/PlayerHasGravity.cpp @@ -1,5 +1,5 @@ /* - Effect by ProfessorBiddle, modified + Effect by ProfessorBiddle, modified x2 */ #include @@ -16,23 +16,26 @@ static void OnTick() Ped playerPed = PLAYER_PED_ID(); // get all moveable entities - for (Ped ped : GetAllPeds()) + for (Entity ent : GetAllEntitiesArray()) { - if (ped != playerPed) + if (IS_ENTITY_A_PED(ent)) { - entities.push_back(ped); + if (ent != playerPed) + { + entities.push_back(ent); + } } - } - for (Vehicle veh : GetAllVehs()) - { - if (!IS_PED_IN_VEHICLE(playerPed, veh, false)) + else if (IS_ENTITY_A_VEHICLE(ent)) { - entities.push_back(veh); + if (!IS_PED_IN_VEHICLE(playerPed, ent, false)) + { + entities.push_back(ent); + } + } + else + { + entities.push_back(ent); } - } - for (Entity prop : GetAllProps()) - { - entities.push_back(prop); } Vector3 playerCoord = GET_ENTITY_COORDS(playerPed, false); @@ -41,8 +44,6 @@ static void OnTick() for (Entity entity : entities) { static float startDistance = 50; - static float maxForceDistance = 1; - static float maxForce = 80; Vector3 entityCoord = GET_ENTITY_COORDS(entity, false); @@ -54,8 +55,6 @@ static void OnTick() { SET_PED_TO_RAGDOLL(entity, 5000, 5000, 0, true, true, false); } - float forceDistance = std::min(std::max(0.f, (startDistance - distance)), maxForceDistance); - float force = (forceDistance / maxForceDistance) * maxForce; Memory::ApplyForceToEntity(entity, 3, (entityCoord.x - playerCoord.x) * -1.f, (entityCoord.y - playerCoord.y) * -1.f, (entityCoord.z - playerCoord.z) * -1.f, 0, 0, 0, false, false, true, true, false, true); diff --git a/ChaosMod/PlayerMagnetGravity.cpp b/ChaosMod/PlayerMagnetGravity.cpp new file mode 100644 index 000000000..583d9d0cb --- /dev/null +++ b/ChaosMod/PlayerMagnetGravity.cpp @@ -0,0 +1,114 @@ +/* + Effect By OnlyRealNubs +*/ + +#include + +static enum MagnetGravityState +{ + PULL = -1, + IDLE, + PUSH +} g_EffectState; + +static DWORD64 lastChangeTick; +static const int changeInterval = 2000; + +static const float maxDistance = 60.f; +static const float minDistance = 40.f; + +static void OnStart() +{ + g_EffectState = MagnetGravityState::IDLE; + lastChangeTick = GetTickCount64(); +} + +static void OnTick() +{ + DWORD64 currentTick = GetTickCount64(); + if (lastChangeTick < currentTick - changeInterval) + { + lastChangeTick = currentTick; + g_EffectState = (MagnetGravityState)(g_EffectState >= 1 ? -1 : g_EffectState + 1); + } + + #pragma region Variables + static Ped player = PLAYER_ID(); + Ped playerPed = PLAYER_PED_ID(); + Vector3 playerCoord = GET_ENTITY_COORDS(playerPed, false); + + int count = 10; + std::vector entities; + #pragma endregion + + #pragma region Get Entities + // get all moveable entities + for (Entity ent : GetAllEntitiesArray()) + { + if (IS_ENTITY_A_PED(ent)) + { + if (ent != playerPed) + { + entities.push_back(ent); + } + } + else if (IS_ENTITY_A_VEHICLE(ent)) + { + if (!IS_PED_IN_VEHICLE(playerPed, ent, false)) + { + entities.push_back(ent); + } + } + else + { + entities.push_back(ent); + } + } + #pragma endregion + + if (g_EffectState != IDLE) + { + float randomDistance = g_Random.GetRandomFloat(minDistance, maxDistance); + 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 < maxDistance) + { + if (IS_ENTITY_A_PED(entity) && !IS_PED_RAGDOLL(entity)) + { + SET_PED_TO_RAGDOLL(entity, 5000, 5000, 0, true, true, false); + } + Memory::ApplyForceToEntity(entity, 3, (entityCoord.x - playerCoord.x) * (float)g_EffectState, + (entityCoord.y - playerCoord.y) * (float)g_EffectState, + (entityCoord.z - playerCoord.z) * (float)g_EffectState, + 0, 0, 0, false, false, true, true, false, true); + + if (IS_ENTITY_A_MISSION_ENTITY(entity)) + { + SET_ENTITY_INVINCIBLE(entity, true); + } + + if (--count <= 0) + { + WAIT(0); + + count = 10; + } + } + } + } +} + +// clang-format off +REGISTER_EFFECT(OnStart, nullptr, OnTick, EffectInfo + { + .Name = "Pulsating Gravity Field", + .Id = "player_magnetgravity", + .IsTimed = true, + .IsShortDuration = true, + .EffectCategory = EEffectCategory::Gravity + } +); \ No newline at end of file diff --git a/ChaosMod/Util/EntityIterator.h b/ChaosMod/Util/EntityIterator.h index f9c9ba674..b8130e1a9 100644 --- a/ChaosMod/Util/EntityIterator.h +++ b/ChaosMod/Util/EntityIterator.h @@ -176,4 +176,18 @@ _NODISCARD inline auto GetAllVehsArray() _NODISCARD inline auto GetAllPropsArray() { return GetAllProps().ToArray(); +} + +_NODISCARD inline auto GetAllEntitiesArray() +{ + auto pedsArray = GetAllPedsArray(); + auto vehsArray = GetAllVehsArray(); + auto propsArray = GetAllPropsArray(); + + std::vector entitiesArray; + entitiesArray.insert(entitiesArray.end(), pedsArray.begin(), pedsArray.end()); + entitiesArray.insert(entitiesArray.end(), vehsArray.begin(),vehsArray.end()); + entitiesArray.insert(entitiesArray.end(), propsArray.begin(), propsArray.end()); + + return entitiesArray; } \ No newline at end of file diff --git a/ConfigApp/Effects.cs b/ConfigApp/Effects.cs index e045e76e7..ba96444c8 100644 --- a/ConfigApp/Effects.cs +++ b/ConfigApp/Effects.cs @@ -372,6 +372,7 @@ public enum EffectTimedType { "screen_colorfulworld", new EffectInfo("Colorful World", EffectCategory.Screen, true) }, { "screen_arc", new EffectInfo("Arced Screen", EffectCategory.Screen, true, true) }, { "world_blackhole", new EffectInfo("Black Hole", EffectCategory.Misc, true, true) }, + { "player_magnetgravity", new EffectInfo("Pulsating Gravity Field", EffectCategory.Player, true, true) }, }; } } From 9a159d21654d1d393d2afb86db1fb1b1fb6fa982 Mon Sep 17 00:00:00 2001 From: OnlyRealNubs <91900600+OnlyRealNubs@users.noreply.github.com> Date: Wed, 1 Jun 2022 13:06:40 -0400 Subject: [PATCH 2/4] Add missing OnStop function --- ChaosMod/PlayerMagnetGravity.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/ChaosMod/PlayerMagnetGravity.cpp b/ChaosMod/PlayerMagnetGravity.cpp index 583d9d0cb..b2b7a2609 100644 --- a/ChaosMod/PlayerMagnetGravity.cpp +++ b/ChaosMod/PlayerMagnetGravity.cpp @@ -23,6 +23,15 @@ static void OnStart() lastChangeTick = GetTickCount64(); } +static void OnStop() +{ + SET_PLAYER_INVINCIBLE(PLAYER_ID(), false); + for (Entity ent : GetAllEntitiesArray()) + { + SET_ENTITY_INVINCIBLE(ent, false); + } +} + static void OnTick() { DWORD64 currentTick = GetTickCount64(); @@ -32,17 +41,12 @@ static void OnTick() g_EffectState = (MagnetGravityState)(g_EffectState >= 1 ? -1 : g_EffectState + 1); } - #pragma region Variables - static Ped player = PLAYER_ID(); Ped playerPed = PLAYER_PED_ID(); Vector3 playerCoord = GET_ENTITY_COORDS(playerPed, false); int count = 10; std::vector entities; - #pragma endregion - #pragma region Get Entities - // get all moveable entities for (Entity ent : GetAllEntitiesArray()) { if (IS_ENTITY_A_PED(ent)) @@ -64,10 +68,11 @@ static void OnTick() entities.push_back(ent); } } - #pragma endregion if (g_EffectState != IDLE) { + SET_PLAYER_INVINCIBLE(PLAYER_ID(), true); + float randomDistance = g_Random.GetRandomFloat(minDistance, maxDistance); for (Entity entity : entities) { From 7ec4d649a8701ae972de0af735b95184cd0ceaf3 Mon Sep 17 00:00:00 2001 From: OnlyRealNubs <91900600+OnlyRealNubs@users.noreply.github.com> Date: Wed, 1 Jun 2022 13:10:53 -0400 Subject: [PATCH 3/4] Move effect file location --- ChaosMod/ChaosMod.vcxproj | 2 +- ChaosMod/{ => Effects/db/Player}/PlayerMagnetGravity.cpp | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename ChaosMod/{ => Effects/db/Player}/PlayerMagnetGravity.cpp (100%) diff --git a/ChaosMod/ChaosMod.vcxproj b/ChaosMod/ChaosMod.vcxproj index 2f91a8be7..c3fb4dcad 100644 --- a/ChaosMod/ChaosMod.vcxproj +++ b/ChaosMod/ChaosMod.vcxproj @@ -154,6 +154,7 @@ + @@ -367,7 +368,6 @@ - Create Create diff --git a/ChaosMod/PlayerMagnetGravity.cpp b/ChaosMod/Effects/db/Player/PlayerMagnetGravity.cpp similarity index 100% rename from ChaosMod/PlayerMagnetGravity.cpp rename to ChaosMod/Effects/db/Player/PlayerMagnetGravity.cpp From 654c07800c6f35c01e98f37061ffba40160ca20f Mon Sep 17 00:00:00 2001 From: OnlyRealNubs <91900600+OnlyRealNubs@users.noreply.github.com> Date: Wed, 1 Jun 2022 13:12:30 -0400 Subject: [PATCH 4/4] Register missing OnStop --- ChaosMod/Effects/db/Player/PlayerMagnetGravity.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ChaosMod/Effects/db/Player/PlayerMagnetGravity.cpp b/ChaosMod/Effects/db/Player/PlayerMagnetGravity.cpp index b2b7a2609..5b7e73c39 100644 --- a/ChaosMod/Effects/db/Player/PlayerMagnetGravity.cpp +++ b/ChaosMod/Effects/db/Player/PlayerMagnetGravity.cpp @@ -108,7 +108,7 @@ static void OnTick() } // clang-format off -REGISTER_EFFECT(OnStart, nullptr, OnTick, EffectInfo +REGISTER_EFFECT(OnStart, OnStop, OnTick, EffectInfo { .Name = "Pulsating Gravity Field", .Id = "player_magnetgravity",