Difference between revisions of "Talk:GetDialogueTarget - Actor"
Jump to navigation
Jump to search
imported>Jbezorg |
imported>Jbezorg |
||
Line 57: | Line 57: | ||
== Alternative Method == | == Alternative Method == | ||
Same usage, slower, but in theory the examples above could miss the Dialogue target by testing the same NPC several times. Unlikely with a 200 unit radius but it also cannot test outside the 200 unit radius | Same usage, slower, but in theory the examples above could miss the Dialogue target by testing the same NPC several times. Unlikely with a 200 unit radius but it also cannot test outside the 200 unit radius and I've had arresting city guards enter dialogue with the player at a much greater distance. ~[[jbezorg]] | ||
<source lang="papyrus"> | <source lang="papyrus"> |
Revision as of 15:17, 11 February 2013
Obtains the actor the player is currently in dialogue with.
Syntax
Actor Function GetPlayerDialogueTarget() non-native
Source:
Actor Function GetPlayerDialogueTarget()
Actor kPlayerDialogueTarget
Actor kPlayerRef = Game.GetPlayer()
Int iLoopCount = 10
While iLoopCount > 0
iLoopCount -= 1
kPlayerDialogueTarget = Game.FindRandomActorFromRef(kPlayerRef , 200.0)
If kPlayerDialogueTarget != kPlayerRef && kPlayerDialogueTarget.IsInDialogueWithPlayer()
Return kPlayerDialogueTarget
EndIf
EndWhile
Return None
EndFunction
Parameters
None.
Return Value
The actor the player is currently in dialogue with (if any).
Examples
;This is a custom function so you have to include it in your script.
Actor Function GetPlayerDialogueTarget()
Actor kPlayerDialogueTarget
Actor kPlayerRef = Game.GetPlayer()
Int iLoopCount = 10
While iLoopCount > 0
iLoopCount -= 1
kPlayerDialogueTarget = Game.FindRandomActorFromRef(kPlayerRef , 200.0)
If kPlayerDialogueTarget != kPlayerRef && kPlayerDialogueTarget.IsInDialogueWithPlayer()
Return kPlayerDialogueTarget
EndIf
EndWhile
Return None
EndFunction
Event SomeEvent()
; Print a message if the player is in dialogue with Bob.
if (GetPlayerDialogueTarget() == Bob)
Debug.Trace("The player is in dialogue with Bob!")
endIf
EndEvent
Notes
This usually finds the actor the player is in dialogue with but more testing is required. It works very well for me, so far... I tend to modify this by passing in the player's reference and lowering iLoopCount but the version I posted is safe and convenient.
Alternative Method
Same usage, slower, but in theory the examples above could miss the Dialogue target by testing the same NPC several times. Unlikely with a 200 unit radius but it also cannot test outside the 200 unit radius and I've had arresting city guards enter dialogue with the player at a much greater distance. ~jbezorg
Actor Function GetPlayerDialogueTarget() global
Actor kPlayerRef = Game.GetPlayer()
Actor kTargetRef = None
Actor kNthRef = None
Cell kCell = kPlayerRef.GetParentCell()
Int iType = 43 ; kNPC = 43
Int iIndex = kCell.GetNumRefs( iType )
While iIndex && !kTargetRef
iIndex -= 1
kNthRef = kCell.GetNthRef( iIndex, iType ) as Actor
If kNthRef != kPlayerRef && kNthRef.IsInDialogueWithPlayer()
kTargetRef = kNthRef
EndIf
EndWhile
Return kTargetRef
EndFunction