Jump to content

Function that returns the nearest actor to the player


TheBlob2

Recommended Posts

Try this UDF:

ScriptName NearestActorUDF
reference rActor
reference rClosestActor

Begin Function { }
    Set rActor to GetFirstRef 200 0
    Set rClosestActor to rActor
    While rActor
        If rActor.GetDead || rActor.GetDisabled || rActor.GetIsCreature
            ; skip
        ElseIf rActor.GetDistance Player < rClosestActor.GetDistance Player
            Set rClosestActor to rActor
        EndIf
        Set rActor to GetNextRef
    Loop
    SetFunctionValue rClosestActor
End
Edited by Ladez
Link to comment
Share on other sites

 

Try this UDF:

ScriptName NearestActorUDF
reference rActor
reference rClosestActor

Begin Function { }
    Set rActor to GetFirstRef 200 0
    Set rClosestActor to rActor
    While rActor
        If rActor.GetDead || rActor.GetDisabled || rActor.GetIsCreature
            ; skip
        ElseIf rActor.GetDistance Player < rClosestActor.GetDistance Player
            Set rClosestActor to rActor
        EndIf
        Set rActor to GetNextRef
    Loop
    SetFunctionValue rClosestActor
End

what about a way to check if the nearest actor is close enough to start dialog? and a way to check if the player has their crosshair on nearest actor?

Link to comment
Share on other sites

Both should be easy once you know how close you need to be to enter dialog and how to find out what object the player's crosshair is pointing at. I don't know either, right at this moment.

Edited by Ladez
Link to comment
Share on other sites

 

what about a way to check if the nearest actor is close enough to start dialog? and a way to check if the player has their crosshair on nearest actor?

 

 

If this compiles

if eval (Call NearestActorUDF) == GetCrosshairREF

or just in case

Let rTemp := GetCrosshairREF
if eval (Call NearestActorUDF) == rTemp

About the distance, you could check if the value is at least 150 (or 120, don't remember), but you wouldn't really need it. Distance can be forced via Dialogue package, and there's a brand new StartConversationDistance function that allows to specify it. Not sure if it's already online, but in case just wait a little time and it will.

Edited by Fallout2AM
Link to comment
Share on other sites

I know this is off topic, and it may seem like a stupid question, but are references in scripts self contained?

Like, if I put a set command in a script. Will every script that uses the reference that I just 'set', use what I have 'set' it as?

Or if I put an 'if' statement in a script, and the qualifications of the 'if' statement is met in an actor, will every actor also be affected by the effects of the 'if' statement if they have the script on them too even if they don't meet the qualifications of it?

Edited by TheBlob2
Link to comment
Share on other sites

I know this is off topic, and it may seem like a stupid question, but are references in scripts self contained?
Like, if I put a set command in a script. Will every script that uses the reference that I just 'set', use what I have 'set' it as?

 

The scope of reference variables, as well as all other types of script variables, only extends to the script itself. In other words, they are self contained in the script in which they're declared. A variable called actor may contain one actor in one script and a different actor in another. A script attached to two actors with the variable friendshipPoints can have different values for each actor. You can be good friends with one and not so good friends with the other.

 

Or if I put an 'if' statement in a script, and the qualifications of the 'if' statement is met in an actor, will every actor also be affected by the effects of the 'if' statement if they have the script on them too even if they don't meet the qualifications of it?

 

I think this could have been worded better, but I think I understand what you mean. Using the example with the two friends above, each would have their own version of the script running seperately with their own set of variables. Also, reference functions usually only affect either the reference that the script is currently running on (using implied reference syntax) or the reference that the function is called on (using explicit reference syntax.)

Link to comment
Share on other sites

  • Recently Browsing   0 members

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