Question Need Assistance: Dynamic building locations and schedules

Maclimes

Cowpoke
I'm building a custom NPC, and if they're married to the player, I'd like them to walk up to a spot a few blocks away from the player's barn (assuming it exists) at a particular time. The problem is, I don't know the X,Y coordinates for the barn, since it can be wherever the player chooses. Plus, you may have more than one barn!

I realize that there must be something like that in there already. A married NPC finds their way to the bed somehow, even if it's moved or if there's more than one (although I am realizing now I've never seen them actually walking to the bed). And the barn's explicit location must be callable, because if the witch event occurs, the camera knows to center on a coop. So I figure this stuff is in there, I just need to somehow combine them in a schedule event.

So, how would I identify a barn's location, and how would I input that into a schedule line for an NPC? And assuming I can do that, how do I off-set those values (so they're not clipping inside the building)? For the moment, I'm not too worried about clipping inside of whatever object is in that location. That's probably a whole new level of headache. (Alternatively, if anyone knows of an existing NPC mod that does something like this, let me know so I can reverse-engineer how it was done.)
 

mouse

Farmer
A couple things to consider: first, unless some mod has dramatically broken this open recently, NPCs cannot path around on the farm like they can in other locations. You can't use the farm as part of the schedule like that. The other is that yes, you can get coordinates for barns, but you'd usually do it by iterating through all the buildings in the location, finding a barn, and then getting those coordinates -- something perfectly doable in a SMAPI (C#) mod, but not a content pack that is only dealing with editing/replacing/adding assets that don't change how the game uses those assets.

You're right that the game can certainly find those buildings, but there are a lot of things that the game does without specifically checking some pre-set variable in a file you can change or read from a content pack. So, doable if you are doing a SMAPI mod, not so much if you are sticking with packs for CP and associated frameworks.

In my opinion the simplest way to deal with both 1 and 2 is to limit farm interactions to pre-written events (vs part of a schedule), and make a config option in your CP pack for where building-related events should take place. You could set default coordinates to use, or maybe better, just provide no default value and allow it to be blank, then condition the event on the player having filled it with something, using HasValue.
 
Top