Page 1 of 1
Load specific scenes based on relationships
Posted: Fri Aug 06, 2021 8:04 am
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!
Re: Load specific scenes based on relationships
Posted: Fri Aug 06, 2021 12:31 pm
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:
Configure the second trigger to check if Tom is positive but Horst isn't, etc.
Re: Load specific scenes based on relationships
Posted: Sat Aug 07, 2021 2:54 pm
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.
Re: Load specific scenes based on relationships
Posted: Sat Aug 07, 2021 3:26 pm
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");
}
}
}
Re: Load specific scenes based on relationships
Posted: Sun Aug 08, 2021 8:16 am
by TomsTales
Argh. It just was that I checked the Relationship on the NPC, which was 0, and not on the Player
So changing
("DrunkenMan", "Player") > 0;
to
("Player", "DrunkenMan") > 0;
did the trick. God Damn it
Re: Load specific scenes based on relationships
Posted: Sun Aug 08, 2021 8:50 am
by Tony Li
Glad you found the issue!