I have a mod out that lets you distribute armor and weapons to settlers by placing them in chests. Up next on the requested features list is the ability to distribute gear based on the settler's role (guard, provisioner, merchant, farmer, scavenger, unassigned, etc.) Is there a way to check their role? I know you can tell provisioners by checking one of the reference collection aliases in the WorkshopParent quest, but I don't think there are similar aliases for other assignments.

Check settler's role via script?
#1
Posted 10 August 2017 - 05:58 AM

#2
Posted 10 August 2017 - 06:46 AM

Well a poor man's way might be to do
ObjectReference[] ResourceObjects = workshopRef.GetWorkshopOwnedObjects(theActor)
Then loop the array and check each assigned object for keywords to determine the type. You can grab the workshop ID the actor belongs to with
(theActor as WorkshopNPCScript).GetWorkshopID()
Then just grab the workshopRef with that.
Edited by BigAndFlabby, 10 August 2017 - 06:48 AM.
#3
Posted 10 August 2017 - 07:04 AM

Thanks! I'm using WorkshopParent.GetWorkshopFromLocation to get the armory container's parent workshop, then WorkshopParent.GetWorkshopActors to get the settlers, so I think I have everything I need to pass to GetWorkshopOwnedObjects.
#4
Posted 10 August 2017 - 07:49 AM

An alternative way is to use condition function HasVMscript and GetVMscriptVariable for alias collections. So for example if we have 4 kinds of workers we make 4 refcollections and set conditions for each collection depending on the kind of work . Then choose workshopnpcscript and a variable. I can`t remember now how to set it for farmers, but I think you can do it by excluding scavengers, guards, caravaners and unemployed. Then in some moment you start the quest and all groups of settlers in the settlement get into proper collections. Then you can do with them anything you want using alias script, quest script etc.
Edited by kitcat81, 10 August 2017 - 07:50 AM.
#5
Posted 10 August 2017 - 08:52 AM

Thanks! I'm using WorkshopParent.GetWorkshopFromLocation to get the armory container's parent workshop, then WorkshopParent.GetWorkshopActors to get the settlers, so I think I have everything I need to pass to GetWorkshopOwnedObjects.
GetWorkshopFromLocation is unreliable, as certain locations in certain settlements won't return a workshop index (such as Somerville Place and I've heard Red Rocket Truck Stop). If you already have the reference of a workshop object, then you can just use GetLinkedRef() through the WorkshopItemKeyword to get the workshop reference.
#6
Posted 10 August 2017 - 08:56 AM

Thanks! I'm using WorkshopParent.GetWorkshopFromLocation to get the armory container's parent workshop, then WorkshopParent.GetWorkshopActors to get the settlers, so I think I have everything I need to pass to GetWorkshopOwnedObjects.
GetWorkshopFromLocation is unreliable, as certain locations in certain settlements won't return a workshop index (such as Somerville Place and I've heard Red Rocket Truck Stop). If you already have the reference of a workshop object, then you can just use GetLinkedRef() through the WorkshopItemKeyword to get the workshop reference.
You can also just use GetActorRefOwner().
#7
Posted 10 August 2017 - 11:05 AM

The script "WorkshopNPCScript" seems to be undocumented, but it has some properties that you may find useful. I've taken this directly from the source:
bool bIsWorker: set to TRUE if this NPC is a worker of any kind
bool bIsGuard: set to TRUE if this NPC is a "guard"
bool bIsScavenger: set to TRUE if this NPC is a scavenger
ActorValue assignedMultiResource: if NONE this worker is assigned a single object to work on. Otherwise, this is the rating keyword (food, safety, etc.) of the type of resource this NPC can work on.
Here's a code snippet I took from another mod (Settlement Management Software from matzman666), which shows how to use that last property:
;Property workshopparentscript Property WorkshopParent Auto Const mandatory ;Variable workshopdatascript#workshopratingkeyword[] ratings workshopnpcscript worker ratings = WorkshopParent.WorkshopRatings If (worker.assignedMultiResource == ratings[WorkshopParent.WorkshopRatingFood].resourceValue) ;he is a farmer EndIf
Edited by MaxShadow09, 10 August 2017 - 11:12 AM.
#8
Posted 10 August 2017 - 06:53 PM

Thanks MaxShadow09, that does look faster.
#9
Posted 15 August 2017 - 07:02 AM

Here's what I ended up coming up with, if anyone's interested. You need a combination of methods to catch all of the possibilities.
WorkshopParentScript Property WorkshopParent Auto RefCollectionAlias Property CaravanActors Auto int Function GetJobIndex(WorkshopNPCScript akNPC) ; 0 - unassigned ; 1 - guard ; 2 - scavenger ; 3 - provisioner ; 4 - farmer ; 5 - merchant (and phoropter tech? soda jerk? power cyclist?) If akNPC.bIsWorker If akNPC.bIsGuard return 1 ; 1 - Guard ElseIf akNPC.bIsScavenger return 2 ; 2 - Scavenger Else If akNPC.assignedMultiResource == WorkshopParent.WorkshopRatings[WorkshopParent.WorkshopRatingFood].resourceValue return 4 ; 4 - farmer Else return 5 ; 5 - merchant or other EndIf EndIf Else If CaravanActors.Find(akNPC) >= 0 return 3 ; 3 - provisioner Else return 0 ; 0 - unassigned EndIf EndIf EndFunction
#10
Posted 06 February 2021 - 06:32 PM

Here's what I ended up coming up with, if anyone's interested. You need a combination of methods to catch all of the possibilities.
WorkshopParentScript Property WorkshopParent Auto RefCollectionAlias Property CaravanActors Auto int Function GetJobIndex(WorkshopNPCScript akNPC) ; 0 - unassigned ; 1 - guard ; 2 - scavenger ; 3 - provisioner ; 4 - farmer ; 5 - merchant (and phoropter tech? soda jerk? power cyclist?) If akNPC.bIsWorker If akNPC.bIsGuard return 1 ; 1 - Guard ElseIf akNPC.bIsScavenger return 2 ; 2 - Scavenger Else If akNPC.assignedMultiResource == WorkshopParent.WorkshopRatings[WorkshopParent.WorkshopRatingFood].resourceValue return 4 ; 4 - farmer Else return 5 ; 5 - merchant or other EndIf EndIf Else If CaravanActors.Find(akNPC) >= 0 return 3 ; 3 - provisioner Else return 0 ; 0 - unassigned EndIf EndIf EndFunction
Could it be that these settlers have been moved from another settlement, so they were added to the CaravanActors ref col?
Edited by lukandroll, 06 February 2021 - 06:42 PM.
Also tagged with one or more of these keywords: assignment, settler, role, settlement, workshop
