Jump to content

FindClosestActor/FindRandomActor only returns Player?


Hoamaii

Recommended Posts

Hey guys,

 

I'm obviously doing something wrong in Fallout 4 with these functions.

 

Calling:

 

Actor Buddy = Game.FindClosestActorFromRef(Game.GetPlayer(), 512.0) - or any larger or smaller radius -

 

or all this function's variations (FindRandomActor, FindClosestActor, etc.) in a MagicEffect script only ever returns the player itself no matter how close I stand to other NPCs nor how many there are around me.

 

After many attempts, I'm getting the feeling that these functions don't quite work as they did in Skyrim. Are inGame instances of actors treated as ObjectReferences only in F04? Or do these functions only work with AliasReferences?

 

Many thanks in advance! :)

Link to comment
Share on other sites

@hoamaii

That is an awesome question, and I don't know what awesome mods you're cooking up,

but given this question, it's going to be all kinds of floating-point awesome stuff.

 

FO4 is a bit of a hodgepodge compared with Skyrim or FONV or FO3, tbh imho.

 

 

 

although my own mod fu is not particularly strong,

I am more than happy to offer some perspective in the meantime until

a more pro modder can arrive to help more thoroughly.

 

I think there are two things at play;

first, you have to exclude the player from the array, by type from the check. that prevents the call from selecting yourself, as you will always be the closest to a call which originates from the Player-Character Node hehe.

I think the check is also being made when you enter or leave a cell, not while you are in it.

that's similar to the Pipboy Settlement Menu overhaul/accurate settlement menus and HUDui suite.

 

then, you also have to set a minimum and a maximum distance, and where those maximum distances touch on the "cell reset issue"/"cell system",

you have to use workarounds. 512 I think is 2 or more cells distance... vaguely from memory. It's either 2 or 1/2... heheh.

NPC's in FO4 are a little different, they're a floating-point value,

and if you try to get the call from a cell that isn't the settlement,

say, a Mall at Malden or something,

you're not going to get an accurate return as the game doesn't actually model the NPC's transiting between cells...

 

we had a similar problem trying to make moving region node stalls for "brahmin wagons"

and "Super Mutant slave trains"...

the call wasn't checking around the node, and always returned 0.

 

Similarly, large skyscraper elevator vendor nodes also have complicated calls...

if you wanted to make the price of items a function of number of NPC's around (ie, the busier the settlement, the more 'demand' there is... hehe)

these calls could let you do it...

 

----

I think you're using this approach to get the nearest NPC to the Player Character,

perhaps for ambient quests or random intermittent events etc?

the bounty board project might also help for some ideas on how to get persistent dynamic MCMC generated ambient quests hehe.

 

 

 

I hope this is of some use to you in the meantime,

and I look forward to seeing the answer to this, as it's a more complex hypothetical which isn't covered in many other how-to tutorials elsewhere.

Edited by montky
Link to comment
Share on other sites

@ Montky:

 

