Handling Relationships with different NPC's

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
MeyOrMeyNot
Posts: 10
Joined: Mon May 16, 2022 5:49 am

Handling Relationships with different NPC's

Post by MeyOrMeyNot »

Hi,

I have a few questions about how to handle Relationships with the Dialogue System.
I've tried out [lua(GetRelationship(Actor["NPCName"], Actor["PlayerName"], "friendship"))] which works, I can Inc and Dec the relationship points for multiple relationships between the Player and different NPC's. Now I wanted to display the different relationships in a separate UI but I don't know how to achieve that. How could I use GetRelationship in a C# script to "store" it and display it in a seperate UI?
Or would It be more logical to use Custom Lua Functions, but for this I would have to make a new Variable for each NPC or am I thinking wrong?

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

Re: Handling Relationships with different NPC's

Post by Tony Li »

Hi,

You can use Lua.Run() to evaluate Lua functions in C#:

Code: Select all

float value = Lua.Run("GetRelationship(Actor['NPCName'], Actor['PlayerName'], 'friendship')").asFloat;
The DialogueLua class gives you direct C# access to a lot of Lua functionality, such as DialogueLua.GetVariable():

Code: Select all

float value = DialogueLua.GetVariable("Some Variable").asFloat;
But since GetRelationship() receives Lua objects (actors) as parameters it's unwieldy to use DialogueLua.GetRelationship().

In either case, you might find it cleaner to write a wrapper function:

Code: Select all

public float GetDSRelationship(string npcName, string playerName, string relationship)
{
    return Lua.Run($"GetRelationship(Actor['{npcName}'], Actor['{playerName}'], '{relationship}')").asFloat;
}

If you already have a license for Love/Hate, that's another option. However, if the Dialogue System's relationship functions are sufficient for your needs and you don't have Love/Hate, no need for the extra expense.
MeyOrMeyNot
Posts: 10
Joined: Mon May 16, 2022 5:49 am

Re: Handling Relationships with different NPC's

Post by MeyOrMeyNot »

Thank your for the quick answer! I think I try using a wrapper function.
Now I have another questions about that. when I make such a wrapper function do I make functions for each Relationship like this?

void relationshiptest()
{
GetDSRelationship("NPC1", "Player","friendship");
}
void relationshiptest2()
{
GetDSRelationship("NPC2", "Player","friendship");
}
...
And also how do I Inc and Dec the relationship with the wrapper function you showed?
User avatar
Tony Li
Posts: 21977
Joined: Thu Jul 18, 2013 1:27 pm

Re: Handling Relationships with different NPC's

Post by Tony Li »

I recommend one of two approaches:

1. Specify the relationship in the wrapper functions:

Code: Select all

public float GetDSRelationship(string npcName, string playerName, string relationship)
{
    return Lua.Run($"GetRelationship(Actor['{npcName}'], Actor['{playerName}'], '{relationship}')").asFloat;
}
public void IncDSRelationship(string npcName, string playerName, string relationship, float amount)
{
    Lua.Run($"IncRelationship(Actor['{npcName}'], Actor['{playerName}'], '{relationship}', {amount})");
}
//etc....
and use them like this:

Code: Select all

IncDSRelationship("Some NPC", "Player", "friendship", 50);

2. Or make separate wrapper functions for each relationship type. If the second actor is always the player, you could event omit the player parameter:

Code: Select all

public float GetFriendship(string npcName)
{
    return Lua.Run($"GetRelationship(Actor['{npcName}'], Actor['Player'], 'friendship')").asFloat;
}
public void IncFriendship(string npcName, float amount)
{
    Lua.Run($"IncRelationship(Actor['{npcName}'], Actor['Player'], 'friendship', {amount})");
}
public float GetLust(string npcName)
{
    return Lua.Run($"GetRelationship(Actor['{npcName}'], Actor['Player'], 'lust')").asFloat;
}
public void IncLust(string npcName, float amount)
{
    Lua.Run($"IncRelationship(Actor['{npcName}'], Actor['Player'], 'lust', {amount})");
}
//etc....
and use them like this:

Code: Select all

IncFriendship("Some NPC", 50);
MeyOrMeyNot
Posts: 10
Joined: Mon May 16, 2022 5:49 am

Re: Handling Relationships with different NPC's

Post by MeyOrMeyNot »

Thank you so much Tony!
It threw an Error in the Incfriendship because of the void and the return, i got rid of the return and it works!
Last edited by MeyOrMeyNot on Mon May 16, 2022 4:52 pm, edited 1 time in total.
User avatar
Tony Li
Posts: 21977
Joined: Thu Jul 18, 2013 1:27 pm

Re: Handling Relationships with different NPC's

Post by Tony Li »

Sorry about that. I just fixed those typos above in case someone else needs to refer to this answer in the future.
MeyOrMeyNot
Posts: 10
Joined: Mon May 16, 2022 5:49 am

Re: Handling Relationships with different NPC's

Post by MeyOrMeyNot »

Yes no problem, thank you for your super fast answers!!

Can I put IncFriendship("Some NPC", 50); inside a custom Lua function so I can call it in the conversation and change the amount more flexible in the conversation?

And if I have more NPC's can I simply use the wrapper and just change the IncFriendship("Some NPC", 50); to another NPC? Do I understand that right?
User avatar
Tony Li
Posts: 21977
Joined: Thu Jul 18, 2013 1:27 pm

Re: Handling Relationships with different NPC's

Post by Tony Li »

Yes to both questions. There is a C# -> Lua Tutorial that will show you how to make your C# wrapper functions available to Lua.

You can specify whatever NPCs you want. For example, say you've defined Actors named "Ann" and "Bob" in the Dialogue Editor. You can increment both like:

Code: Select all

IncFriendship("Ann", 50);
IncFriendship("Bob", 75);
Post Reply