Difference between revisions of "FindRandomReferenceOfAnyTypeInListFromRef - Game"
Jump to navigation
Jump to search
imported>Jlundin |
imported>Tox2ik |
||
Line 21: | Line 21: | ||
== Examples == | == Examples == | ||
<source lang="papyrus"> | <source lang="papyrus"> | ||
; | import debug | ||
ObjectReference | FormList property AllEnchantedArmors auto ; roughly 1500 entries | ||
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 | |||
</source> | </source> | ||
Revision as of 08:00, 25 January 2013
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
ObjectReference Function FindRandomReferenceOfAnyTypeInListFromRef(FormList arBaseObjectsA, ObjectReference arCenter, \
float afRadius) global
Parameters
- 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
Return Value
A random reference of of any of the types within the radius or the center reference, none if none was found.
Examples
import debug
FormList property AllEnchantedArmors auto ; roughly 1500 entries
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