Difference between revisions of "GetNearestObject"

From NWN Lexicon
Jump to: navigation, search
(Created page with "=GetNearestObject(int, object, int)= Gets the nearest object, which matches given criteria, to the selected target. object  GetNearestObject(     [[...")
 
Line 3: Line 3:
 
Gets the nearest object, which matches given criteria, to the selected target.
 
Gets the nearest object, which matches given criteria, to the selected target.
  
 +
<nwscript>
 
  [[object | object ]] GetNearestObject(
 
  [[object | object ]] GetNearestObject(
 
      [[ object_type | OBJECT_TYPE_ALL ]],
 
      [[ object_type | OBJECT_TYPE_ALL ]],
Line 8: Line 9:
 
      [[int | int ]] nNth = 1
 
      [[int | int ]] nNth = 1
 
  );
 
  );
 +
</nwscript>
  
 
====Parameters====
 
====Parameters====
Line 43: Line 45:
 
====Example====
 
====Example====
  
<font color="#007f00">// This script is for a bar maid tagged "BAR_MAID".
+
<nwscript>
  </font><font color="#007f00">// The bar maid will find the third nearest door
+
// This script is for a bar maid tagged "BAR_MAID".
  </font><font color="#007f00">// and attempt to walk to it.
+
  // The bar maid will find the third nearest door
</font>
+
  // and attempt to walk to it.
  <font color="#0000ff">void</font> main
+
 
 +
  void main
 
  {
 
  {
       <font color="#007f00">// Initialize objects.
+
       // Initialize objects.
</font>    <font color="#0000ff">object</font> oBarMaid = GetObjectByTag(<font color="#00007f">"BAR_MAID"</font>);
+
      object oBarMaid = GetObjectByTag("BAR_MAID");
       <font color="#0000ff">object</font> oDoor = GetNearestObject(OBJECT_TYPE_DOOR, oBarMaid, <font color="#7f007f">3</font>)
+
       object oDoor = GetNearestObject(OBJECT_TYPE_DOOR, oBarMaid, 3)
       <font color="#007f00">// Bar maid walks to the third nearest door.
+
       // Bar maid walks to the third nearest door.
</font>    ActionForceMoveToObject(oDoor)
+
      ActionForceMoveToObject(oDoor)
 
  }
 
  }
 +
</nwscript>
  
 
====See Also====
 
====See Also====

Revision as of 20:43, 25 August 2012

GetNearestObject(int, object, int)

Gets the nearest object, which matches given criteria, to the selected target.

 [[object | object ]] GetNearestObject(
     [[ object_type | OBJECT_TYPE_ALL ]],
     [[object | object ]] oTarget = OBJECT_SELF,
     [[int | int ]] nNth = 1
 );

Parameters

nObjectType

OBJECT_TYPE_ALL )

oTarget

(Default: OBJECT_SELF)

nNth

(Default: 1)


Description

Get the Nth object nearest to oTarget that is of the specified type.
Return value on error: OBJECT_INVALID

The function returns the Nth (default is 1, i.e. nearest) object that matches specified type. By default ‘type’ is set to OBJECT_TYPE_ALL, therefore the function will return the Nth nearest valid object unless you specify a type in the form OBJECT_TYPE_* (see end of description for a complete list of valid object types). Also by default the oTARGET is equal to OBJECT_SELF but may be set to another object.

For example, the following script snippet would set object oNearestDoor to the third nearest door to the object oPC:
object oNearestDoor = GetNearestObject(OBJECT_TYPE_DOOR, oPC, 3)

List of available object types constants:
OBJECT_TYPE_ALL (default)
OBJECT_TYPE_AREA_OF_EFFECT
OBJECT_TYPE_CREATURE
OBJECT_TYPE_DOOR
OBJECT_TYPE_ITEM
OBJECT_TYPE_PLACEABLE
OBJECT_TYPE_STORE
OBJECT_TYPE_TRIGGER
OBJECT_TYPE_WAYPOINT



Remarks

It can only return objects in oTarget's area, as GetNearestObjectByTag does, and is intended behaviour.

Obviously, this also means Modules and Areas cannot return a valid value for this.


Version

1.22

Example

 // This script is for a bar maid tagged "BAR_MAID".
 // The bar maid will find the third nearest door
 // and attempt to walk to it.
 
 void main
 {
      // Initialize objects.
      object oBarMaid = GetObjectByTag("BAR_MAID");
      object oDoor = GetNearestObject(OBJECT_TYPE_DOOR, oBarMaid, 3)
      // Bar maid walks to the third nearest door.
      ActionForceMoveToObject(oDoor)
 }

See Also

functions: 

GetNearestObjectToLocation

constants: 

OBJECT_TYPE_* Constants



 author: Jason Simpson, editor: Jasperre