How to display FactionMember PADs

Announcements, support questions, and discussion for Love/Hate.
Post Reply
dkrusenstrahle
Posts: 36
Joined: Sat Apr 20, 2024 7:03 pm

How to display FactionMember PADs

Post by dkrusenstrahle »

Hello,

Is there a way to list out all the FactionMembers and their PAD values as well as how they feel about the player?
I want to display that in the UI canvas.

Thank you!
User avatar
Tony Li
Posts: 20680
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to display FactionMember PADs

Post by Tony Li »

Hi,

For quick info, you can set up a Faction Member Debugger Canvas to float atop each faction member's head. (Add a FactionMemberDebugger component to the faction member, and assign the "Faction Member Debug Canvas" prefab or "Faction Member Debug Canvas TMPro" prefab to it.)

For a more detailed report, here's an example:

Code: Select all

// Find the player's faction:
int playerFactionID = 0;
foreach (var faction in FactionManager.instance.factionDatabase.factions)
{
    if (faction.name == "Player")
    {
        playerFactionID = faction.id;
        break;
    }
}

// Report all faction members' states:
string s = "";
foreach (var factionMembers in FactionManager.instance.members)
{
    Faction faction = factionMembers.Key;
    List<FactionMember> members = factionMembers.Value;
    if (faction.id == playerFactionID) continue;
    s += $"Faction: {faction.name}\n";
    var affinity = FactionManager.instance.GetAffinity(faction.id, playerFactionID);
    s += $"  Affinity to player: {affinity}\n";
    foreach (var member in members)
    {
        var pad = member.pad;
        s += $"  {member.name} P={pad.pleasure} A={pad.arousal} D={pad.dominance} Happiness={pad.happiness}\n";
    }
}
Debug.Log(s);
dkrusenstrahle
Posts: 36
Joined: Sat Apr 20, 2024 7:03 pm

Re: How to display FactionMember PADs

Post by dkrusenstrahle »

Works perfactly! Thank you
User avatar
Tony Li
Posts: 20680
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to display FactionMember PADs

Post by Tony Li »

Glad to help!
dkrusenstrahle
Posts: 36
Joined: Sat Apr 20, 2024 7:03 pm

Re: How to display FactionMember PADs

Post by dkrusenstrahle »

Another thing. It looks like this below code only fetches the FactionMembers that are currently in the scene.

FactionManager.instance.members

Is there a way to fetch all faction members regardsless of they are located on the scene?
I want to track how the "villages" behaves and feels just like Stardew valley.

Thanks!
User avatar
Tony Li
Posts: 20680
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to display FactionMember PADs

Post by Tony Li »

Hi,

If you're interested in relationships (e.g., affinity), they're in the faction database, which is independent of any specific scene. You can get relationship info like this:

Code: Select all

// Find the player's faction:
int playerFactionID = 0;
foreach (var faction in FactionManager.instance.factionDatabase.factions)
{
    if (faction.name == "Player")
    {
        playerFactionID = faction.id;
        break;
    }
}

// Report all factions' affinities to player:
string s = "";
foreach (var faction in FactionManager.instance.factionDatabase.factions)
{
    if (faction.id == playerFactionID) continue;
    var affinity = FactionManager.instance.GetAffinity(faction.id, playerFactionID);
    s += $"Faction: {faction.name} affinity to player: {affinity}\n";
}
Debug.Log(s);
dkrusenstrahle
Posts: 36
Joined: Sat Apr 20, 2024 7:03 pm

Re: How to display FactionMember PADs

Post by dkrusenstrahle »

A perfect! Can I get their PADs somehow from here too?
User avatar
Tony Li
Posts: 20680
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to display FactionMember PADs

Post by Tony Li »

Not as easily. FactionMembers exist in their respective scenes.

However, if you're changing scenes using the save system (link is to DS documentation, but it's the same save system) or saving faction member data between scenes using FactionMember.SerializeToString(), you can examine the serialized string. It's a string of comma-separated values in this format:

factionID, happiness, pleasure, arousal, dominance, ...other values...

If you use the save system and FactionMemberSaver components, each faction member saves its string under its own Key. So if you know the faction member's key (e.g., "Sally"), you can get the PAD like this:

Code: Select all

string s = SaveSystem.currentSavedGameData.GetData("Sally");
string[] values = s.Split(',');
float happiness = float.Parse(values[1]);
float pleasure = float.Parse(values[2]);
float arousal = float.Parse(values[3]);
float dominance = float.Parse(values[4]);
dkrusenstrahle
Posts: 36
Joined: Sat Apr 20, 2024 7:03 pm

Re: How to display FactionMember PADs

Post by dkrusenstrahle »

Mm, I wish there was an easier way to just get all FactionMembers. Can I get a FactionMember based upon the faction name? Or perhaps I should put all NPC hidden just outside the scene so they get counted :)

How would I model an overview about the players relationships with the village people? Right now I can get affinity which I guess is enough but I need to access other things for the NPC, for example name and avatar (I have a special script on the NPC/prefab that allows me to add this).
User avatar
Tony Li
Posts: 20680
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to display FactionMember PADs

Post by Tony Li »

Hi,

If each faction member NPC has their own faction (which can have shared parent factions), you just go through the faction database's factions list -- for example, to get each NPC's relationships (e.g., affinity) regardless of what scene you're in.

If you have a special script on your NPC GameObject that has its name and avatar, how do you get that information when that NPC GameObject isn't present in the current scene?
Post Reply