Jump to content

Photo

Check settler's role via script?

assignment settler role settlement workshop

  • Please log in to reply
9 replies to this topic

#1
BrendonLeCount

BrendonLeCount

    Faithful poster

  • Premium Member
  • 1,980 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.



#2
BigAndFlabby

BigAndFlabby

    Faithful poster

  • Premium Member
  • 1,890 posts

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
BrendonLeCount

BrendonLeCount

    Faithful poster

  • Premium Member
  • 1,980 posts

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
kitcat81

kitcat81

    Faithful poster

  • Supporter
  • PipPipPipPip
  • 1,193 posts

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
KernalsEgg

KernalsEgg

    Faithful poster

  • Premium Member
  • 1,151 posts

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
kitcat81

kitcat81

    Faithful poster

  • Supporter
  • PipPipPipPip
  • 1,193 posts

 

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
MaxShadow09

MaxShadow09

    Fan

  • Members
  • PipPipPip
  • 264 posts

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
BrendonLeCount

BrendonLeCount

    Faithful poster

  • Premium Member
  • 1,980 posts

Thanks MaxShadow09, that does look faster.



#9
BrendonLeCount

BrendonLeCount

    Faithful poster

  • Premium Member
  • 1,980 posts

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
lukandroll

lukandroll

    Newbie

  • Members
  • Pip
  • 16 posts

 

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, 06 February 2021 - 06:42 PM.






Also tagged with one or more of these keywords: assignment, settler, role, settlement, workshop

IPB skins by Skinbox
Page loaded in: 1.075 seconds