Jump to content

Creating new caravans (Expanded Caravans Mod)


kirloper

Recommended Posts

All right, so I've been messing with caravans recently myself, so I can add a few pointers. This first part will be workshop caravans. In other words, settlers you assigned to caravan from one settlement to another:

 

First and foremost, script-wise they're assigned via lines 1570-1633 of WorkshopParentScript, here:

function AssignCaravanActorPUBLIC(WorkshopNPCScript assignedActor, Location destinationLocation)
	; NOTE: package on alias uses two actor values to condition travel between the two workshops
	wsTrace("------------------------------------------------------------------------------ ")
	wsTrace("	AssignCaravanActorPUBLIC actor=" + assignedActor + ", destination=" + destinationLocation)
	; lock editing
	GetEditLock()

	; get destination workshop
	WorkshopScript workshopDestination = GetWorkshopFromLocation(destinationLocation)

	; current workshop
	WorkshopScript workshopStart = GetWorkshop(assignedActor.GetWorkshopID())
	; unassign this actor from any current job
	UnassignActor(assignedActor)

	; is this actor already assigned to a caravan?
	int caravanIndex = CaravanActorAliases.Find(assignedActor)
	if caravanIndex < 0
		; add to caravan actor alias collection
		wsTrace("		AssignCaravanActorPUBLIC actor=" + assignedActor + " IsUnique()=" + assignedActor.GetActorBase().IsUnique())
		CaravanActorAliases.AddRef(assignedActor)
		if assignedActor.GetActorBase().IsUnique() == false && assignedActor.GetValue(WorkshopProhibitRename) == 0
			wsTrace("		AssignCaravanActorPUBLIC actor=" + assignedActor + " not unique, putting in rename alias")
			; put in "rename" alias
			CaravanActorRenameAliases.AddRef(assignedActor)
		endif
	else
		; clear current location link
		Location oldDestination = GetWorkshop(assignedActor.GetCaravanDestinationID()).myLocation
		workshopStart.myLocation.RemoveLinkedLocation(oldDestination, WorkshopCaravanKeyword)
	endif
	
	int destinationID = workshopDestination.GetWorkshopID()

	; set destination actor value (used to find destination workshop from actor)
	assignedActor.SetValue(WorkshopCaravanDestination, destinationID)
	wsTrace("		AssignCaravanActorPUBLIC: destination=" + assignedActor.GetValue(WorkshopCaravanDestination) + " start=" + assignedActor.GetWorkshopID())

	; make caravan ref type
	if assignedActor.IsCreated()
		assignedActor.SetLocRefType(workshopStart.myLocation, WorkshopCaravanRefType)
	endif

	; add linked refs to actor (for caravan package)
	assignedActor.SetLinkedRef(workshopStart.GetLinkedRef(WorkshopLinkCenter), WorkshopLinkCaravanStart)
	assignedActor.SetLinkedRef(workshopDestination.GetLinkedRef(WorkshopLinkCenter), WorkshopLinkCaravanEnd)

	; add link between locations
	;debug.trace(self + " AssignCaravanActorPUBLIC: linking " + workshopStart.myLocation + "(" + workshopStart + ") to " + workshopDestination.myLocation + "(" + workshopDestination + ")")
	workshopStart.myLocation.AddLinkedLocation(workshopDestination.myLocation, WorkshopCaravanKeyword)

	; 1.6: send custom event for this actor
	Var[] kargs = new Var[2]
	kargs[0] = assignedActor
	kargs[1] = workshopStart
	wsTrace(" 	sending WorkshopActorCaravanAssign event")
	SendCustomEvent("WorkshopActorCaravanAssign", kargs)

	; stat update
	Game.IncrementStat("Supply Lines Created")

	; unlock editing
	EditLock = false
endFunction

So what that function does is, it takes a workshop actor and converts them to a caravan actor, unassigns them from a caravan route they have if they're already assigned, and handles related tasks like linking the workshops together.

 

Specific portions of note are lines 1614 and 1615, which sets the endpoints of the caravan's patrol route, and line 1619, which handles linking the two workshops together. (This combines the workshop resources and draws a line between them on the map.)

 

Now, these assume that the actor has the WorkshopNPCScript attached to them, which will store the relevant information. There is other handling elsewhere in WorkshopScript and WorkshopParentScript and WorkshopNPC script for what happens when the NPC gets hurt, as well as for assigning, maintaining, and removing the caravan's brahmin, but this is the gist of the script-side to get them going back and forth between settlements, as well as getting the resources flowing.

 

In the creation kit itself, the caravan NPCs will use either the WorkshopCaravanPackage or the WorkshopCaravanBrahminPackage, depending. These are quest-locked packages, so you would need to either hook into the quest or copy the package and unlock the copy for use. I have had success doing the latter, and I have not tried the former.

 

 

Anyway, I assume you're actually after caravans like Lucas Miller, and so their information starts below:

 

Lucas Miller is a good one to look at because he starts out roaming between several specific settlements, but has all the standard features of a caravan merchant. If you go to the Character->Package portion of the Creation kit, and search Lucas, you'll find a series of packages with names starting with the word Caravan. All of those are or were intended to be used by LucasMiller, and they follow standard Bethesda naming rules. There is a package for his entourage to use while he's set up shop, a series of six different movement packages for going from place to place, a series of three packages for Lucas to use to pause and "wait" somewhere, etc. The vast majority of the packages are templated off the GroupMovement package, so there isn't much to poke around with in them, just he data to assign at the top.

 

