Jump to content

Check settler's role via script?


Recommended Posts

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

 

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().

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • 3 years later...

 

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

 

I'm trying to use this script, however, unassigned settlers are flagged as provisioners, I also tried using CaravanActorAliases col ref, same results
I can't find a way to identify why these unassigned settlers are in the CaravanAactors col ref

Could it be that these settlers have been moved from another settlement, so they were added to the CaravanActors ref col?

Edited by lukandroll
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...