diff --git a/ChaosMod/ChaosMod.vcxproj b/ChaosMod/ChaosMod.vcxproj index c6cc7cdf9..c3fb4dcad 100644 --- a/ChaosMod/ChaosMod.vcxproj +++ b/ChaosMod/ChaosMod.vcxproj @@ -154,6 +154,7 @@ + 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/Effects/db/Player/PlayerMagnetGravity.cpp b/ChaosMod/Effects/db/Player/PlayerMagnetGravity.cpp new file mode 100644 index 000000000..5b7e73c39 --- /dev/null +++ b/ChaosMod/Effects/db/Player/PlayerMagnetGravity.cpp @@ -0,0 +1,119 @@ +/* + 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 OnStop() +{ + SET_PLAYER_INVINCIBLE(PLAYER_ID(), false); + for (Entity ent : GetAllEntitiesArray()) + { + SET_ENTITY_INVINCIBLE(ent, false); + } +} + +static void OnTick() +{ + DWORD64 currentTick = GetTickCount64(); + if (lastChangeTick < currentTick - changeInterval) + { + lastChangeTick = currentTick; + g_EffectState = (MagnetGravityState)(g_EffectState >= 1 ? -1 : g_EffectState + 1); + } + + Ped playerPed = PLAYER_PED_ID(); + Vector3 playerCoord = GET_ENTITY_COORDS(playerPed, false); + + int count = 10; + std::vector 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); + } + } + + if (g_EffectState != IDLE) + { + SET_PLAYER_INVINCIBLE(PLAYER_ID(), true); + + 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, OnStop, 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) }, }; } }