SKSE Plugin Development/Iterating all Actors/NPCs

From the CreationKit Wiki
Revision as of 17:25, 10 December 2024 by Xieve (talk | contribs) (Created page with "Also known as Cloak Scanning. <syntaxhighlight lang="css"> const auto processLists = RE::ProcessLists::GetSingleton(); if (!processLists) { return; } const auto *ActorTypeNP...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Also known as Cloak Scanning.

const auto processLists = RE::ProcessLists::GetSingleton();
if (!processLists) { return; }

const auto *ActorTypeNPC = RE::TESForm::LookupByEditorID<RE::BGSKeyword>("ActorTypeNPC");

for (auto &targetHandle: processLists->highActorHandles) {
   const auto actorPtr = targetHandle.get();
   if (!actorPtr) { continue; }

   // Check if actor is NPC (leave out if you want all actors)
   const auto base = actorPtr->GetActorBase();
   if (base && !base->GetRace()->HasKeyword(ActorTypeNPC)) {
       continue;
   }

   // Your code here
}