vp_terrain_node_set

From Virtual Paradise Wiki
Revision as of 23:29, 31 July 2018 by Sleepy E (talk | contribs) (Added reference number attribute)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
Method call snippet vp_terrain_node_set(instance, tile_x, tile_z, node_x, node_z, cells);

Replace terrain node data.

Parameters

These are the parameters that this method requires:

Parameter Usage
VPInstance
instance
Pointer to the instance this method call is intended for
int
tile_x
Tile X coordinate (with no terrain scaling, divide coordinates in decameter by 32 to get tile coordinates)
int
tile_z
Tile Z coordinate
int
node_x
Node X coordinate (within tile, 0 to 3)
int
node_z
Node Z coordinate
vp_terrain_cell_t*
cells
Pointer to 64 cells (8x8: cells[z*8+x])

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

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

Behavior

Examples

/*
 * Set the height of the terrain node containing the terrain cell coordinate x, z (Note: it will reset the texture, rotation and hole flag!)
 */

int tile_from_cell(int val)
{
  return val < 0 ? (val - 32) / 32 : val / 32;
}

void set_terrain_node_height(VPInstance sdk, int x, int z, float height)
{
  int tile_x, tile_z;

  tile_x = tile_from_cell(x);
  tile_z = tile_from_cell(z);

  int node_x, node_z;

  if (node_x < 0)
    node_x -= 8;

  node_x = (x % 32) / 8;

  if (node_z < 0)
    node_z -= 8;

  node_z = (z % 32) / 8;

  struct vp_terrain_cell_t cells[64];

  memset(cells, 0, sizeof(cells));

  for (int i = 0; i < 64; i++)
    cells[i].height = height;

  vp_terrain_node_set(sdk, tile_x, tile_z, node_x, node_z, cells);
}

See also