FindClosestReferenceOfTypeFromRef - Game

From the CreationKit Wiki
Revision as of 07:56, 13 January 2014 by imported>Chesko (Removed confusing return function from syntax, as other functions on this wiki do not follow that format.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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?
;======================================================================================;
;  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

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]