GetNearestObjectToLocation(int, location, int)

From NWN Lexicon
Jump to navigationJump to search

Returns the nearest object, which is of a specified type, to a given location.

object GetNearestObjectToLocation(
    int nObjectType,
    location lLocation,
    int nNth = 1
);

Parameters

nObjectType
Object type to find, an OBJECT_TYPE_* constant. More than one can be included with bitwise OR |
oTarget
Location to find a nearby object from.
nNth
The nNth thing to find (Default: 1)


Description

Get the nNth object nearest to lLocation that is of the specified type. You can 'or' several OBJECT_TYPE_* constants together using the bitwise | (or) operator. See code sample below.

Return value on error: OBJECT_INVALID


Remarks

It seems that this function returns OBJECT_INVALID if the location of the object is identical to the location passed to the function. In other words, if there is an object at the exact location that is fed into the function it will NOT be returned by the function. Simply put, the function does not consider an identical location to be the nearest location.


Known Bugs

1.64 made sure this function is now consistent - it will return the nearest objects every time it is called from the same location.


Version

1.64


Example

// Find the nearest creature, placeable, or item to the
// module's starting location.

void main()
{
    location lLoc = GetStartingLocation();

    object oTarget = GetNearestObjectToLocation(OBJECT_TYPE_CREATURE | OBJECT_TYPE_PLACEABLE | OBJECT_TYPE_ITEM, lLoc);
}

See Also

functions: 

GetObjectByTag, GetNearestObject, GetNearestCreature, GetNearestObjectByTag

constants: 

OBJECT_TYPE_* Constants



 author: Jason Simpson, editor: Jasperre, additional contributor(s): Lilac Soul, Heed, Jasperre