GetAreaSize(int, object)

From NWN Lexicon
Jump to navigationJump to search

Gets the size of the area measured in tiles.

int GetAreaSize(
    int nAreaDimension,
    object oArea


The area dimension that you wish to determine (AREA_* constant - AREA_HEIGHT or AREA_WIDTH).
The area that you wish to get the size of.


Gets the size of the area measured in tiles.

Specifying AREA_HEIGHT in the nAreaDimension parameter causes the function to return the height of oArea.

Using AREA_WIDTH there causes the function to the width of oArea.

An invalid area or wrong nAreaDimension value will return 0.


The function returns the number of tiles that the area is wide/high, or zero on an error. If no valid area (or object) is specified, it uses the area of the caller. If an object other than an area is specified, it will use the area that the object is currently in.

One tile = 10.0 meters




// Generate a random location in an area based on the area's size.

void main()
    //  Determine the area to generate the location in.
    object oArea = GetObjectByTag("Area_Tag");
    // If a valid area was found, compute the random location.
      // Determine the width and height of the area in tiles.
      int iWidthInTiles  = GetAreaSize(AREA_WIDTH,  oArea);
      int iHeightInTiles = GetAreaSize(AREA_HEIGHT, oArea);
      // Convert the width and height from tiles into meters.
      int iWidthInMeters  = iWidthInTiles  * 10;
      int iHeightInMeters = iHeightInTiles * 10;
      // Generate a random position in the area.
      float  fXPosition = IntToFloat(Random(iWidthInMeters  * 10)) / 10.0;
      float  fYPosition = IntToFloat(Random(iHeightInMeters * 10)) / 10.0;
      float  fZPosition = 0.0;
      vector vRandomPos = Vector(fXPosition, fYPosition, fZPosition);
      // Convert the random position to obtain the random location.
      float    fFacing = 0.0;
      location lRandom = Location(oArea, vRandomPos, fFacing);

See Also





author: bernosky, editor: Mistress, contributor: Axe Murderer