Hmmm... Very interesting Spoiler (though a bit depressing if you don't mind my saying so)... I only wish my English was better (non-native English speaker here) so I could get all the subtleties of this... ;)

 

About radius, my assumption was that units are basically the same as they were in Skyrim (meaning an actor's average height is about 128), and as far as I've experienced in F04, this should be about right: I used a simple 3 sits couch to verify that, getting my Character to detect the center of the couch while sitting in turn in each interactive point calling "FindClosestReferenceOfAnyTypeInList(...)" - and any radius less than 64 units won't detect the couch unless using the center sitting spot. 64 units work for "2 sits" couches, 80 is roughly ok (inconsistent results) for "3 sits" ones. So I guess 128 is about right for an actor's height. (http://www.creationkit.com/index.php?title=File:UnitScaleRef.jpg)

 

So yeah, 512 is probably like 2 or 3 stories high, or a large room wide - but 2 exterior cells? How can it be if a couch is roughly 90 units long? (though I didn't check about cells to be honest).

 

Anyway, yeah, I'm trying to target the nearest NPC without using a gun to do this - but you say "the game checks when you enter or leave a cell, not while you're in it"?!.. Oh my, if that's true, it does make that FindClosestActor function completely useless since NPCs keep moving around all the time (I can never find Preston when I'm looking for him in Sanctuary - he only drops on me when I'm desperately trying to avoid him!..).

 

Exclude the player in an array - I've thought of that but that would only work if the game checks at run-time while I'm inside the cell, right?

 

For the moment, I'm thinking of trying to target specific factions or specific actors with formList, see if I get any better luck... If NPCs are sort of floating-points like you say, I doubt that'll work but worth a try...

 

I'll let you know ;)

 

Meanwhile, I'm listening to all suggestions!.. Thanks!

Link to comment
Share on other sites

Update:

 

Using an Actors FormList to call "BuddyRef = FindClosestReferenceOfAnyTypeInList(...)" works but of course returns an ObjectReference. From there however, it's fairly easy to move on to "Actor Buddy = BuddyRef as Actor" to call functions on the closest actor.

 

That's limiting of course to your FormList - but for me it's a start. And possibly a confirmation that if you want to call functions on Actors, you first need to treat them as ObjectReferences (Instances of Actors, not Forms) before you use them as Actors in your script (not talking about quests nor Aliases here, I'm just working on a MagicEffect atm). It may also mean that you can't use Actors as Forms in MagicEffect scripts' Properties, but rather actor's in-game ObjectReferences (maybe from their initial spawn cell for instance - haven't tried that yet though).

Link to comment
Share on other sites

@hoamaii

apologies for a tangent-ladden spoiler box,

though you asked a really good technical question, which seems to ask more questions than it may have answers,

and suggest a lot of awesome ideas for other mod projects

in relation to some floating-point stuff in FO4.

 

I hope we will hear from some pro modders too, just so as I didn't veer us off into a garden path too far hehe.

 

 

 

although my own mod-fu in FO4 is not strong,

anything I can do to assist in realizing some of these ambitious mods envisioned is awesome.

 

Thank you also for your insights onto other approaches, those may help with quite a few projects.

not least, some 'regional economy' mods/barter system overhaul,

karma system, choice system/more gamestates overhaul etc.

 

if we combine that with a 'get.thatNPCrefID#" call,

we can generate a floating-point array without P-NP hyperdefining our variables,

which will be interoperable with the "Don't Call Me Settler" mod,

and the envisioned karma mods, AGIxml "talking heads" mod, live embeddable dynamic audio etc.

all of this goes a long way towards increasing overall 'verisimilitude'

exegetically, via 'increased recursive emotional investment' in the various NPC's,

just like in real-life pen and paper RolePlayingGames

such as FORPG, GURPS etc.

 

Imagine - dynamic embedded 'live acting' audio,

and a live-acting NPC... all persistent sandbox in real time.

thats where FORPG and MMORPG/live game blurs.

This is the kind of awesome stuff we can do with games, if we treat games as we might a TV show etc...

if we take 1 engine or approach, and wring as much as we can out of it...

 

 

Link to comment
Share on other sites

@ Reneer:

 

Thanks, I'll do that, I just need to clean up my 500 lines long script to extract the section which is causing me trouble here and clean up that section from all failed attempts (preceded by ;...) - but I'll do that in my next post, at the moment I'm struggling to calculate offsets, and I'm just terrible at Maths, so any help from a more experienced scripter would be awesome!.. (I've created another thread here about that). Thanks for offering your help.

 

@ Montky:

 

Yeah, funny thing that the very experienced modders I used to stumble upon all the time in Skyrim's CK forums don't seem to come here that often... Not sure it may help you, but I've also found out that any attempt to dynamically modify the player's position (MoveTo, SetPosition, SetAngle, etc.) will systematically trigger a quick fade out game, that can be adjusted in the game settings but I'd rather not encourage users to change their game settings as long as they're not better documented about their secondary long-term effects... Looks like I'm going to have to find some crazy workarounds to achieve what I'm trying to do (position two actors properly to get them to dynamically play together an animation set - doing that in Skyrim was kind of a piece of cake though).

Link to comment
Share on other sites

I haven't had a chance to try and see if this would work, but something like this, in theory, should do what you want:

 

Keyword Property ActorTypeNPC Auto
ObjectReference[] Property FoundActors Auto
 
Function FindActorsAroundPlayer()
   FoundActors = Game.GetPlayer().FindAllReferencesWithKeyword(ActorTypeNPC, 4000.0)
   ; note that the player would be in this list, most likely.
endFunction
Link to comment
Share on other sites

@Reneer,

that is some elegant block.

indeed, the player would be in that array/list,

but, you can exclude the player via a few methods.

that is very elegant though!

 

thanks a zillion Reneer, and I hope that will help Hoamaii

it gives me a few ideas for an issue with floatingpoint nodes for vendors on an elevator being across multiple nodes...

 

Edit:

 

 

shavkacagarikia has checked reneer's block, and apparently the playercharacter is unlikely to be in that call.

I stand corrected on that hehe, my mod-fu ain't so good hahaha

when I tried that approach on some nodes, it returned a few floatingpoint values, so I am doing something odd hehe.

I think it's reading from the wrong papyrus array line, or the wrong .xml table...

 

thanks to both of you Reneer and Shavkacagarikia for going the extra mile and helping

on a tricky question that isn't covered in many if any tutorials.

 

 

Edited by montky
Link to comment
Share on other sites

@ Reneer,

 

Oh my, you've been seriously helping me twice in rhe same day!..

 

I wish I could kudo you a second time - perhaps that's an option the Nexus should examine to be able to give kudos from the Forum too rather than just on the Nexus Profile.

 

Yeah, it'd be easy to exclude the player from that array, or use any other type of Keywords.

 

For my present purpose, the FormList works fine, but I'll definitely give that a try after I've completely tested the last line of code you gave me - and post some variations of this if I find any useful.

 

Thank you so much again, Reneer!..

Link to comment
Share on other sites

  • Recently Browsing   0 members

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