FindClosestReferenceOfTypeFromRef - Game

From the CreationKit Wiki
Revision as of 19:24, 29 June 2013 by imported>Thingy Person (→‎Syntax)
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

ObjectReference Function FindClosestReferenceOfTypeFromRef(Form arBaseObject, ObjectReference arCenter, float afRadius) global
	return FindClosestReferenceOfType(arBaseObject, arCenter.X, arCenter.Y, arCenter.Z, afRadius)
endFunction

Parameters

  • 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

The closest reference found, none if none.

Examples

; 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

  • 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