Last Updated: February 25, 2016
·
4.96K
· xenplex

Get a List of all Object References of a specific Form Type in the current Cell with Papyrus

Following protip is for the Scripting language Papyrus, used to mod the game Skyrim.

Here is a small code example, on how to get a List of all Object References of a specific Form Type in the current Cell with Papyrus:

Cell kCell = Self.GetParentCell()
Int iIndex = kCell.GetNumRefs(formTypeToGet)
ObjectReference[] objectReferencesList = new ObjectReference[100]
while (iIndex)
    iIndex -= 1
    objectReferencesList[iIndex] = kCell.GetNthRef(iIndex, formTypeToGet)
endwhile

Needs SKSE to work

This is useful for example if you need to dynamically access all NPCs in a Cell, without hard-coding a list into Papyrus or Creation Kit.

Gist for this Code
Papyrus
SKSE