tostikaas Posted January 26, 2014 Share Posted January 26, 2014 I would like to be able to run a script using the reference of the NPC the player is currently in dialog with. I couldn't find a proper function to retrieve this ref. GetActionRef came close but I don't think it's made for a situation like this. Is there maybe a workaround to detect this ref without tinkering with NPC scripts or dialog? I want to be able to retrieve refs of all NPC's in the game, both vanilla and modded, just by interacting with them. Link to comment Share on other sites More sharing options...
jazzisparis Posted January 26, 2014 Share Posted January 26, 2014 Unfortunately, as far as I know, there is no function that would enable you to retrieve the dialogue's target reference directly. There is, however, a workaround. It requires NVSE version 3 (or newer). 1. Create a new Quest, tick Start Game Enabled and set the Processing Delay to 1.0 2. Create a new Script, set Script Type to Quest, and use the following code: scn DialogueTargetScript short bScan ref rActor ref rTarget begin MenuMode 1009 if bScan == 0 set bScan to 1 set rActor to GetFirstRef 200 2 0 Label 1 if IsFormValid rActor if rActor.GetDialogueTarget == player set rTarget to rActor ; Found the dialogue target (now stored in rTarget). ; Do something. Return endif set rActor to TeddyBear01 set rActor to GetNextRef GoTo 1 endif endif end begin GameMode if bScan set bScan to 0 set rTarget to 0 endif end 3. Return to the Quest from step 1 and select this script from the Script dropbox. This script runs continuously and retrieves the dialogue target's reference, every time you start a conversation with an NPC. If you've never worked with NVSE scripts, note that it requires that you launch the GECK via nvse_loader.exe, as described here (2nd paragraph under Installation). Link to comment Share on other sites More sharing options...
tostikaas Posted January 26, 2014 Author Share Posted January 26, 2014 (edited) Wow thanks for the quick reply. Actually I also found a similar solution. I figured I could use the GetCrosshairRef function, since the player's crosshair is always focused on the NPC when you exit dialog. MyQuestScript short Dialog Begin GameMode If Player.GetItemCount MyItem < 1 Player.AddItem MyItem 1 Endif End Begin MenuMode 1009 If Dialog != 1 Set Dialog to 1 Endif End MyItemScript ref CurrentRef Begin GameMode If MyQuest.Dialog == 1 Set CurrentRef to GetCrosshairRef MessageBoxEx "You just talked to: %n" CurrentRef Set MyQuest.Dialog to 0 Endif End I tested it and it works. Let's hope it holds up. For instance I'm a bit worried what might happen with talking activators... Thanks again jazzisparis, I will also give GetFirstRef and GetNextRef a try. Edited January 26, 2014 by tostikaas Link to comment Share on other sites More sharing options...
jazzisparis Posted January 26, 2014 Share Posted January 26, 2014 I figured I could use the GetCrosshairRef function, since the player's crosshair is always focused on the NPC when you exit dialog.Indeed, that is also an option, though considerably less reliable in my opinion. The script I gave you detects the reference immediately when dialogue begins, regardless of where the target NPC/activator is positioned. Also, player.GetCombatTarget is preferable to GetCrosshairRef, since it has a much greater range (and does not rely on NVSE). Link to comment Share on other sites More sharing options...
tostikaas Posted January 26, 2014 Author Share Posted January 26, 2014 (edited) Ah, I went with GetCrosshairRef because it seemed easier on the engine (no goto loops) but what you say makes sense so even if this is true it'll be a small price to pay for reliability. I had no idea GetDialogueTarget existed by the way, very nice. So in case I want to run the script when either the player or the NPC initiates the conversation, should I use something like: if rActor.GetDialogueTarget == player || rActor.GetDialogueSubject == player Anyways, I think I can figure it out from here. Nogmaals bedankt he :wink: Edited January 26, 2014 by tostikaas Link to comment Share on other sites More sharing options...
jazzisparis Posted January 26, 2014 Share Posted January 26, 2014 Ah, I went with GetCrosshairRef because it seemed easier on the engine (no goto loops) but what you say makes sense so even if this is true it'll be a small price to pay for reliability.Actually, that loop only runs once, for a single frame, and only when you start dialogue, therefore it has zero effect on performance. However, if you find that the GetCrosshairRef (or GetCombatTarget) method works well, then by all means - use it. I had no idea GetDialogueTarget existed by the way, very nice. So in case I want to run the script when either the player or the NPC initiates the conversation, should I use something like: if rActor.GetDialogueTarget == player || rActor.GetDialogueSubject == playerrActor.GetDialogueSubject returns rActor, and is therefore useless. I don't know on which cases (if any) this function can be of use. Nogmaals bedankt he :wink:Graag gedaan. ;) Link to comment Share on other sites More sharing options...
Recommended Posts