Jump to content

(Papyrus Scripting) How to find the closest inn to player and put into a Location or ObjectReference Alias?


Recommended Posts

I'm trying to have my giantess follower mod "carry" (using the spline node movement functions) the player to the nearest inn after certain dialogue or combat events (I guess as a "Defeat" option). The problem is that I can't figure out how to find the closest inn to the player's current position.

 

The three things I've tried so far are:

1. Player visits an inn, use OnCellLoad to put the cell into a Location Alias if it has an inn keyword. This cell doesn't seem to be the actual inn location, and cells can't be called with the MoveTo function, which expects an ObjectReference. If there was a way to convert the LocationAlias to an ObjectReference and then put that into a normal alias I guess this could work.

2. Restarting a quest occasionally which is just a placeholder for ObjectReference aliases pointing to various locations using condition functions. This works, but the selected inns are not always the closest.

3. Just letting the player chose the inn via dialogue or MCM setting, but this breaks immersion, or setting specific inn as Location aliases.

 

Any ideas to automate finding closest locations of whichever type, which may or not be loaded, or even in the same current cell?

 

Link to comment
18 hours ago, invisible_rodent said:

2. Restarting a quest occasionally which is just a placeholder for ObjectReference aliases pointing to various locations using condition functions. This works, but the selected inns are not always the closest.

 

Don't know an easy/efficient way to do it, but if this works, you could just add a  `distance < x' condition where x is distance of the closest one you found so far, update x (put it in a global or somewhere else you can get at like a conditional property) if you find a new one and restart the quest until it fails, then use the last one found.  (Can just run it when you need the location, rather than `occasionally'.)

(Note that distance can get big, so init x to a very large value for the first run.)

If it can also start in an interior, you may need to just pick a random one, track cell changes until you're outside and then find the closest, as distance (to things outside) won't work properly while in an interior.

 

(For a similar problem in SCB I just use a fixed list of markers in an array alias and find the closest by iterating through that list. Not pretty, not flexible but it works.)

 

18 hours ago, invisible_rodent said:

If there was a way to convert the LocationAlias to an ObjectReference and then put that into a normal alias I guess this could work.

 

Haven't tried but I think you could use e.g. GetIsEditorLocAlias in a condition on a second (reference) alias to find an object reference (eg the coc marker) in that location.

 

Edited by MTB
Link to comment

 

It's probably best to make a list of all the inns in the base game with the location markers as objectreference. If you want to expand on scripting you could also add unlinked markers that players can set with a key or spell. You will need to manually select the Location Markers for the ObjectReferences. This however would only work when you are in Tamriel world.

Spoiler
ObjectReference Property MymodInitialsInn1 Auto
ObjectReference Property MymodInitialsInn2 Auto
ObjectReference Property MymodInitialsInn3 Auto
ObjectReference Property MymodInitialsInn4 Auto
Alias Property MyAlias Auto ;(Or "ReferenceAlias Property MyAlias Auto" I am not certain anymore just see what works)

ObjectReference Property ClosestLocation Auto
; You will have to manually select these ObjectReferences. It is possible that Then use the line
ClosestLocation=MymodInitialsInn1
	If Game.GetPlayer().GetDistance(MymodInitialsInn2)>Game.GetPlayer().GetDistance(MymodInitialsInn1)
		ClosestLocation=MymodInitialsInn2
	EndIf 
	If Game.GetPlayer().GetDistance(MymodInitialsInn3)>Game.GetPlayer().GetDistance(MymodInitialsInn2)
		ClosestLocation=MymodInitialsInn3
	EndIf
	If Game.GetPlayer().GetDistance(MymodInitialsInn4)>Game.GetPlayer().GetDistance(MymodInitialsInn3)
		ClosestLocation=MymodInitialsInn4
	EndIf
; Now ClosestLocation is an ObjectReference that contains the closest in location.
; Defining this ObjectReference as alias can be done with the command
Alias_MyAlias.ForceRefTo(ClosestLocation)

From the website https://ck.uesp.net/wiki/ForceRefTo_-_ReferenceAlias

You can also use ObjectReference as actor by typing "ClosestLocation as Actor". Although I don't see why you would do this it looks like al the moveto commands work with ObjectReferences not with Actors. You can also define actors as ObjectReferences. You might want to read my blog regarding scripting by clicking on my profile.

Edited by DarkBlade13
Link to comment
1 minute ago, DarkBlade13 said:

It's probably best to make a list of all the inns in the base game with the location markers as objectreference. If you want to expand on scripting you could also add unlinked

  

But this AI package could also work and might be a lot easier, no scripting required

Spoiler

afbeelding.png.89241abc0d80608d61833f4aedf902a8.png

 

Edited by DarkBlade13
Link to comment
On 3/10/2024 at 9:41 PM, DarkBlade13 said:

But this AI package could also work and might be a lot easier, no scripting required


Good point, for animating the travel itself you would need an AI package with a travel procedure. This procedure can take an location as its target; does not need an object reference.

I don't think the linked-ref option would work as it needs that a linked ref with that keyword is already set on the actor running the AI package...
However, if you manage to get the target location into a location alias the `loc alias' option should do the trick... (would need to set the owning quest on the package else it will be grayed out...)

 

If you just want to jump there with a moveto then you'd still need an object reference.

 

 

Link to comment
2 hours ago, MTB said:


Good point, for animating the travel itself you would need an AI package with a travel procedure. This procedure can take an location as its target; does not need an object reference.

I don't think the linked-ref option would work as it needs that a linked ref with that keyword is already set on the actor running the AI package...
However, if you manage to get the target location into a location alias the `loc alias' option should do the trick... (would need to set the owning quest on the package else it will be grayed out...)

 

If you just want to jump there with a moveto then you'd still need an object reference.

 

 

Just let me know if you have any more questions or if you need help with something. I haven't made proper armor and animations so far. I can help with everything else.

Edited by DarkBlade13
Link to comment

Thanks Darkblade13 and MTB, very much appreciate your help!

 

This seems to be working: using an alias ObjectReference listing all the inns as OR, along with an AND for GetDistance to the Player < x (5000 seems adequate). Then, set the quest containing this alias to restart when the Player is outside. I didn't realize that all of the Condition functions can also be used when setting aliases.

 

It's not completely satisfactory though because sometimes with the MoveTo command the Player is teleported into a wall or in blank space outside the interior cell space. But this is probably because I'm abusing the translate to node function.

 

 

 

 

 

 

 

 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. For more information, see our Privacy Policy & Terms of Use