Load specific scenes based on relationships

Announcements, support questions, and discussion for Love/Hate.
Post Reply
TomsTales
Posts: 16
Joined: Tue Apr 27, 2021 6:38 am

Load specific scenes based on relationships

Post by TomsTales »

Hi Tony (I guess) ;),

my Love/hate system is set up and working with the dialogue system. Say based on 2 different answers, the characters relationship increases or decreases.

And the "end" of a scene, the player will have talked to various NPC and have a different relationship to everyone.

- Tom +50
- Horst -50

I want to load different scenes based on those numbers. Let's say if Tom and Horst both have a positive value, load 1, if one is negative, load 2, and so on.

I tried to find something in the manual but couldn't. Can you help? I suppose I have to use a seperate loading script and somehow check those values?

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

Re: Load specific scenes based on relationships

Post by Tony Li »

Hi,

If you write a script, you can check affinity values. Example:

Code: Select all

isTomPositive = FactionManager.instance.GetAffinity("Tom", "Player") > 0;
isHorstPositive = FactionManager.instance.GetAffinity("Horst", "Player") > 0;
if (isTomPositive && isHorstPositive)
{
    PixelCrushers.SaveSystem.LoadScene("scene 1");
}
else if (isTomPositive && !isHorstPositive)
{
    PixelCrushers.SaveSystem.LoadScene("scene 2");
}
etc.
If you don't want to write a script, you could use multiple Dialogue System Triggers. Configure the first trigger's Conditions > Lua Conditions to check:

Code: Select all

GetAffinity("Tom", "Player") > 0 and GetAffinity("Horst", "Player") > 0
and Actions > Play Sequence to run:

Code: Select all

LoadLevel(scene 1)
Configure the second trigger to check if Tom is positive but Horst isn't, etc.
TomsTales
Posts: 16
Joined: Tue Apr 27, 2021 6:38 am

Re: Load specific scenes based on relationships

Post by TomsTales »

Sorry, not sure where I am wrong. I have added a script (load scene) to a random object in the scene. After talking to Drunken Man, the Relationship to DrunkenMan on player increases to +50.

Then I have a Trigger on the object with the load scene script object and when walking into this, the level should change.

I am not sure where I get the isTomPositive from. I understand that is you basically teaching me how to code this entirely so please do not feel you need to, it's way beyond usual support and I am aware of this :)

Code: Select all

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using PixelCrushers.LoveHate;

public class LoadScene : MonoBehaviour
{
    public void OnTriggerEnter2D(Collider2D col)

    {
        isDrunkenManPositive = FactionManager.instance.GetAffinity("DrunkenMan", "Player") > 0;
        if (isDrunkenManPositive)
        {
            SceneManager.LoadScene("02_Level");
        }
    }
}
Of course this also just throws an error that isDrunkenManPositive is not available in this context.
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: Load specific scenes based on relationships

Post by Tony Li »

Hi,

Put a "bool" in front of isDrunkenManPositive to indicate that you're declaring a Boolean variable:

Code: Select all

bool isDrunkenManPositive = FactionManager.instance.GetAffinity("DrunkenMan", "Player") > 0;

You may also want to only allow GameObjects that are tagged "Player" to activate the trigger:
[code]public void OnTriggerEnter2D(Collider2D col)
{
    if (col.CompareTag("Player"))
    {
        bool isDrunkenManPositive = FactionManager.instance.GetAffinity("DrunkenMan", "Player") > 0;
        if (isDrunkenManPositive)
        {
            SceneManager.LoadScene("02_Level");
        }
    }
}
TomsTales
Posts: 16
Joined: Tue Apr 27, 2021 6:38 am

Re: Load specific scenes based on relationships

Post by TomsTales »

Argh. It just was that I checked the Relationship on the NPC, which was 0, and not on the Player :o

So changing

("DrunkenMan", "Player") > 0;

to

("Player", "DrunkenMan") > 0;

did the trick. God Damn it :lol:
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: Load specific scenes based on relationships

Post by Tony Li »

Glad you found the issue! :-)
Post Reply