Jump to content

Find Closest Object


Ikedude

Recommended Posts

Is there an easy way to find the closest object of any type? I found these:

 

http://www.creationkit.com/FindClosestReferenceOfAnyTypeInList_-_Game

 

http://www.creationkit.com/FindClosestReferenceOfType_-_Game

 

but I just want the closest object of any type. I guess I could fill in the FormList with a limited set, but I feel like there has to be a better way.

 

Thanks

Link to comment
Share on other sites

The problem with *the* closest object is that it will likely be a light or fx or a static of some kind, and I doubt you really want to mess with that. Here's some sample code of what you can do:

 

FormList Property OwnerList  Auto  

...

	Actor player = Game.GetPlayer()

	ObjectReference p = Game.FindClosestReferenceOfAnyTypeInListFromRef(OwnerList, player, 2048)
	if (p != none)
		if (p.GetActorOwner() != player.GetActorBase())
			p.SetActorOwner(player.GetActorBase())
		endif
	endif

Link to comment
Share on other sites

For my usage it will be in reference to another object, not the player, so hopefully it will return the object I actually want. To check if it is something I want to mess with I'm planning on using GetMass, if it returns zero then I'll leave it alone.

 

It might actually be more useful to get a FormList of all objects within a specific radius, then I could iterate through them... no idea how to get that though, ha.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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