Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion MiscUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ namespace MiscUtil {
for (UInt32 idx = 0, n = 0; idx < count; idx++) {
TESObjectREFR* ObjRef = GetCellObj(Cell, idx);

if (ObjRef == NULL || ObjRef->baseForm->formType != FindType) continue; // Invalid
if (ObjRef == NULL || ObjRef->baseForm == NULL || ObjRef->baseForm->formType != FindType) continue; // Invalid
else if (SearchRadius > 0.0f && !IsWithinRadius(CenterObj, ObjRef, SearchRadius)) continue; // Outside search radius
else if (FindKeyword && !HasKeyword(ObjRef, FindKeyword)) continue; // Missing keyword
else output.push_back(ObjRef); // MATCH
Expand Down
26 changes: 26 additions & 0 deletions Scripts/Source/MiscUtil.psc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,32 @@ scriptname MiscUtil Hidden
; NOTE: Keyword searches seem a little unpredictable so be sure to test if your usage of it works before using the results.
ObjectReference[] function ScanCellObjects(int formType, ObjectReference CenterOn, float radius = 0.0, Keyword HasKeyword = none) global native

ObjectReference[] function ScanCellObjectsOfAnyTypeInList(FormList arBaseObjects, ObjectReference arCenterOn, float afRadius = 1000.0)
ObjectReference[] Output
if !arBaseObjects || arBaseObjects.GetSize() < 1
return Output ; Invalid args
endIf
return ScanCellObjectsOfAnyTypeInArray(arBaseObjects.ToArray(), arCenterOn, afRadius)
endFunction

ObjectReference[] function ScanCellObjectsOfAnyTypeInArray(Form[] arBaseObjects, ObjectReference arCenterOn, float afRadius = 1000.0)
ObjectReference[] Output
Form[] TempBaseObjects = PapyrusUtil.RemoveForm(arBaseObjects, none)
if !TempBaseObjects || TempBaseObjects.Length < 1 || !arCenterOn || arCenterOn == none || afRadius < 1.0
return Output ; Invalid args
endIf
Cell akTargetCell = arCenterOn.GetParentCell()
int iRef = akTargetCell.getNumRefs()
ObjectReference TempRef
while iRef
iRef -= 1
TempRef = akTargetCell.getNthRef(iRef)
if TempRef && TempRef != arCenterOn && TempRef.GetBaseObject() && TempBaseObjects.Find(TempRef.GetBaseObject()) >= 0 && TempRef.GetDistance(arCenterOn) <= afRadius
Output = PapyrusUtil.PushObjRef(Output, TempRef)
endIf
endWhile
return Output
endFunction

; Scans the current cell of the given CenterOn for an actor within the given radius and returns an array for all actors that are
; currently alive and (optionally) has the given keyword if changed from default none. Setting radius higher than 0.0 will restrict the
Expand Down