vp_object_load

From Virtual Paradise Wiki
Jump to navigation Jump to search
Method call snippet vp_object_load(instance);

Load a new object, overriding user id and timestamp.

Parameters

These are the parameters that this method requires:

Parameter Usage
VPInstance
instance
Pointer to the instance this method call is intended for

Used attributes

This method uses data set in these attributes when called:

Attribute Usage
VP_REFERENCE_NUMBER Is passed to the callback to identify for which method call it is fired
VP_OBJECT_TIME Creation time to put on object (in unix time, seconds since UTC 00:00:00, 1 January 1970)
VP_OBJECT_USER_ID User id to put on object
VP_OBJECT_TYPE Type of object (0 - 3D Model, 2 - Particle emitter, 3 - Path object)
VP_OBJECT_X X coordinate
VP_OBJECT_Y Y coordinate
VP_OBJECT_Z Z coordinate
VP_OBJECT_ROTATION_X Rotation X axis
VP_OBJECT_ROTATION_Y Rotation Y axis
VP_OBJECT_ROTATION_Z Rotation Z axis
VP_OBJECT_ROTATION_ANGLE Rotation angle in radians
VP_OBJECT_YAW Yaw angle in degrees (these are used instead of X,Y,Z axis when rotation angle is set to INFINITY)
VP_OBJECT_PITCH Pitch angle in degrees
VP_OBJECT_ROLL Roll angle in degrees
VP_OBJECT_MODEL Model
VP_OBJECT_ACTION Action
VP_OBJECT_DESCRIPTION Description
VP_OBJECT_DATA Data

Returns

This method returns a return code integer, which indicates whether the call was successful or errored for any reason:

Return code Cause
VP_RC_SUCCESS Successful call (for methods that have a registered callback, it only means the request has been sent)
VP_RC_NOT_IN_WORLD Bot is not currently in a world
VP_RC_NOT_ALLOWED Instance does not have the permission to load objects.
VP_RC_DATABASE_ERROR Unspecified database error

The following attributes will be returned in VP_CALLBACK_OBJECT_LOAD if the operation was successful:

Attribute Usage Also returned for
VP_OBJECT_ID Object id that was assigned to the new object

Behavior

  • Upon successful creation of an object, VP_EVENT_OBJECT is triggered for those who have subscribed to it. See vp_event_set().
  • If VP_OBJECT_ROTATION_ANGLE is set to INFINITY then it will be stored as that in world. The euler angles will be not be converted to an equivalent axis-angle representation. See examples in vp_object_add() for euler to axis-angle conversion code.

Caveats

  • Setting VP_OBJECT_USER_ID to 0 will not default it to the owner of the bot (it will be set to user id #0).
  • Setting VP_OBJECT_TIME to 0 will not default it to current time (it will be set to unix time 0, that is 00:00:00, 1 January 1970).

Examples

Load a street1.rwx object at 0X 0Y 0Z.

void handle_object_load(VPInstance sdk, int rc, int ref)
{
  if (rc)
    printf("Couldn't load object (reason %d)\n", rc);
  else
    printf("Object loaded successfully!\n");
}

int main(int argc, const char* argv[])
{
  //...
  
  vp_callback_set(sdk, VP_CALLBACK_OBJECT_LOAD, handle_object_load);

  vp_int_set(sdk, VP_OBJECT_TYPE, 0); // 3D Model
  vp_int_set(sdk, VP_OBJECT_USER_ID, 1234); // Owner #1234
  vp_int_set(sdk, VP_OBJECT_TIME, time(NULL) - 3600); // One hour ago
  vp_float_set(sdk, VP_OBJECT_X, 0.0);
  vp_float_set(sdk, VP_OBJECT_Y, 0.0);
  vp_float_set(sdk, VP_OBJECT_Z, 0.0);
  vp_float_set(sdk, VP_OBJECT_ROTATION_X, 0.0);
  vp_float_set(sdk, VP_OBJECT_ROTATION_Y, 0.0);
  vp_float_set(sdk, VP_OBJECT_ROTATION_Z, 0.0);
  vp_float_set(sdk, VP_OBJECT_ROTATION_ANGLE, 0.0);
  vp_string_set(sdk, VP_OBJECT_MODEL, "street1.rwx");
  vp_string_set(sdk, VP_OBJECT_ACTION, "");
  vp_string_set(sdk, VP_OBJECT_DESCRIPTION, "");
	
  rc = vp_object_load(sdk);
  if (rc)
    printf("Couldn't load object (reason %d)\n", rc);

  //...
}

See also