Jump to content

How to get speaker's name for text replacement in Player Dialogue Topics in Creation Kit?


Recommended Posts

Posted

Is there a way to insert the speaker's name into the "Topic Text" for player dialogue?

 

For example, currently the player says something like "Hello, do you want to trade?" but I'm hoping there is a way to use text replacement or aliases to have it say "Hello <Speaker Name>, do you want to trade?

 

This is for a player dialogue generic quest that could be used with various different followers or NPCs and not specifically tied to a "quest" quest or scene.

 

Could this be solved with a papyrus code fragment attached to the quest under the "quest stages" tab? (though I haven't tried to make a quest with any stages which seem required for papyrus fragments)

 

Thanks!

 

 

Posted (edited)

A bit rusty on this since it's been a while, but I do recall having to create a workaround for this:

Actor Function GetPlayerDialogueTarget(Actor player) Global
    {Unlike GetDialogueTarget, this method works on the player.}
    
    Actor temp
    Cell c = player.GetParentCell()
    int knpc = 43 ; kNPC
    int i = c.GetNumRefs(knpc)
    
    While (i > 0)
        i -= 1
        temp = c.GetNthref(i, knpc) As Actor
        
        If (temp != none && temp != player && temp.IsInDialogueWithPlayer())
            Return temp
        EndIf
    EndWhile
    
    Return none
EndFunction

 

Not sure if I ever tested it. Probably would need to be careful with performance as well. As for getting that into a text replacement... run GetPlayerDialogueTarget on start topic. Shove that target into an alias and do <Alias.Name=some_alias_name> and hope there's no race condition here? Like I said, rusty.

Edited by traison
Posted

Thank you for the response. I'm trying to implement your function but there's quite a bit about Papyrus/Creation Kit I don't understand which is making it more difficult than it should be.

 

I added this function to a new script under the "Script" tab of the Quest.

 

Quote

As for getting that into a text replacement... run GetPlayerDialogueTarget on start topic. Shove that target into an alias and do <Alias.Name=some_alias_name> and hope there's no race condition here? Like I said, rusty.

 

If I call the function in a start topic, is that just the first topic in the Player Dialogue tab? So will any scripts here run and then provide results for following topics? And it can't be in a fragment, right? Because fragments are already functions and the compiler reports an error when attempting to import the new script that has the GetPlayerDialogueTarger function defined in it. Sorry I'm confused on the steps how to include this function into the quest!

 

The mod Submissive Lola does something like this with aliases in the topic text to insert the Master/Mistress's name (it's so great when mod authors provide their source code!). I think what that mod does is run a script associated with the quest which updates a global which is then assigned to an alias. That seems like a lot of work (and beyond my ability) but maybe it's the cleanest solution?

 

 

 

Posted
7 hours ago, invisible_rodent said:

If I call the function in a start topic, is that just the first topic in the Player Dialogue tab?

 

Starting topic is defined by branch, so... sometimes?

 

7 hours ago, invisible_rodent said:

So will any scripts here run and then provide results for following topics?

 

Depends on how you implement it. If you put the output in a quest alias like I suggested, you just need to make sure its called before it is used.

 

7 hours ago, invisible_rodent said:

And it can't be in a fragment, right? Because fragments are already functions and the compiler reports an error when attempting to import the new script that has the GetPlayerDialogueTarger function defined in it.

 

Define it in a quest or global script (like I did) and call it from a fragment. It's a global function, so you'll have to change that depending on where you define it.

 

7 hours ago, invisible_rodent said:

I think what that mod does is run a script associated with the quest which updates a global

 

GlobalVariables can not contain actors.

Posted (edited)

Couldn't get this to work reliably. It's unclear when the game loads dialogue branches and to get the function to run it must be called in a fragment attached to a preceding topic info in the same branch as it will be used. So this makes it impossible to have something like "Hey <Follower Name>,..." as a top-level dialogue branch because there's no chance to run the fragment and fill the alias first.

 

Also, since the alias is assigned in a topic info, then one might as well use akSpeaker (see below) to fill the alias, instead of using the InDialogueWithPlayer loop which has a questionable performance penalty (see this thread).

 

I got this to work in a topic info fragment:

 

Follower_alias.Clear() ; required to clear whatever was put in the alias when the quest started or the last conversation.
Follower_alias.ForceRefTo(akspeaker)

 

Then in the next topic, was able to use text replacement to call the alias in the topic text field.

 

Anyway, an educational foray into the use of quest aliases.

Edited by invisible_rodent

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...