FindClosestReferenceOfTypeFromRef - Game

Member of: Game Script

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

SyntaxEdit

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

ParametersEdit

  • 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 ValueEdit

The closest reference found, none if none.

ExamplesEdit

; 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?
;======================================================================================;
;  VARIABLES   /
;=============/
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!")
	else
		if( closestDoor.isLocked() )
			Debug.Notification("Opening door!")
			closestDoor.Lock(false)
		else
			Debug.Notification("The door is not locked!")
		endif	
	endif
EndEvent

NotesEdit

  • 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 AlsoEdit