Difference between revisions of "FindClosestActorFromRef - Game"

From the CreationKit Wiki
Jump to navigation Jump to search
imported>Imp of the Perverse
imported>Thingy Person
 
(4 intermediate revisions by 3 users not shown)
Line 8: Line 8:
<source lang="papyrus">
<source lang="papyrus">
Actor Function FindClosestActorFromRef(ObjectReference arCenter, float afRadius) global
Actor Function FindClosestActorFromRef(ObjectReference arCenter, float afRadius) global
return FindClosestActor(arCenter.X, arCenter.Y, arCenter.Z, afRadius)
endFunction
</source>
</source>


Line 20: Line 22:
<source lang="papyrus">
<source lang="papyrus">
; Find the closest actor to the player, limiting the search to 5 units
; Find the closest actor to the player, limiting the search to 5 units
Actor closest = Game.FindClosestActorFromRef(Game.GetPlayer(), 5.0)
Actor closest = Game.FindClosestActorFromRef(RefProperty, 5.0)
</source>
</source>
== Notes ==
* The player is an actor, so this function can return the player if they are the closest actor to arCenter.
* If an actor is used as the center of this search, that actor's reference will always be the one returned by this function, so it cannot be used to find the closest actor to another actor, including the player.


== See Also ==
== See Also ==

Latest revision as of 18:32, 29 June 2013

Member of: Game Script

Finds the closest actor within a given radius of a reference.

Syntax[edit | edit source]

Actor Function FindClosestActorFromRef(ObjectReference arCenter, float afRadius) global
	return FindClosestActor(arCenter.X, arCenter.Y, arCenter.Z, afRadius)
endFunction

Parameters[edit | edit source]

  • arCenter: The reference to search around
  • afRadius: Maximum distance from center to look for an actor

Return Value[edit | edit source]

The closest actor found, none if none. The reference provided for arCenter is not excluded from the search, limiting this function's usefulness somewhat. The example code, for example, would always return "player".

Examples[edit | edit source]

; Find the closest actor to the player, limiting the search to 5 units
Actor closest = Game.FindClosestActorFromRef(RefProperty, 5.0)

Notes[edit | edit source]

  • The player is an actor, so this function can return the player if they are the closest actor to arCenter.
  • If an actor is used as the center of this search, that actor's reference will always be the one returned by this function, so it cannot be used to find the closest actor to another actor, including the player.

See Also[edit | edit source]