FindRandomReferenceOfAnyTypeInListFromRef - Game

From the CreationKit Wiki
Jump to navigation Jump to search

Member of: Game Script

Finds a random reference of any of the types in the list from the given reference location and within the given radius.

Syntax[edit | edit source]

ObjectReference Function FindRandomReferenceOfAnyTypeInListFromRef(FormList arBaseObjects, ObjectReference arCenter, float afRadius) global

Parameters[edit | edit source]

  • arBaseObjectsA: The list of valid base objects to look for
  • arCenter: The reference to use as a center of the search.
  • afRadius: Maximum distance from center to look for a reference. The unit of this parameter is comparatively much shorter than the radius of a cloak spell or the feet parameter given to "target actor" and "target location" spells. Try starting with a value of 400.

Return Value[edit | edit source]

A random reference of of any of the types within the radius or the center reference, none if none was found.

Examples[edit | edit source]

import debug
FormList property lookForItems auto       ; roughly 1500 entries (all enchanted armors)
float 	distance	= 2560.0          ; slightly longer than the carpet in The Great Porch of Dragonsreach
int 	len		= lookForItems.getSize()
bool	looking		= true

ObjectReference item
ObjectReference p = game.getPlayer() as ObjectReference

while i < len && looking
	item = Game.FindRandomReferenceOfAnyTypeInListFromRef(lookForItems, p, distance)
	if item
		looking = false
	endif
	if i % 60 == 0
		trace(" iteration: " + i + " / " + len)
	endif
i += 1
endWhile


if item 
	item.moveto(p)
	trace("got item: " + item)
else
	trace("no items found. list: " +lookForItems+ ", list entries: " + len)
endif

This example will look any enchanted armor that the lookForItems FormList has been filled with (in the CK). While the search distance and the length of the form list look ominously big, this example should find an item within a second if the player is within the specified distance of a qualifying item. The reason for iterating so many times is not really well founded, but it follows the example in critterBird.psc.

See Also[edit | edit source]