×
Меню
Индекс

MSFD Distance of one object to another

 
GetDistance, "ObjectID"     (returns float)
 
"ObjectID1"->GetDistance, "ObjectID2"
 
This function returns the distance (in units) of one object to another. In syntax one, that is the distance between the calling object (to which script is attached to) and the named object. This can be used to trigger attacks or other events, or simply to roughly determine the player's whereabouts for use in a script.
Here is a snippet from an original Morrowind script:
 
; From a script attached to an NPC Ashamanu:
; Ashamanu will give journal entry 60 when player is near
 
if ( GetDisabled != 1 )
     if ( GetDistance Player <= 256 )
          if ( GetDistance "guar_white_unique" <= 256 )
               if ( GetJournalIndex "MS_WhiteGuar" <= 50 )
                    Journal "MS_WhiteGuar" 60
               endif
          endif
     endif
endif
 
Limitations:
•     GetDistance requires that the object given as parameter is placed in the gameworld (in the editor) and has references persist checked (or is naturally persistent such as an NPC).
•     Note that you should use this function only with unique ID's or in environments where you exactly know that there is only one instance of the ID – otherwise the Game engine will just grab the first instance of the ID it finds and report that distance – most likely not the distance to the object you want. Thus, a script that warns the player of the presence of a slaughterfish that is closer than 800 units would have to be attached to the ID of the slaughterfish, and check the distance to "player" (which is unique), not vice versa.
•     If you determine distance to an object you are moving with Move or MoveWorld, GetDistance will still report the distance to the original location of the object (the one you set in the editor). Use GetPos and good ol' Pythagoras (c2 = a2 + b2) to determine distances in these instances.
•     GetDistance won't work on disabled objects.