In Skyrim is it possible to use the console to target the nearest hostile npc

//ads -- adsterra.com -- native banner
?>
Just clicking on the nearest npc won't fit my needs unfortunately. I would like to be able to use it in a script that finds my closest enemy and tells me the distance to them. I am hoping to be able to target the GetPos command on both the player and the nearest npc, determine the difference and output the answer. If anyone knows how to do this or can point me in the right direction for a tutorial that would be great. Thanks.
Pictures about "In Skyrim is it possible to use the console to target the nearest hostile npc"



How do I target NPC in Skyrim console?
To target an object, open the console and click the object. Its name will appear about center screen. An item targeted in the console is also called a reference. A target may also be selected using the PRID command and the target's Reference ID.How do you calm a hostile NPC in Skyrim?
EDIT: To stop random NPC's attacking you, just turn off Ai detection with ' tdetect ' and then click on the NPC and type ' setav aggression 0 '. while detection is off, they should not be able to find you and continue to go about their business. If you need to, try ' resetai '.How do you stop an NPC from being hostile?
Several more Celestial Dew are hidden within Eternal City, an area the Tarnished will likely reach later in the game. Once players have Celestial Dew, they can head to the Church of Vows and interact with the statue on the altar to atone for their sins. This will remove any NPC hostility.How do you control NPCs in Skyrim?
Toggle Player Control Turns on and off control of an NPC. To use, target an NPC and type the command. The NPC will now be controlled, and player will have command of both their character and the NPC simultaneously.[Skyrim Special Edition] Debug Menu (Xbox): NPC targeting system functional
Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.
Images: Ketut Subiyanto, Ketut Subiyanto, Kampus Production, Eren Li