FindClosestReferenceOfTypeFromRef - Game

From the CreationKit Wiki
Jump to navigation Jump to search

Member of: Game Script

Finds the closest reference of the given type from the location of the target reference and within the given radius.

Syntax[edit | edit source]

ObjectReference Function FindClosestReferenceOfTypeFromRef(Form arBaseObject, ObjectReference arCenter, float afRadius) global

Parameters[edit | edit source]

  • arBaseObject: The type of base object to look for
  • arCenter: Reference to use as a center to search from
  • afRadius: Maximum distance from center to look for a reference

Return Value[edit | edit source]

The closest reference found, none if none.

Examples[edit | edit source]

; Find the closest diamond reference to the player, limiting the search to 5 units
ObjectReference closestDiamond = Game.FindClosestReferenceOfTypeFromRef(Diamond, Game.GetPlayer(), 5.0)

scriptName OpenShackDoorScript extends ActiveMagicEffect
{Script for a Self Spell that opens the nearest Whiterun shack door}

import game
Door property WRShackDoor01 auto ; Switching to Door because Form properties are not auto-filled?
objectReference CastFromHereRef
ObjectReference closestDoor
float RadiusToFindDoor = 1000.0
;   EVENTS     /

Event OnEffectStart(Actor Target, Actor Caster)
	CastFromHereRef = Caster
	closestDoor  = Game.FindClosestReferenceOfTypeFromRef(WRShackDoor01, CastFromHereRef, RadiusToFindDoor )

	if ( closestDoor == None) 
		Debug.Notification("There is no shack door near!")
		if( closestDoor.isLocked() )
			Debug.Notification("Opening door!")
			Debug.Notification("The door is not locked!")

Notes[edit | edit source]

  • If the ObjectReference arCenter is of the same type as arBaseObject, this function will return arCenter. That is to say that this function does not exclude arCenter from it's search.

See Also[edit | edit source]