Aw object query

From ActiveWiki
Jump to navigation Jump to search


Minimum requirements
Added in version 4.2
SDKbuild 70


int aw_object_query (void)

Description

Queries the world for an object.

Callback

AW_CALLBACK_OBJECT_QUERY

Notes

The object to be queried can be specified in two ways. This is the old method for doing it:

  • AW_OBJECT_X is set to x coordinate of object (in cm's).
  • AW_OBJECT_Z is set to z coordinate of object (in cm's).
  • AW_OBJECT_NUMBER is set to object number (only unique for objects in the same cell).

which is only unique to all objects within the same cell).

There is also new method which was introduced in version 4.1:

Arguments

None

Argument attributes

AW_OBJECT_NUMBER
AW_OBJECT_X
AW_OBJECT_Z
AW_OBJECT_ID

Return values

RC_SUCCESS (1) (2)
RC_NOT_INITIALIZED (1)
RC_NO_INSTANCE (1)
RC_NO_CONNECTION (1)
The connection to the world is down.
RC_NO_SUCH_OBJECT (2)

(1) Possible return values when a callback is installed.

(2) Returned by the world server.

Returned attributes

AW_OBJECT_TYPE
AW_OBJECT_ID (1)
AW_OBJECT_NUMBER (2)
AW_OBJECT_OWNER
AW_OBJECT_BUILD_TIMESTAMP
AW_OBJECT_X (2)
AW_OBJECT_Y
AW_OBJECT_Z (2)
AW_OBJECT_YAW
AW_OBJECT_TILT
AW_OBJECT_ROLL
AW_OBJECT_MODEL
AW_OBJECT_DESCRIPTION
AW_OBJECT_ACTION
AW_OBJECT_DATA

(1) Only attribute returned for failed queries by AW_OBJECT_ID. All other attributes will be cleared.

(2) Only attributes returned for failed queries by AW_OBJECT_NUMBER, AW_OBJECT_X and AW_OBJECT_Z. All other attributes will be cleared. Note, returned coordinates will point to the cell instead of the object (still in cm's).

Usage

void query_object (int number, int x, int z)
{
  int rc;
  
  aw_int_set (AW_OBJECT_NUMBER, number);
  aw_int_set (AW_OBJECT_X, x);
  aw_int_set (AW_OBJECT_Z, z);
  
  rc = aw_object_query ();
  if (rc != RC_SUCCESS)
    printf ("Object query failed (reason %d)\n", rc);
  else
    printf ("Object owner is %d\n", aw_int (AW_OBJECT_OWNER));
}

void query_object_by_id (int id)
{
  int rc;
  
  aw_int_set (AW_OBJECT_ID, id);
  aw_int_set (AW_OBJECT_NUMBER, 0);
  
  rc = aw_object_query ();
  if (rc != RC_SUCCESS)
    printf ("Object query failed (reason %d)\n", rc);
  else
    printf ("Object owner is %d\n", aw_int (AW_OBJECT_OWNER));
}

See also