Individual Reputation

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
timbecile
Posts: 110
Joined: Mon Mar 12, 2018 11:00 pm

Individual Reputation

Post by timbecile »

Hey Tony,

I'm trying to implement a reputation score that's individualized per NPC, but I'm not sure exactly how to have Dialogue Manager check for it. I could put the variable on a script on the NPC, but how do I send the game object of the conversant over script?

Unless there's a way to have individual variables on each conversation? that might be easier.
User avatar
Tony Li
Posts: 21061
Joined: Thu Jul 18, 2013 1:27 pm

Re: Individual Reputation

Post by Tony Li »

Hi,

The Dialogue System has a simple relationship system. (See: Relationship Lua Functions) Relationship values are included in saved games.

Let's say you have an NPC named Bob. So your dialogue database has actors named Player and Bob. Use the relationship functions to set Bob's relationship to the player. Examples:
  • Dialogue Text [Bob]: "Thanks for the help! You're a good person."
  • Script: IncRelationship(Actor["Bob"], Actor["Player"], "Reputation", 15); -- Increase rep with Bob by +15
and
  • Dialogue Text [Ann]: "Hi! Bob mentioned what a nice person you are."
  • Conditions: GetRelationship(Actor["Bob"], Actor["Player"], "Reputation") >= 10
The third parameter is the relationship type. It's an arbitrary string of your choosing.

If you're writing a conversation that can be reused by multiple NPCs, you can use Variable["ConversantIndex"] to refer to the conversant (NPC). Example:
  • Dialogue Text: "Thanks for the help! You're a good person."
  • Script: IncRelationship(Actor[Variable["ConversantIndex"]], Actor["Player"], "Reputation", 15);
This will increase reputation with the current conversant by +15.

If you don't want to use the Dialogue System's built-in relationship system, you can write your own in C# and register your C# methods with Lua so you can use them in your conversations' Conditions and Script fields.
timbecile
Posts: 110
Joined: Mon Mar 12, 2018 11:00 pm

Re: Individual Reputation

Post by timbecile »

This looks perfect! Can I get/set these values in script outside of dialogue manager also?
User avatar
Tony Li
Posts: 21061
Joined: Thu Jul 18, 2013 1:27 pm

Re: Individual Reputation

Post by Tony Li »

timbecile wrote: Fri Sep 09, 2022 4:20 pmThis looks perfect! Can I get/set these values in script outside of dialogue manager also?
Yes. You can use Lua.Run() to run the Lua function:

Code: Select all

Lua.Run("IncRelationship(Actor['Bob'], Actor['Player'], 'Reputation', 15)");
or you can use DialogueLua.Get/Set/Inc/DecRelationship(). It's a little awkward because you must pass the Lua actors:

Code: Select all

Language.Lua.LuaTable bob = Lua.Run("return Actor['Bob']").luaValue as Language.Lua.LuaTable;
Language.Lua.LuaTable player = Lua.Run("return Actor['Player']").luaValue as Language.Lua.LuaTable;
DialogueLua.IncRelationship(bob, player, "Reputation", 15);
timbecile
Posts: 110
Joined: Mon Mar 12, 2018 11:00 pm

Re: Individual Reputation

Post by timbecile »

how do I use lua.run to get the actual value? I was only getting back a lua-result
User avatar
Tony Li
Posts: 21061
Joined: Thu Jul 18, 2013 1:27 pm

Re: Individual Reputation

Post by Tony Li »

Sorry, I forgot to mention that. Use ".asFloat" at the end (or .asInt, .asString, .asBool, or .asTable for other types).

Code: Select all

float rep = Lua.Run("return GetRelationship(Actor['Bob'], Actor['Player'], 'Reputation')").asFloat;
Post Reply