Skip to main content

Factions and hostility

When two pedestrians meet in Los Santos, the engine consults a matrix of relationships to determine their initial attitude: Will they ignore each other, exchange greetings, or draw weapons on sight? In ScriptHookVDotNet, this system is governed by RelationshipGroup.

The modern RelationshipGroup struct

In older versions of SHVDN and obsolete documentation, relationship groups were treated as raw integers, and developers called static methods like World.SetRelationshipBetweenGroups(int, int, ...). That API is completely obsolete.

In modern SHVDN3, GTA.RelationshipGroup is a strongly typed struct:

using GTA;

// 1. Create or retrieve a named relationship group
RelationshipGroup guardGroup = World.AddRelationshipGroup("COMPANION_GUARD");

// 2. Get the player's native group
RelationshipGroup playerGroup = Game.Player.Character.RelationshipGroup;

// 3. Set mutual companionship (bidirectional = true)
guardGroup.SetRelationshipBetweenGroups(playerGroup, Relationship.Companion, true);

The Relationship levels

The Relationship enumeration defines how groups view one another:

RelationshipBehavior
CompanionFiercely loyal. Defends group members and fights their attackers.
RespectFriendly. Will assist if nearby.
LikeFavorable. Tolerates proximity and minor accidental bumps.
NeutralDefault citizen behavior. Ignores other groups until provoked.
DislikeSuspicious. May insult or back away if approached.
HateInstantly hostile. Will attack or flee based on combat attributes.

Assigning groups to entities

Once your group relationship rules are established, assign the group to your spawned pedestrians:

Ped guard = World.CreatePed(model, spawnPos);
guard.RelationshipGroup = guardGroup;

Now, the native game engine recognizes that this guard and the player belong to allied factions.

Faction membership vs the decision to attack

Here is a critical nuance you must remember for Project 05:

Belonging to a faction with Relationship.Hate tells the engine who is the enemy, but it does not dictate when to start shooting. If you rely purely on ambient hatred, NPCs will start shooting across three city blocks through bushes the instant they spawn.

In professional scripted mods, you use relationship groups to establish faction identity, but your script's own state machine (checking player distance, line of sight, and drawn weapons) decides the exact moment to trigger Task.Combat().

Next, we put this into practice in Project 03: Bodyguard.