Skip to content

Instantly share code, notes, and snippets.

@fireundubh
Last active May 24, 2016 05:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fireundubh/915dff2face49caf394c3593ea534e60 to your computer and use it in GitHub Desktop.
Save fireundubh/915dff2face49caf394c3593ea534e60 to your computer and use it in GitHub Desktop.
Faction Property WorkshopNPCFaction Auto
; prepare:
; 1. create keyword: ActorTypeSettler
; 2. create keyword: ActorTypeSettlerIgnored
; 3. attach ActorTypeSettler keyword to every WorkshopNPCFaction NPC
Keyword Property pActorTypeSettler Auto
Keyword Property pActorTypeSettlerIgnored Auto
Float Property pFindAllRadius Auto
Location Property pSettlementLocation Auto
Function DoStuff()
ObjectReference[] kSettlers = BuildArray(pActorTypeSettler, pFindAllRadius)
Int i = 0
Bool bBreak = False
While (i < kSettlers.Length) && !bBreak
If ; something undesirable occurs
bBreak = True
EndIf
If !bBreak
ObjectReference kSettler = kSettlers[i] as ObjectReference
; do stuff with kSettler
kSettler.RemoveKeyword(pActorTypeSettler)
kSettler.AddKeyword(pActorTypeSettlerIgnored)
EndIf
EndWhile
EndFunction
ObjectReference[] Function BuildArray(Keyword akKeyword, Float afRadius)
ObjectReference[] kResult = new ObjectReference[0]
kResult = Player.FindAllReferencesWithKeyword(akKeyword, afRadius)
kResult = FilterArray(kResult)
Return kResult
EndFunction
ObjectReference[] Function FilterArray(ObjectReference[] akArray)
ObjectReference[] kResult = new ObjectReference[0]
If (akArray as Bool) && (akArray != None)
; Note: FindAllReferences*() builds an array of references starting with the outermost references.
; So, we invert that array so our script affects objects in nearest-to-farthest order.
Int i = akArray.Length - 1
While i >= 0
ObjectReference kObject = akArray[i]
; add actor to filtered array if conditions are met
If kObject != None
If CheckIfObjectCanBeProcessed(kItem)
Actor kActor = kObject as Actor
; condition: actor exists
If (kActor != None) && (kActor != Player)
; condition: actor is alive
If !kActor.IsDead()
; condition: actor is in settler faction (defaults to -1)
If kActor.IsInFaction(WorkshopNPCFaction)
; condition: actor has joined settler faction
If kActor.GetFactionRank(WorkshopNPCFaction) > -1
; condition: actor is in the settlement location
If kActor.IsInLocation(pSettlementLocation)
; add actor object to ObjectReference[] array
kResult.Add(kObject, 1)
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
i -= 1
EndWhile
EndIf
Return kResult
EndFunction
; Return true if all conditions are met
Bool Function CheckIfObjectCanBeProcessed(ObjectReference akObject)
Return akObject.Is3DLoaded() && !akObject.IsDisabled() && !akObject.IsDeleted() && !akObject.IsDestroyed() && !akObject.IsActivationBlocked()
EndFunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment