Jump to content

Find Nearest Object And Move To Script Help


Recommended Posts

So im trying to make a script that programs a npc to actively search for nearby object and go to them.

 

My problem is when using the command Player.translatetoref, when specifying the location I want the npc to move to I need it to automatically use the object that the npc has found that is closest to it.

 

So player.translatetoref( The location is automaticly retrieved,100)

 

 

Link to comment
Share on other sites

You could use FindClosestReferenceOfTypeFromRef() for this. But using TranslateToRef will have your NPC floating to the target reference, not walking. You might need to use packages for this.

 

Just for the sake of the example, with TranslateToRef, you could do something like this:

Function MoveMyNPC()
	ObjectReference ClosestObj = Game.FindClosestReferenceOfTypeFromRef(ObjToSearch, Game.GetPlayer(), 1500.0)

	If ClosestObj != none
		Debug.Notification("Object found and starting movement...")
		MyNPC.TranslateToRef(ClosestObj, 90.0)
	Else
		Debug.Notification("Nothing Found")
	EndIf
EndFunction

FindClosestReferenceOfTypeFromRef looks for BaseID's or for a FormList with BaseID's inside.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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