Handling Relationships with different NPC's
-
- Posts: 10
- Joined: Mon May 16, 2022 5:49 am
Handling Relationships with different NPC's
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!
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!
Re: Handling Relationships with different NPC's
Hi,
You can use Lua.Run() to evaluate Lua functions in C#:
The DialogueLua class gives you direct C# access to a lot of Lua functionality, such as DialogueLua.GetVariable():
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:
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.
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;
Code: Select all
float value = DialogueLua.GetVariable("Some Variable").asFloat;
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.
-
- Posts: 10
- Joined: Mon May 16, 2022 5:49 am
Re: Handling Relationships with different NPC's
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?
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?
Re: Handling Relationships with different NPC's
I recommend one of two approaches:
1. Specify the relationship in the wrapper functions:
and use them like this:
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:
and use them like this:
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....
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....
Code: Select all
IncFriendship("Some NPC", 50);
-
- Posts: 10
- Joined: Mon May 16, 2022 5:49 am
Re: Handling Relationships with different NPC's
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!
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.
Re: Handling Relationships with different NPC's
Sorry about that. I just fixed those typos above in case someone else needs to refer to this answer in the future.
-
- Posts: 10
- Joined: Mon May 16, 2022 5:49 am
Re: Handling Relationships with different NPC's
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?
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?
Re: Handling Relationships with different NPC's
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:
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);