Difference between revisions of "Talk:GetDialogueTarget - Actor"

1,388 bytes added ,  17:37, 27 February 2020
imported>Xander9009
imported>Haravikk
 
Line 157: Line 157:
*[[Bethesda Tutorial Dialogue]]
*[[Bethesda Tutorial Dialogue]]
*[[Bethesda Tutorial Advanced Dialogue]]
*[[Bethesda Tutorial Advanced Dialogue]]
== Additional Optimisations ==
I've found myself needing to grab the player's dialogue target recently, and I've found that the Game.[[GetCurrentCrosshairRef]]() function can usually get the dialogue target as long it triggers quickly enough. For example:
<source lang="papyrus">
Event OnInit()
    RegisterForMenu("Dialogue Menu")
EndEvent
Event OnMenuOpen(String asMenu)
    If asMenu == "Dialogue Menu" ; don't need this if this is the only menu we care about
        Actor akActor = Game.GetCurrentCrosshairRef() as Actor
        If !akActor.IsInDialogueWithPlayer()
            ; Perform a search with Game.FindRandomActorFromRef or search by Cell (see examples above)
        ; Else ; Got it one!
        EndIf
        If akActor != None ; Got it one, or search ended with a result
            ; Do something with akActor
        EndIf
    EndIf
EndEvent
</source>
It can be a bit hit and miss if the dialogue is already open, but it's generally pretty reliable, so the code won't usually need any of the extra checks.
Man I wish Bethesda had just added a function for this, or at the very least given us more useful search functions (ones that didn't include the search target in the result would have been nice, or one to grab several matches at once, e.g- the nearest 10 NPCs). Oh well! -- [[User:Haravikk|Haravikk]] ([[User talk:Haravikk|talk]]) 2020-02-27T17:37:41 (EST)
Anonymous user