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

Added "Pulsating Gravity" effect #3035

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions ChaosMod/ChaosMod.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@
<ClCompile Include="Effects\db\Peds\PedsMercenaries.cpp" />
<ClCompile Include="Effects\db\Misc\MiscOilLeaks.cpp" />
<ClCompile Include="Effects\db\Player\PlayerIllegalInnocence.cpp" />
<ClCompile Include="Effects\db\Player\PlayerMagnetGravity.cpp" />
<ClCompile Include="Effects\db\Player\PlayerRandomStuntJump.cpp" />
<ClCompile Include="Effects\db\Player\PlayerTpToEverything.cpp" />
<ClCompile Include="Effects\db\Player\PlayerLagCamera.cpp" />
Expand Down
31 changes: 16 additions & 15 deletions ChaosMod/Effects/db/Player/PlayerForcefield.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Effect by Last0xygen
Effect by Last0xygen, modified
*/

#include <stdafx.h>
Expand All @@ -11,27 +11,28 @@ static void OnTick()
Ped player = PLAYER_PED_ID();
std::vector<Entity> 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)
{
Expand Down
33 changes: 16 additions & 17 deletions ChaosMod/Effects/db/Player/PlayerHasGravity.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Effect by ProfessorBiddle, modified
Effect by ProfessorBiddle, modified x2
*/

#include <stdafx.h>
Expand All @@ -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);
Expand All @@ -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);

Expand All @@ -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);
Expand Down
119 changes: 119 additions & 0 deletions ChaosMod/Effects/db/Player/PlayerMagnetGravity.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/*
Effect By OnlyRealNubs
*/

#include <stdafx.h>

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<Entity> 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
}
);
14 changes: 14 additions & 0 deletions ChaosMod/Util/EntityIterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Entity> 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;
}
1 change: 1 addition & 0 deletions ConfigApp/Effects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) },
};
}
}