pepperman35 Posted April 8, 2023 Share Posted April 8, 2023 (edited) Okay, here is the second attempt to orchestrate organized seating for the Fallout 4 church concept. Script and video follow. The script needs improvement as it is a brute force approach, and additional cases need to be added (i.e., where # of workshop NPCs exceed the max seating capacity). IMHO the seating appears to be a bit more organized with this approach. Suggestions and feedback welcomed and appreciated, especially regarding the script. Scriptname WorkshopSummonedByChurchScript extends Quest ;/Script designed to summon the settlement's NPC to the church. AI packages are placed on the NPC aliases to facilitate seating Script resides on the quest. /; RefCollectionAlias Property Alias_WorkshopNPCs Auto Const ReferenceAlias Property Alias_Workshop Auto Const ReferenceAlias Property Alias_Bell Auto Const workshopparentscript Property WorkshopParent Auto Const Furniture Property FO4_NpcBenchChurchSit01 Auto Const Mandatory Actor Property pPlayerREF Auto Const Mandatory ActorValue Property WorkshopBellDistance Auto Const GlobalVariable Property FO4_CongregationSummonState Auto Const Mandatory ObjectReference Property FO4_ChurchBellsLocMarker const auto Sound Property FO4_ChurchBellsRinging const auto Keyword Property LinkCustom01 Auto Const mandatory Race property HumanRace Auto Const Mandatory ObjectReference Property FO4_ChurchPulpit01REF Auto Const mandatory ObjectReference Property FO4_GoToChurchMarkerCenter Auto Const mandatory ObjectReference Property FO4_GoToChurchMarkerRight Auto Const mandatory ObjectReference Property FO4_GoToChurchMarkerLeft Auto Const mandatory ObjectReference Property FO4_ChurchPew01 Auto Const mandatory ObjectReference Property FO4_ChurchPew02 Auto Const mandatory ObjectReference Property FO4_ChurchPew03 Auto Const mandatory ObjectReference Property FO4_ChurchPew04 Auto Const mandatory ObjectReference Property FO4_ChurchPew05 Auto Const mandatory ObjectReference Property FO4_ChurchPew06 Auto Const mandatory ObjectReference Property FO4_ChurchPew07 Auto Const mandatory ObjectReference Property FO4_ChurchPew08 Auto Const mandatory ObjectReference Property FO4_ChurchPew09 Auto Const mandatory ObjectReference Property FO4_ChurchPew10 Auto Const mandatory ObjectReference Property FO4_ChurchPew11 Auto Const mandatory ObjectReference Property FO4_ChurchPew12 Auto Const mandatory ObjectReference Property FO4_ChurchPew13 Auto Const mandatory function Startup() ; ; debug.trace("FO4_SummonCongregationQuest: Summoning the NPCs to the church") ; ; Initialization ObjectReference[] workshopNPCs = WorkshopParent.GetWorkshopActors(Alias_Workshop.GetRef() as WorkshopScript) int npcIndex = 0 int npcPewCap = 4 int npcCapPerPew = 4 int numNPCsSeated = 0 int MaxSeatingCap = 52 ; Chime the church bells for effect ; FO4_ChurchBellsRinging.play(pPlayerREF) If workshopNPCs.Length > 0 While npcIndex < npcPewCap ObjectReference theNPC = workshopNPCs[npcIndex] ; Only allow humans that are alive to be ref linked If ((theNPC as Actor).IsDead() == False) && ((theNPC as Actor).GetRace() == HumanRace) ;Debug.Trace("The actor is not dead, and they are human, so we link them") theNPC.SetLinkedRef(FO4_ChurchPew01, LinkCustom01) ; ; Check how far away the NPC is from the church lectern. Teleport ; NPCs closer if they are too far away to speed up the seating process ; If theNPC.GetDistance(FO4_ChurchPulpit01REF) > 3000 ; Randomize move to location to avoid congestion int RandomMarker = Utility.RandomInt(1, 3) If (RandomMarker == 1) theNPC.MoveTo(FO4_GoToChurchMarkerCenter) ElseIf (RandomMarker == 2) theNPC.MoveTo(FO4_GoToChurchMarkerRight) ElseIf (RandomMarker == 3) theNPC.MoveTo(FO4_GoToChurchMarkerLeft) EndIf EndIf ; ; Now we want to only add those actors that we have ref linked earlier ; If theNPC.GetLinkedRef(LinkCustom01) Alias_WorkshopNPCs.AddRef(theNPC) numNPCsSeated += 1 EndIf npcIndex += 1 Utility.Wait(5.0) EndIf EndWhile npcIndex = npcPewCap npcPewCap = npcCapPerPew * 2 If npcIndex < workshopNPCs.Length && numNPCsSeated < MaxSeatingCap While npcIndex < npcPewCap ObjectReference theNPC = workshopNPCs[npcIndex] ; Only allow humans that are alive to be ref linked If ((theNPC as Actor).IsDead() == False) && ((theNPC as Actor).GetRace() == HumanRace) ;Debug.Trace("The actor is not dead, and they are human, so we link them") theNPC.SetLinkedRef(FO4_ChurchPew02, LinkCustom01) ; ; Check how far away the NPC is from the church lectern. Teleport ; NPCs closer if they are too far away to speed up the seating process ; If theNPC.GetDistance(FO4_ChurchPulpit01REF) > 3000 ; Randomize move to location to avoid congestion int RandomMarker = Utility.RandomInt(1, 3) If (RandomMarker == 1) theNPC.MoveTo(FO4_GoToChurchMarkerCenter) ElseIf (RandomMarker == 2) theNPC.MoveTo(FO4_GoToChurchMarkerRight) ElseIf (RandomMarker == 3) theNPC.MoveTo(FO4_GoToChurchMarkerLeft) EndIf EndIf ; ; Now we want to only add those actors that we have ref linked earlier ; If theNPC.GetLinkedRef(LinkCustom01) Alias_WorkshopNPCs.AddRef(theNPC) numNPCsSeated += 1 EndIf npcIndex += 1 Utility.Wait(5.0) EndIf EndWhile EndIf npcIndex = npcPewCap npcPewCap = npcCapPerPew * 3 If npcIndex < workshopNPCs.Length && numNPCsSeated < MaxSeatingCap While npcIndex < npcPewCap ObjectReference theNPC = workshopNPCs[npcIndex] ; Only allow humans that are alive to be ref linked If ((theNPC as Actor).IsDead() == False) && ((theNPC as Actor).GetRace() == HumanRace) ;Debug.Trace("The actor is not dead, and they are human, so we link them") theNPC.SetLinkedRef(FO4_ChurchPew03, LinkCustom01) ; ; Check how far away the NPC is from the church lectern. Teleport ; NPCs closer if they are too far away to speed up the seating process ; If theNPC.GetDistance(FO4_ChurchPulpit01REF) > 3000 ; Randomize move to location to avoid congestion int RandomMarker = Utility.RandomInt(1, 3) If (RandomMarker == 1) theNPC.MoveTo(FO4_GoToChurchMarkerCenter) ElseIf (RandomMarker == 2) theNPC.MoveTo(FO4_GoToChurchMarkerRight) ElseIf (RandomMarker == 3) theNPC.MoveTo(FO4_GoToChurchMarkerLeft) EndIf EndIf ; ; Now we want to only add those actors that we have ref linked earlier ; If theNPC.GetLinkedRef(LinkCustom01) Alias_WorkshopNPCs.AddRef(theNPC) numNPCsSeated += 1 EndIf npcIndex += 1 Utility.Wait(5.0) EndIf EndWhile EndIf npcIndex = npcPewCap npcPewCap = npcCapPerPew * 4 If npcIndex < workshopNPCs.Length && numNPCsSeated < MaxSeatingCap While npcIndex < npcPewCap ObjectReference theNPC = workshopNPCs[npcIndex] ; Only allow humans that are alive to be ref linked If ((theNPC as Actor).IsDead() == False) && ((theNPC as Actor).GetRace() == HumanRace) ;Debug.Trace("The actor is not dead, and they are human, so we link them") theNPC.SetLinkedRef(FO4_ChurchPew04, LinkCustom01) ; ; Check how far away the NPC is from the church lectern. Teleport ; NPCs closer if they are too far away to speed up the seating process ; If theNPC.GetDistance(FO4_ChurchPulpit01REF) > 3000 ; Randomize move to location to avoid congestion int RandomMarker = Utility.RandomInt(1, 3) If (RandomMarker == 1) theNPC.MoveTo(FO4_GoToChurchMarkerCenter) ElseIf (RandomMarker == 2) theNPC.MoveTo(FO4_GoToChurchMarkerRight) ElseIf (RandomMarker == 3) theNPC.MoveTo(FO4_GoToChurchMarkerLeft) EndIf EndIf ; ; Now we want to only add those actors that we have ref linked earlier ; If theNPC.GetLinkedRef(LinkCustom01) Alias_WorkshopNPCs.AddRef(theNPC) numNPCsSeated += 1 EndIf npcIndex += 1 Utility.Wait(5.0) EndIf EndWhile EndIf npcIndex = npcPewCap npcPewCap = npcCapPerPew * 5 If npcIndex < workshopNPCs.Length && numNPCsSeated < MaxSeatingCap While npcIndex < npcPewCap ObjectReference theNPC = workshopNPCs[npcIndex] ; Only allow humans that are alive to be ref linked If ((theNPC as Actor).IsDead() == False) && ((theNPC as Actor).GetRace() == HumanRace) ;Debug.Trace("The actor is not dead, and they are human, so we link them") theNPC.SetLinkedRef(FO4_ChurchPew05, LinkCustom01) ; ; Check how far away the NPC is from the church lectern. Teleport ; NPCs closer if they are too far away to speed up the seating process ; If theNPC.GetDistance(FO4_ChurchPulpit01REF) > 3000 ; Randomize move to location to avoid congestion int RandomMarker = Utility.RandomInt(1, 3) If (RandomMarker == 1) theNPC.MoveTo(FO4_GoToChurchMarkerCenter) ElseIf (RandomMarker == 2) theNPC.MoveTo(FO4_GoToChurchMarkerRight) ElseIf (RandomMarker == 3) theNPC.MoveTo(FO4_GoToChurchMarkerLeft) EndIf EndIf ; ; Now we want to only add those actors that we have ref linked earlier ; If theNPC.GetLinkedRef(LinkCustom01) Alias_WorkshopNPCs.AddRef(theNPC) numNPCsSeated += 1 EndIf npcIndex += 1 Utility.Wait(5.0) EndIf EndWhile EndIf npcIndex = npcPewCap npcPewCap = npcCapPerPew * 6 If npcIndex < workshopNPCs.Length && numNPCsSeated < MaxSeatingCap While npcIndex < npcPewCap ObjectReference theNPC = workshopNPCs[npcIndex] ; Only allow humans that are alive to be ref linked If ((theNPC as Actor).IsDead() == False) && ((theNPC as Actor).GetRace() == HumanRace) ;Debug.Trace("The actor is not dead, and they are human, so we link them") theNPC.SetLinkedRef(FO4_ChurchPew06, LinkCustom01) ; ; Check how far away the NPC is from the church lectern. Teleport ; NPCs closer if they are too far away to speed up the seating process ; If theNPC.GetDistance(FO4_ChurchPulpit01REF) > 3000 ; Randomize move to location to avoid congestion int RandomMarker = Utility.RandomInt(1, 3) If (RandomMarker == 1) theNPC.MoveTo(FO4_GoToChurchMarkerCenter) ElseIf (RandomMarker == 2) theNPC.MoveTo(FO4_GoToChurchMarkerRight) ElseIf (RandomMarker == 3) theNPC.MoveTo(FO4_GoToChurchMarkerLeft) EndIf EndIf ; ; Now we want to only add those actors that we have ref linked earlier ; If theNPC.GetLinkedRef(LinkCustom01) Alias_WorkshopNPCs.AddRef(theNPC) numNPCsSeated += 1 EndIf npcIndex += 1 Utility.Wait(5.0) EndIf EndWhile EndIf npcIndex = npcPewCap npcPewCap = npcCapPerPew * 7 If npcIndex < workshopNPCs.Length && numNPCsSeated < MaxSeatingCap While npcIndex < npcPewCap ObjectReference theNPC = workshopNPCs[npcIndex] ; Only allow humans that are alive to be ref linked If ((theNPC as Actor).IsDead() == False) && ((theNPC as Actor).GetRace() == HumanRace) ;Debug.Trace("The actor is not dead, and they are human, so we link them") theNPC.SetLinkedRef(FO4_ChurchPew07, LinkCustom01) ; ; Check how far away the NPC is from the church lectern. Teleport ; NPCs closer if they are too far away to speed up the seating process ; If theNPC.GetDistance(FO4_ChurchPulpit01REF) > 3000 ; Randomize move to location to avoid congestion int RandomMarker = Utility.RandomInt(1, 3) If (RandomMarker == 1) theNPC.MoveTo(FO4_GoToChurchMarkerCenter) ElseIf (RandomMarker == 2) theNPC.MoveTo(FO4_GoToChurchMarkerRight) ElseIf (RandomMarker == 3) theNPC.MoveTo(FO4_GoToChurchMarkerLeft) EndIf EndIf ; ; Now we want to only add those actors that we have ref linked earlier ; If theNPC.GetLinkedRef(LinkCustom01) Alias_WorkshopNPCs.AddRef(theNPC) numNPCsSeated += 1 EndIf npcIndex += 1 Utility.Wait(5.0) EndIf EndWhile EndIf Alias_WorkshopNPCs.EvaluateAll() Else ; Inform the player that they need to recruit some settlers first EndIf Debug.MessageBox("The number of workshop NPCs for this settlement is " + workshopNPCs.Length) Debug.MessageBox("The number of NPCs loaded into the alias is " + Alias_WorkshopNPCs.GetCount()) Debug.MessageBox("The number of NPCs seated is " + numNPCsSeated) Alias_WorkshopNPCs.EvaluateAll() ; Set a flag so we know the congregation has been summoned FO4_CongregationSummonState.SetValue(1 as float) EndFunction function Shutdown() ;start timer StartTimerGameTime(0.25) ; timer shuts down quest EndFunction Event OnTimerGameTime(int aiTimerID) FO4_CongregationSummonState.SetValue(0 as float) Stop() EndEvent Edited April 9, 2023 by pepperman35 Link to comment Share on other sites More sharing options...
lee3310 Posted April 9, 2023 Share Posted April 9, 2023 (edited) Okay, here is the second attempt to orchestrate organized seating for the Fallout 4 church concept. Script and video follow. The script needs improvement as it is a brute force approach, and additional cases need to be added (i.e., where # of workshop NPCs exceed the max seating capacity). IMHO the seating appears to be a bit more organized with this approach. Suggestions and feedback welcomed and appreciated, especially regarding the script. Scriptname WorkshopSummonedByChurchScript extends Quest ;/Script designed to summon the settlement's NPC to the church. AI packages are placed on the NPC aliases to facilitate seating Script resides on the quest. /; RefCollectionAlias Property Alias_WorkshopNPCs Auto Const ReferenceAlias Property Alias_Workshop Auto Const ReferenceAlias Property Alias_Bell Auto Const workshopparentscript Property WorkshopParent Auto Const Furniture Property FO4_NpcBenchChurchSit01 Auto Const Mandatory Actor Property pPlayerREF Auto Const Mandatory ActorValue Property WorkshopBellDistance Auto Const GlobalVariable Property FO4_CongregationSummonState Auto Const Mandatory ObjectReference Property FO4_ChurchBellsLocMarker const auto Sound Property FO4_ChurchBellsRinging const auto Keyword Property LinkCustom01 Auto Const mandatory Race property HumanRace Auto Const Mandatory ObjectReference Property FO4_ChurchPulpit01REF Auto Const mandatory ObjectReference Property FO4_GoToChurchMarkerCenter Auto Const mandatory ObjectReference Property FO4_GoToChurchMarkerRight Auto Const mandatory ObjectReference Property FO4_GoToChurchMarkerLeft Auto Const mandatory ObjectReference Property FO4_ChurchPew01 Auto Const mandatory ObjectReference Property FO4_ChurchPew02 Auto Const mandatory ObjectReference Property FO4_ChurchPew03 Auto Const mandatory ObjectReference Property FO4_ChurchPew04 Auto Const mandatory ObjectReference Property FO4_ChurchPew05 Auto Const mandatory ObjectReference Property FO4_ChurchPew06 Auto Const mandatory ObjectReference Property FO4_ChurchPew07 Auto Const mandatory ObjectReference Property FO4_ChurchPew08 Auto Const mandatory ObjectReference Property FO4_ChurchPew09 Auto Const mandatory ObjectReference Property FO4_ChurchPew10 Auto Const mandatory ObjectReference Property FO4_ChurchPew11 Auto Const mandatory ObjectReference Property FO4_ChurchPew12 Auto Const mandatory ObjectReference Property FO4_ChurchPew13 Auto Const mandatory function Startup() ; ; debug.trace("FO4_SummonCongregationQuest: Summoning the NPCs to the church") ; ; Initialization ObjectReference[] workshopNPCs = WorkshopParent.GetWorkshopActors(Alias_Workshop.GetRef() as WorkshopScript) int npcIndex = 0 int npcPewCap = 4 int npcCapPerPew = 4 int numNPCsSeated = 0 int MaxSeatingCap = 52 ; Chime the church bells for effect ; FO4_ChurchBellsRinging.play(pPlayerREF) If workshopNPCs.Length > 0 While npcIndex < npcPewCap ObjectReference theNPC = workshopNPCs[npcIndex] ; Only allow humans that are alive to be ref linked If ((theNPC as Actor).IsDead() == False) && ((theNPC as Actor).GetRace() == HumanRace) ;Debug.Trace("The actor is not dead, and they are human, so we link them") theNPC.SetLinkedRef(FO4_ChurchPew01, LinkCustom01) ; ; Check how far away the NPC is from the church lectern. Teleport ; NPCs closer if they are too far away to speed up the seating process ; If theNPC.GetDistance(FO4_ChurchPulpit01REF) > 3000 ; Randomize move to location to avoid congestion int RandomMarker = Utility.RandomInt(1, 3) If (RandomMarker == 1) theNPC.MoveTo(FO4_GoToChurchMarkerCenter) ElseIf (RandomMarker == 2) theNPC.MoveTo(FO4_GoToChurchMarkerRight) ElseIf (RandomMarker == 3) theNPC.MoveTo(FO4_GoToChurchMarkerLeft) EndIf EndIf ; ; Now we want to only add those actors that we have ref linked earlier ; If theNPC.GetLinkedRef(LinkCustom01) Alias_WorkshopNPCs.AddRef(theNPC) numNPCsSeated += 1 EndIf npcIndex += 1 Utility.Wait(5.0) EndIf EndWhile npcIndex = npcPewCap npcPewCap = npcCapPerPew * 2 If npcIndex < workshopNPCs.Length && numNPCsSeated < MaxSeatingCap While npcIndex < npcPewCap ObjectReference theNPC = workshopNPCs[npcIndex] ; Only allow humans that are alive to be ref linked If ((theNPC as Actor).IsDead() == False) && ((theNPC as Actor).GetRace() == HumanRace) ;Debug.Trace("The actor is not dead, and they are human, so we link them") theNPC.SetLinkedRef(FO4_ChurchPew02, LinkCustom01) ; ; Check how far away the NPC is from the church lectern. Teleport ; NPCs closer if they are too far away to speed up the seating process ; If theNPC.GetDistance(FO4_ChurchPulpit01REF) > 3000 ; Randomize move to location to avoid congestion int RandomMarker = Utility.RandomInt(1, 3) If (RandomMarker == 1) theNPC.MoveTo(FO4_GoToChurchMarkerCenter) ElseIf (RandomMarker == 2) theNPC.MoveTo(FO4_GoToChurchMarkerRight) ElseIf (RandomMarker == 3) theNPC.MoveTo(FO4_GoToChurchMarkerLeft) EndIf EndIf ; ; Now we want to only add those actors that we have ref linked earlier ; If theNPC.GetLinkedRef(LinkCustom01) Alias_WorkshopNPCs.AddRef(theNPC) numNPCsSeated += 1 EndIf npcIndex += 1 Utility.Wait(5.0) EndIf EndWhile EndIf npcIndex = npcPewCap npcPewCap = npcCapPerPew * 3 If npcIndex < workshopNPCs.Length && numNPCsSeated < MaxSeatingCap While npcIndex < npcPewCap ObjectReference theNPC = workshopNPCs[npcIndex] ; Only allow humans that are alive to be ref linked If ((theNPC as Actor).IsDead() == False) && ((theNPC as Actor).GetRace() == HumanRace) ;Debug.Trace("The actor is not dead, and they are human, so we link them") theNPC.SetLinkedRef(FO4_ChurchPew03, LinkCustom01) ; ; Check how far away the NPC is from the church lectern. Teleport ; NPCs closer if they are too far away to speed up the seating process ; If theNPC.GetDistance(FO4_ChurchPulpit01REF) > 3000 ; Randomize move to location to avoid congestion int RandomMarker = Utility.RandomInt(1, 3) If (RandomMarker == 1) theNPC.MoveTo(FO4_GoToChurchMarkerCenter) ElseIf (RandomMarker == 2) theNPC.MoveTo(FO4_GoToChurchMarkerRight) ElseIf (RandomMarker == 3) theNPC.MoveTo(FO4_GoToChurchMarkerLeft) EndIf EndIf ; ; Now we want to only add those actors that we have ref linked earlier ; If theNPC.GetLinkedRef(LinkCustom01) Alias_WorkshopNPCs.AddRef(theNPC) numNPCsSeated += 1 EndIf npcIndex += 1 Utility.Wait(5.0) EndIf EndWhile EndIf npcIndex = npcPewCap npcPewCap = npcCapPerPew * 4 If npcIndex < workshopNPCs.Length && numNPCsSeated < MaxSeatingCap While npcIndex < npcPewCap ObjectReference theNPC = workshopNPCs[npcIndex] ; Only allow humans that are alive to be ref linked If ((theNPC as Actor).IsDead() == False) && ((theNPC as Actor).GetRace() == HumanRace) ;Debug.Trace("The actor is not dead, and they are human, so we link them") theNPC.SetLinkedRef(FO4_ChurchPew04, LinkCustom01) ; ; Check how far away the NPC is from the church lectern. Teleport ; NPCs closer if they are too far away to speed up the seating process ; If theNPC.GetDistance(FO4_ChurchPulpit01REF) > 3000 ; Randomize move to location to avoid congestion int RandomMarker = Utility.RandomInt(1, 3) If (RandomMarker == 1) theNPC.MoveTo(FO4_GoToChurchMarkerCenter) ElseIf (RandomMarker == 2) theNPC.MoveTo(FO4_GoToChurchMarkerRight) ElseIf (RandomMarker == 3) theNPC.MoveTo(FO4_GoToChurchMarkerLeft) EndIf EndIf ; ; Now we want to only add those actors that we have ref linked earlier ; If theNPC.GetLinkedRef(LinkCustom01) Alias_WorkshopNPCs.AddRef(theNPC) numNPCsSeated += 1 EndIf npcIndex += 1 Utility.Wait(5.0) EndIf EndWhile EndIf npcIndex = npcPewCap npcPewCap = npcCapPerPew * 5 If npcIndex < workshopNPCs.Length && numNPCsSeated < MaxSeatingCap While npcIndex < npcPewCap ObjectReference theNPC = workshopNPCs[npcIndex] ; Only allow humans that are alive to be ref linked If ((theNPC as Actor).IsDead() == False) && ((theNPC as Actor).GetRace() == HumanRace) ;Debug.Trace("The actor is not dead, and they are human, so we link them") theNPC.SetLinkedRef(FO4_ChurchPew05, LinkCustom01) ; ; Check how far away the NPC is from the church lectern. Teleport ; NPCs closer if they are too far away to speed up the seating process ; If theNPC.GetDistance(FO4_ChurchPulpit01REF) > 3000 ; Randomize move to location to avoid congestion int RandomMarker = Utility.RandomInt(1, 3) If (RandomMarker == 1) theNPC.MoveTo(FO4_GoToChurchMarkerCenter) ElseIf (RandomMarker == 2) theNPC.MoveTo(FO4_GoToChurchMarkerRight) ElseIf (RandomMarker == 3) theNPC.MoveTo(FO4_GoToChurchMarkerLeft) EndIf EndIf ; ; Now we want to only add those actors that we have ref linked earlier ; If theNPC.GetLinkedRef(LinkCustom01) Alias_WorkshopNPCs.AddRef(theNPC) numNPCsSeated += 1 EndIf npcIndex += 1 Utility.Wait(5.0) EndIf EndWhile EndIf npcIndex = npcPewCap npcPewCap = npcCapPerPew * 6 If npcIndex < workshopNPCs.Length && numNPCsSeated < MaxSeatingCap While npcIndex < npcPewCap ObjectReference theNPC = workshopNPCs[npcIndex] ; Only allow humans that are alive to be ref linked If ((theNPC as Actor).IsDead() == False) && ((theNPC as Actor).GetRace() == HumanRace) ;Debug.Trace("The actor is not dead, and they are human, so we link them") theNPC.SetLinkedRef(FO4_ChurchPew06, LinkCustom01) ; ; Check how far away the NPC is from the church lectern. Teleport ; NPCs closer if they are too far away to speed up the seating process ; If theNPC.GetDistance(FO4_ChurchPulpit01REF) > 3000 ; Randomize move to location to avoid congestion int RandomMarker = Utility.RandomInt(1, 3) If (RandomMarker == 1) theNPC.MoveTo(FO4_GoToChurchMarkerCenter) ElseIf (RandomMarker == 2) theNPC.MoveTo(FO4_GoToChurchMarkerRight) ElseIf (RandomMarker == 3) theNPC.MoveTo(FO4_GoToChurchMarkerLeft) EndIf EndIf ; ; Now we want to only add those actors that we have ref linked earlier ; If theNPC.GetLinkedRef(LinkCustom01) Alias_WorkshopNPCs.AddRef(theNPC) numNPCsSeated += 1 EndIf npcIndex += 1 Utility.Wait(5.0) EndIf EndWhile EndIf npcIndex = npcPewCap npcPewCap = npcCapPerPew * 7 If npcIndex < workshopNPCs.Length && numNPCsSeated < MaxSeatingCap While npcIndex < npcPewCap ObjectReference theNPC = workshopNPCs[npcIndex] ; Only allow humans that are alive to be ref linked If ((theNPC as Actor).IsDead() == False) && ((theNPC as Actor).GetRace() == HumanRace) ;Debug.Trace("The actor is not dead, and they are human, so we link them") theNPC.SetLinkedRef(FO4_ChurchPew07, LinkCustom01) ; ; Check how far away the NPC is from the church lectern. Teleport ; NPCs closer if they are too far away to speed up the seating process ; If theNPC.GetDistance(FO4_ChurchPulpit01REF) > 3000 ; Randomize move to location to avoid congestion int RandomMarker = Utility.RandomInt(1, 3) If (RandomMarker == 1) theNPC.MoveTo(FO4_GoToChurchMarkerCenter) ElseIf (RandomMarker == 2) theNPC.MoveTo(FO4_GoToChurchMarkerRight) ElseIf (RandomMarker == 3) theNPC.MoveTo(FO4_GoToChurchMarkerLeft) EndIf EndIf ; ; Now we want to only add those actors that we have ref linked earlier ; If theNPC.GetLinkedRef(LinkCustom01) Alias_WorkshopNPCs.AddRef(theNPC) numNPCsSeated += 1 EndIf npcIndex += 1 Utility.Wait(5.0) EndIf EndWhile EndIf Alias_WorkshopNPCs.EvaluateAll() Else ; Inform the player that they need to recruit some settlers first EndIf Debug.MessageBox("The number of workshop NPCs for this settlement is " + workshopNPCs.Length) Debug.MessageBox("The number of NPCs loaded into the alias is " + Alias_WorkshopNPCs.GetCount()) Debug.MessageBox("The number of NPCs seated is " + numNPCsSeated) Alias_WorkshopNPCs.EvaluateAll() ; Set a flag so we know the congregation has been summoned FO4_CongregationSummonState.SetValue(1 as float) EndFunction function Shutdown() ;start timer StartTimerGameTime(0.25) ; timer shuts down quest EndFunction Event OnTimerGameTime(int aiTimerID) FO4_CongregationSummonState.SetValue(0 as float) Stop() EndEvent You need to make some functions here to avoid repeating the same code again (easy to work on and look at) :thumbsup: . Edited April 9, 2023 by lee3310 Link to comment Share on other sites More sharing options...
pepperman35 Posted April 9, 2023 Author Share Posted April 9, 2023 (edited) You need to make some functions here to avoid repeating the same code again (easy to work on and look at) :thumbsup: . Indeed. Working that now. Odd that the posted code is all pink...didn't do that before Anyway, here is the 1st pass through, but having a little trouble passing the variable numNPCsSeated between functions. Scriptname WorkshopSummonedByChurchScript extends Quest ; Script designed to summon the settlement's NPC to the church. ; AI packages are placed on the NPC aliases to facilitate seating ; Script resides on the quest. ; ; ╔═════════════════════════════════════════════════╗ ; ║ Properties ║ ; ╚═════════════════════════════════════════════════╝ RefCollectionAlias Property Alias_WorkshopNPCs Auto Const ReferenceAlias Property Alias_Workshop Auto Const ReferenceAlias Property Alias_Bell Auto Const workshopparentscript Property WorkshopParent Auto Const Furniture Property FO4_NpcBenchChurchSit01 Auto Const Mandatory Actor Property pPlayerREF Auto Const Mandatory ActorValue Property WorkshopBellDistance Auto Const GlobalVariable Property FO4_CongregationSummonState Auto Const Mandatory ObjectReference Property FO4_ChurchBellsLocMarker const auto Sound Property FO4_ChurchBellsRinging const auto Keyword Property LinkCustom01 Auto Const mandatory Race property HumanRace Auto Const Mandatory ObjectReference Property FO4_ChurchPulpit01REF Auto Const mandatory ObjectReference Property FO4_GoToChurchMarkerCenter Auto Const mandatory ObjectReference Property FO4_GoToChurchMarkerRight Auto Const mandatory ObjectReference Property FO4_GoToChurchMarkerLeft Auto Const mandatory ObjectReference Property FO4_ChurchPew01 Auto Const mandatory ObjectReference Property FO4_ChurchPew02 Auto Const mandatory ObjectReference Property FO4_ChurchPew03 Auto Const mandatory ObjectReference Property FO4_ChurchPew04 Auto Const mandatory ObjectReference Property FO4_ChurchPew05 Auto Const mandatory ObjectReference Property FO4_ChurchPew06 Auto Const mandatory ObjectReference Property FO4_ChurchPew07 Auto Const mandatory ObjectReference Property FO4_ChurchPew08 Auto Const mandatory ObjectReference Property FO4_ChurchPew09 Auto Const mandatory ObjectReference Property FO4_ChurchPew10 Auto Const mandatory ObjectReference Property FO4_ChurchPew11 Auto Const mandatory ObjectReference Property FO4_ChurchPew12 Auto Const mandatory ObjectReference Property FO4_ChurchPew13 Auto Const mandatory function Startup() ; ; debug.trace("FO4_SummonCongregationQuest: Summoning the NPCs to the church") ; ; Initialization ObjectReference[] workshopNPCs = WorkshopParent.GetWorkshopActors(Alias_Workshop.GetRef() as WorkshopScript) int npcIndex = 0 int npcPewCap = 4 int npcCapPerPew = 4 int numNPCsSeated = 0 int MaxSeatingCap = 52 ; Chime the church bells for effect ; FO4_ChurchBellsRinging.play(pPlayerREF) If workshopNPCs.Length > 0 If npcPewCap > workshopNPCs.Length npcPewCap = workshopNPCs.Length EndIf ButtsInSeats(npcIndex, npcPewCap, workshopNPCs, FO4_ChurchPew01, numNPCsSeated) Debug.Trace("WorkshopSummonedByChurchScript: Loop #1 executed") Debug.Trace("WorkshopSummonedByChurchScript: The value of npcIndex = " + npcIndex) Debug.Trace("WorkshopSummonedByChurchScript: The value of npcPewCap = " + npcPewCap) Debug.Trace("WorkshopSummonedByChurchScript: The numberr of NPC seated = " + numNPCsSeated) npcIndex = npcPewCap npcPewCap = npcCapPerPew * 2 If npcIndex < workshopNPCs.Length && numNPCsSeated < MaxSeatingCap If npcPewCap > workshopNPCs.Length npcPewCap = workshopNPCs.Length EndIf ButtsInSeats(npcIndex, npcPewCap, workshopNPCs, FO4_ChurchPew02, numNPCsSeated) EndIf Debug.Trace("WorkshopSummonedByChurchScript: Loop #2 executed") Debug.Trace("WorkshopSummonedByChurchScript: The value of npcIndex = " + npcIndex) Debug.Trace("WorkshopSummonedByChurchScript: The value of npcPewCap = " + npcPewCap) Debug.Trace("WorkshopSummonedByChurchScript: The numberr of NPC seated = " + numNPCsSeated) npcIndex = npcPewCap npcPewCap = npcCapPerPew * 3 If npcIndex < workshopNPCs.Length && numNPCsSeated < MaxSeatingCap If npcPewCap > workshopNPCs.Length npcPewCap = workshopNPCs.Length EndIf ButtsInSeats(npcIndex, npcPewCap, workshopNPCs, FO4_ChurchPew03, numNPCsSeated) EndIf Debug.Trace("WorkshopSummonedByChurchScript: Loop #3 executed") Debug.Trace("WorkshopSummonedByChurchScript: The value of npcIndex = " + npcIndex) Debug.Trace("WorkshopSummonedByChurchScript: The value of npcPewCap = " + npcPewCap) Debug.Trace("WorkshopSummonedByChurchScript: The numberr of NPC seated = " + numNPCsSeated) npcIndex = npcPewCap npcPewCap = npcCapPerPew * 4 If npcIndex < workshopNPCs.Length && numNPCsSeated < MaxSeatingCap If npcPewCap > workshopNPCs.Length npcPewCap = workshopNPCs.Length EndIf ButtsInSeats(npcIndex, npcPewCap, workshopNPCs, FO4_ChurchPew04, numNPCsSeated) EndIf Debug.Trace("WorkshopSummonedByChurchScript: Loop #4 executed") Debug.Trace("WorkshopSummonedByChurchScript: The value of npcIndex = " + npcIndex) Debug.Trace("WorkshopSummonedByChurchScript: The value of npcPewCap = " + npcPewCap) Debug.Trace("WorkshopSummonedByChurchScript: The numberr of NPC seated = " + numNPCsSeated) npcIndex = npcPewCap npcPewCap = npcCapPerPew * 5 If npcIndex < workshopNPCs.Length && numNPCsSeated < MaxSeatingCap If npcPewCap > workshopNPCs.Length npcPewCap = workshopNPCs.Length EndIf ButtsInSeats(npcIndex, npcPewCap, workshopNPCs, FO4_ChurchPew05, numNPCsSeated) EndIf Debug.Trace("WorkshopSummonedByChurchScript: Loop #5 executed") Debug.Trace("WorkshopSummonedByChurchScript: The value of npcIndex = " + npcIndex) Debug.Trace("WorkshopSummonedByChurchScript: The value of npcPewCap = " + npcPewCap) Debug.Trace("WorkshopSummonedByChurchScript: The numberr of NPC seated = " + numNPCsSeated) npcIndex = npcPewCap npcPewCap = npcCapPerPew * 6 If npcIndex < workshopNPCs.Length && numNPCsSeated < MaxSeatingCap If npcPewCap > workshopNPCs.Length npcPewCap = workshopNPCs.Length EndIf ButtsInSeats(npcIndex, npcPewCap, workshopNPCs, FO4_ChurchPew06, numNPCsSeated) EndIf Debug.Trace("WorkshopSummonedByChurchScript: Loop #6 executed") Debug.Trace("WorkshopSummonedByChurchScript: The value of npcIndex = " + npcIndex) Debug.Trace("WorkshopSummonedByChurchScript: The value of npcPewCap = " + npcPewCap) Debug.Trace("WorkshopSummonedByChurchScript: The numberr of NPC seated = " + numNPCsSeated) npcIndex = npcPewCap npcPewCap = npcCapPerPew * 7 If npcIndex < workshopNPCs.Length && numNPCsSeated < MaxSeatingCap If npcPewCap > workshopNPCs.Length npcPewCap = workshopNPCs.Length EndIf ButtsInSeats(npcIndex, npcPewCap, workshopNPCs, FO4_ChurchPew07, numNPCsSeated) EndIf Debug.Trace("WorkshopSummonedByChurchScript: Loop #7 executed") Debug.Trace("WorkshopSummonedByChurchScript: The value of npcIndex = " + npcIndex) Debug.Trace("WorkshopSummonedByChurchScript: The value of npcPewCap = " + npcPewCap) Debug.Trace("WorkshopSummonedByChurchScript: The numberr of NPC seated = " + numNPCsSeated) Alias_WorkshopNPCs.EvaluateAll() Else ; Inform the player that they need to recruit some settlers first EndIf Debug.MessageBox("The number of workshop NPCs for this settlement is " + workshopNPCs.Length) Debug.MessageBox("The number of NPCs loaded into the alias is " + Alias_WorkshopNPCs.GetCount()) Debug.MessageBox("The number of NPCs seated is " + numNPCsSeated) Alias_WorkshopNPCs.EvaluateAll() ; Set a flag so we know the congregation has been summoned FO4_CongregationSummonState.SetValue(1 as float) EndFunction function Shutdown() ;start timer StartTimerGameTime(0.25) ; timer shuts down quest EndFunction Function ButtsInSeats(int j, int jMax, ObjectReference[] workshopNPCs, ObjectReference myChurchPew, int numNPCsSeated) While j < jMax ObjectReference theNPC = workshopNPCs[j] ; Only allow humans that are alive to be ref linked If ((theNPC as Actor).IsDead() == False) && ((theNPC as Actor).GetRace() == HumanRace) ;Debug.Trace("The actor is not dead, and they are human, so we link them") theNPC.SetLinkedRef(myChurchPew, LinkCustom01) ; ; Check how far away the NPC is from the church lectern. Teleport ; NPCs closer if they are too far away to speed up the seating process ; If theNPC.GetDistance(FO4_ChurchPulpit01REF) > 3000 ; Randomize move to location to avoid congestion int RandomMarker = Utility.RandomInt(1, 3) If (RandomMarker == 1) theNPC.MoveTo(FO4_GoToChurchMarkerCenter) ElseIf (RandomMarker == 2) theNPC.MoveTo(FO4_GoToChurchMarkerRight) ElseIf (RandomMarker == 3) theNPC.MoveTo(FO4_GoToChurchMarkerLeft) EndIf EndIf ; ; Now we want to only add those actors that we have ref linked earlier ; If theNPC.GetLinkedRef(LinkCustom01) Alias_WorkshopNPCs.AddRef(theNPC) numNPCsSeated += 1 EndIf j += 1 Utility.Wait(5.0) EndIf EndWhile EndFunction Event OnTimerGameTime(int aiTimerID) FO4_CongregationSummonState.SetValue(0 as float) Utility.Wait(1.0) ObjectReference[] workshopNPCs = WorkshopParent.GetWorkshopActors(Alias_Workshop.GetRef() as WorkshopScript) int i = 0 While i < workshopNPCs.Length ;ObjectReference theNPC = workshopNPCs[i] Actor actorNPC = workshopNPCs[i] as Actor actorNPC.EvaluatePackage() i += 1 EndWhile Stop() EndEvent Edited April 9, 2023 by pepperman35 Link to comment Share on other sites More sharing options...
lee3310 Posted April 9, 2023 Share Posted April 9, 2023 (edited) You need to make some functions here to avoid repeating the same code again (easy to work on and look at) :thumbsup: . Indeed. Working that now. Odd that the posted code is all pink...didn't do that before Anyway, here is the 1st pass through, but having a little trouble passing the variable numNPCsSeated between functions. you can define numNPCsSeated outside of the function as "global variable" since it's used by both functions and edit it in ButtsInSeats() without passing it as an argument: Function ButtsInSeats(int j, int jMax, ObjectReference[] workshopNPCs, ObjectReference myChurchPew) Edited April 9, 2023 by lee3310 Link to comment Share on other sites More sharing options...
pepperman35 Posted April 10, 2023 Author Share Posted April 10, 2023 Thanks for that valuable tip lee3310. Works rather well, and the seating of the NPCs seems a bit more organized. Still need to amend the code to use all 13 pew, if needed, and handle the case where there might be > 52 settlers. All in all, coming along nicely. Link to comment Share on other sites More sharing options...
Recommended Posts