Jump to content

Need help with scripting


faktehwin

Recommended Posts

Formlist property markerList auto

Function MoveToNearestMarker(Formlist akList, Actor akActor, Float afDistance)
    int index = akList.GetSize()
    While index
        index -= 1
        if (akList.GetAt(index) as ObjectReference).GetDistance(akActor) <= afDistance
            akActor.MoveTo(akList.GetAt(index) as ObjectReference)
        endif
  Endwhile
EndFunction
MoveToNearestMarker(MarkerList, Game.GetPlayer(), 500.0)

How this works:

Each time the loop iterates, it goes up the list and checks if the objectreference at that position in the list is 500.0 units or less to the player, and itereates to the next form if not. This continues until the last form in the list( actually the first; index 0) is reached.

 

If 2 or more markers are exactly the same distance, it doesn't matter, the loop will move you to the first one found.

Edited by Rasikko
Link to comment
Share on other sites

Thanks! This really help me alot with understanding how the loop function works. Although its not exactly what I was looking for, when I used the script you posted I got ported to each marker listed in the form so long as it was under the 500 unit. However with abit of tinkering I managed to make it work how I wanted. This is the function I used:

 

Function MoveToNearestMarker(Formlist akList, Actor akActor, Float afDistance) ;afDistance was set to 1000000 to roughly cover the world map, not sure whats the limit.
ObjectReference ClosestMarker
int index = akList.GetSize()
While index
index -= 1
if (akList.GetAt(index) as ObjectReference).GetDistance(akActor) <= afDistance
afDistance = (akList.GetAt(index) as ObjectReference).GetDistance(akActor)
ClosestMarker = (akList.GetAt(index) as ObjectReference)
endif
Endwhile
akActor.MoveTo(ClosestMarker)
EndFunction
Link to comment
Share on other sites

  • Recently Browsing   0 members

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