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

Improvements to "Spawn Companion" effects #3703

Merged
merged 2 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions ChaosMod/Components/LuaScripts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "Util/EntityIterator.h"
#include "Util/File.h"
#include "Util/HelpText.h"
#include "Util/Peds.h"
#include "Util/Player.h"
#include "Util/PoolSpawner.h"
#include "Util/Script.h"
Expand Down Expand Up @@ -318,6 +319,7 @@ static const std::vector<ExposableFunc> ms_Exposables {
E("LoadModel", LoadModel),
E("GetAllPeds", GetAllPedsArray),
E("CreatePoolPed", CreatePoolPed),
E("SetCompanionRelationship", SetCompanionRelationship),
E("TeleportPlayer", [](float x, float y, float z, bool noOffset) { TeleportPlayer(x, y, z, noOffset); }),
E("GetAllVehicles", GetAllVehsArray),
E("CreatePoolVehicle", CreatePoolVehicle),
Expand Down
10 changes: 4 additions & 6 deletions ChaosMod/Effects/db/Peds/PedsSpawnCompanionBrad.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
#include <stdafx.h>

#include "Util/Peds.h"

#include "Effects/Register/RegisterEffect.h"

static void OnStart()
{
static const Hash model = "ig_brad"_hash;

Hash relationshipGroup;
ADD_RELATIONSHIP_GROUP("_COMPANION_BRAD", &relationshipGroup);
SET_RELATIONSHIP_BETWEEN_GROUPS(0, relationshipGroup, "PLAYER"_hash);
SET_RELATIONSHIP_BETWEEN_GROUPS(0, "PLAYER"_hash, relationshipGroup);

Ped playerPed = PLAYER_PED_ID();
Vector3 playerPos = GET_ENTITY_COORDS(playerPed, false);

Expand All @@ -22,7 +19,8 @@ static void OnStart()

SET_PED_SUFFERS_CRITICAL_HITS(ped, false);

SET_PED_RELATIONSHIP_GROUP_HASH(ped, relationshipGroup);
SetCompanionRelationship(ped, "_COMPANION_BRAD");

SET_PED_HEARING_RANGE(ped, 9999.f);

SET_PED_AS_GROUP_MEMBER(ped, GET_PLAYER_GROUP(PLAYER_ID()));
Expand Down
9 changes: 3 additions & 6 deletions ChaosMod/Effects/db/Peds/PedsSpawnCompanionChimp.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
#include <stdafx.h>

#include "Util/Peds.h"

#include "Effects/Register/RegisterEffect.h"

static void OnStart()
{
static const Hash modelHash = "a_c_chimp"_hash;

Hash relationshipGroup;
ADD_RELATIONSHIP_GROUP("_COMPANION_CHIMP", &relationshipGroup);
SET_RELATIONSHIP_BETWEEN_GROUPS(0, relationshipGroup, "PLAYER"_hash);
SET_RELATIONSHIP_BETWEEN_GROUPS(0, "PLAYER"_hash, relationshipGroup);

Ped playerPed = PLAYER_PED_ID();
Vector3 playerPos = GET_ENTITY_COORDS(playerPed, false);

Expand All @@ -21,7 +18,7 @@ static void OnStart()

SET_PED_SUFFERS_CRITICAL_HITS(ped, false);

SET_PED_RELATIONSHIP_GROUP_HASH(ped, relationshipGroup);
SetCompanionRelationship(ped, "_COMPANION_CHIMP");
SET_PED_HEARING_RANGE(ped, 9999.f);

SET_PED_AS_GROUP_MEMBER(ped, GET_PLAYER_GROUP(PLAYER_ID()));
Expand Down
9 changes: 3 additions & 6 deletions ChaosMod/Effects/db/Peds/PedsSpawnCompanionChop.cpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
#include <stdafx.h>

#include "Util/Peds.h"

#include "Effects/Register/RegisterEffect.h"

static void OnStart()
{
static const Hash modelHash = "a_c_chop"_hash;

Hash relationshipGroup;
ADD_RELATIONSHIP_GROUP("_COMPANION_CHOP", &relationshipGroup);
SET_RELATIONSHIP_BETWEEN_GROUPS(0, relationshipGroup, "PLAYER"_hash);
SET_RELATIONSHIP_BETWEEN_GROUPS(0, "PLAYER"_hash, relationshipGroup);

Ped playerPed = PLAYER_PED_ID();
Vector3 playerPos = GET_ENTITY_COORDS(playerPed, false);

Ped ped = CreatePoolPed(28, modelHash, playerPos.x, playerPos.y, playerPos.z, GET_ENTITY_HEADING(playerPed));
CurrentEffect::SetEffectSoundPlayOptions({ .PlayType = EffectSoundPlayType::FollowEntity, .Entity = ped });
SET_PED_COMBAT_ATTRIBUTES(ped, 0, false);
SET_PED_RELATIONSHIP_GROUP_HASH(ped, relationshipGroup);
SetCompanionRelationship(ped, "_COMPANION_CHOP");
SET_PED_HEARING_RANGE(ped, 9999.f);

SET_PED_AS_GROUP_MEMBER(ped, GET_PLAYER_GROUP(PLAYER_ID()));
Expand Down
9 changes: 3 additions & 6 deletions ChaosMod/Effects/db/Peds/PedsSpawnCompanionRandom.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
#include <stdafx.h>

#include "Util/Peds.h"

#include "Effects/Register/RegisterEffect.h"

static void OnStart()
{
Hash relationshipGroup;
ADD_RELATIONSHIP_GROUP("_COMPANION_RANDOM", &relationshipGroup);
SET_RELATIONSHIP_BETWEEN_GROUPS(0, relationshipGroup, "PLAYER"_hash);
SET_RELATIONSHIP_BETWEEN_GROUPS(0, "PLAYER"_hash, relationshipGroup);

Ped playerPed = PLAYER_PED_ID();
Vector3 playerPos = GET_ENTITY_COORDS(playerPed, false);

Expand All @@ -19,7 +16,7 @@ static void OnStart()

SET_PED_SUFFERS_CRITICAL_HITS(ped, false);

SET_PED_RELATIONSHIP_GROUP_HASH(ped, relationshipGroup);
SetCompanionRelationship(ped, "_COMPANION_RANDOM");
SET_PED_HEARING_RANGE(ped, 9999.f);

SET_PED_AS_GROUP_MEMBER(ped, GET_PLAYER_GROUP(PLAYER_ID()));
Expand Down
21 changes: 21 additions & 0 deletions ChaosMod/Util/Peds.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,24 @@ inline Ped CreateHostilePed(Hash modelHash, Hash weaponHash, Vector3 *location =
SET_PED_FIRING_PATTERN(ped, 0xC6EE6B4C);
return ped;
}

inline void SetCompanionRelationship(Ped ped, const char* name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering we expose it to the Lua runtime we should accept a const std::string& instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted, didn't know that

{
static const Hash playerGroup = "PLAYER"_hash;
Hash relationshipGroup;
ADD_RELATIONSHIP_GROUP(name, &relationshipGroup);
SET_RELATIONSHIP_BETWEEN_GROUPS(0, relationshipGroup, playerGroup);
SET_RELATIONSHIP_BETWEEN_GROUPS(0, playerGroup, relationshipGroup);
for (Ped ped : GetAllPeds())
{
Hash group = GET_PED_RELATIONSHIP_GROUP_HASH(ped);
if (_DOES_RELATIONSHIP_GROUP_EXIST(group))
{
SET_RELATIONSHIP_BETWEEN_GROUPS(GET_RELATIONSHIP_BETWEEN_GROUPS(playerGroup, group), relationshipGroup,
group);
SET_RELATIONSHIP_BETWEEN_GROUPS(GET_RELATIONSHIP_BETWEEN_GROUPS(group, playerGroup), group,
relationshipGroup);
}
}
SET_PED_RELATIONSHIP_GROUP_HASH(ped, relationshipGroup);
}