If you go to Actors->Actor, and search Lucas, you'll see four NPCs. Lucas himself, his brahmin, and his two guards. Looking at them, it would appear Lucas uses the WorkshopNPC script in combination with a few relevant factions, but has no AI Package set. That's likely set by a quest, so if you head to Character->Quest...

 

You'll find a quest named CaravanTradePostLucas, which controls picking his next location and setting his AI. It has a set of important quest aliases, and this papyrus snippet as a fragment for stage 5:

; Move the caravan to the location
ObjectReference oHitchingPost = Alias_HitchingPost.GetRef()
ObjectReference oAttackMarker = Alias_WorkshopAttackMarker.GetRef()
ObjectReference oTeleportTo

; If the player is too close to the hitching post and there's a valid hidding waypoint
; then have the caravan teleport there, instead.
if ( Game.GetPlayer().GetDistance(oHitchingPost) < 3000 && oAttackMarker )
  oTeleportTo = oAttackMarker
else
  oTeleportTo = oHitchingPost
endif

Alias_CaravanTrader.GetActorRef().MoveTo(oTeleportTo)
;UFO4P 2.0.2 Bug #22768
if( Alias_CaravanBrahmin.GetActorRef() )
  Alias_CaravanBrahmin.GetActorRef().MoveTo(oTeleportTo)
endif
if( Alias_CaravanGuard01.GetActorRef() )
  Alias_CaravanGuard01.GetActorRef().MoveTo(oTeleportTo)
endif
if( Alias_CaravanGuard02.GetActorRef() )
  Alias_CaravanGuard02.GetActorRef().MoveTo(oTeleportTo)
endif

That snipped handles moving the caravan to the destination, likely on fast travel. In terms of related code, there is code for the NPC caravans in WorkshopNPCScript, WorkshopScript, and WorkshopParentScript, although it's muddled and mixed because both the NPC and settler caravans get referred to as caravans with no particular differentiation.

 

Overall, copying the relevant information and quests for Lucas and modifying them to suit your needs would probably be the most efficient way for you to create new, non-settler caravans.

Edited by Glitchfinder
Link to comment
Share on other sites

All right, so I've been messing with caravans recently myself, so I can add a few pointers. This first part will be workshop caravans. In other words, settlers you assigned to caravan from one settlement to another:

 

First and foremost, script-wise they're assigned via lines 1570-1633 of WorkshopParentScript, here:


That snipped handles moving the caravan to the destination, likely on fast travel. In terms of related code, there is code for the NPC caravans in WorkshopNPCScript, WorkshopScript, and WorkshopParentScript, although it's muddled and mixed because both the NPC and settler caravans get referred to as caravans with no particular differentiation.

 

Overall, copying the relevant information and quests for Lucas and modifying them to suit your needs would probably be the most efficient way for you to create new, non-settler caravans.

I don't suppose you know how to set a new destination to set up a specific water caravan from a water source or food/scavenge/supply caravan from the wasteland? Not like the new Gatherers out there mod. Just a simple 2 way patrol that has those specific destinations? I figured to put a marker in the Creation Kit, but associating it with the provision caravan with those specific values....?

Link to comment
Share on other sites

 

All right, so I've been messing with caravans recently myself, so I can add a few pointers. This first part will be workshop caravans. In other words, settlers you assigned to caravan from one settlement to another:

 

First and foremost, script-wise they're assigned via lines 1570-1633 of WorkshopParentScript, here:


That snipped handles moving the caravan to the destination, likely on fast travel. In terms of related code, there is code for the NPC caravans in WorkshopNPCScript, WorkshopScript, and WorkshopParentScript, although it's muddled and mixed because both the NPC and settler caravans get referred to as caravans with no particular differentiation.

 

Overall, copying the relevant information and quests for Lucas and modifying them to suit your needs would probably be the most efficient way for you to create new, non-settler caravans.

I don't suppose you know how to set a new destination to set up a specific water caravan from a water source or food/scavenge/supply caravan from the wasteland? Not like the new Gatherers out there mod. Just a simple 2 way patrol that has those specific destinations? I figured to put a marker in the Creation Kit, but associating it with the provision caravan with those specific values....?

 

 

Lines 1614 and 1615 of WorkshopParentScript, these ones:

	assignedActor.SetLinkedRef(workshopStart.GetLinkedRef(WorkshopLinkCenter), WorkshopLinkCaravanStart)
	assignedActor.SetLinkedRef(workshopDestination.GetLinkedRef(WorkshopLinkCenter), WorkshopLinkCaravanEnd)

Those are the ones that set the endpoints of the back and forth caravan patrol. It is treating the actors as WorkshopNPCScript objects, which means you're going to want to either use actual settlers, apply that script to NPCs you create, or create your own script to store similar variables.

 

Those variables get used by the AI package WorkshopCaravanPackage, which is set up to make an NPC travel back and forth between two specified references. (In this case, the marker you set and a reference for whatever you wanted the other endpoint to be. All settlements have a reference for the "center" of the settlement, which can be grabbed with the WorkshopParentScript or WorkshopScript.

 

Now, WorkshopCaravanPackage is quest-locked, but I would need to know more about your plans before being able to offer more specific setup details. At the moment I've been using this all to set up a mod that makes automated minuteman patrols between every settlement in your control, so my focus was largely on the AI package and grabbing settlement locations/status.

Edited by Glitchfinder
Link to comment
Share on other sites

Today I have been creating a bunch of new NPCs for new caravans but I am a little lost on creating the packages and quest for them to follow each other and move. Never done anything like this before.

 

 

thankyou for the explanation.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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