location / Location(object, vector, float)
location
A location has three components: the object ID of the area, a vector representing the position within the area, and a floating point number representing the facing. They can be newly defined using the function Location as noted below.
To check if a location is valid (for instance retrieving one with GetLocalLocation in a module which uses CreateArea dynamically) you should make sure the area is valid with GetIsObjectValid and that the position is within the area bounds (defaults to 0.0, 0.0, 0.0, but could also wander outside the given area if the area was resized somehow, check with GetAreaSize). The default orientation may be valid, but defaults to 0.0.
location lTarget = GetSpellTargetLocation(); // Retrieves the spell target location and puts it into lTarget
You can use LOCATION_INVALID for optional parameters in a function definition, eg: SetTarget(object oTarget, location lTarget = LOCATION_INVALID), but equivalency tests such as if (GetSpellTargetLocation() != LOCATION_INVALID) will not work.
Location(object, vector, float)
Set the value of a Location data structure.
location Location(
object oArea,
vector vPosition,
float fOrientation
);
Parameters
- oArea
- An Area within the game module
- vPosition
- An object specifying an xyz coordinate
- fOrientation
- An angular value between 0.0 and 360.0
Description
This function is a location constructor. A constructor is a special type of function whose purpose is to create a new instance of its type. A constructor is also where any special construction actions or initialization takes place. Its return type is a new object of the specified type, so in this case what we get back is a new object of type location.
In order to construct a new location object the script needs three things:
- The area the location is referenced in (this is the Area of the Module).
- A new vector containing the x, y and z coordinates of this location.
- A float representing the facing of the object from 0.0 to 360.0 where 0.0 = East, 90.0 = North, 180.0 = West, and 270.0 = South.
Remarks
As noted above, checking for a valid location (eg as a passed parameter or checking a GetLocalLocation value) you can check the area is valid and the position is within the bounds of the area.
For saving locations to SQLite storing the area OID and floats for the various values is the easiest method.
Example
// Locate the area we are in
object oArea = GetArea(OBJECT_SELF);
// Locate where in the are we are
vector vPosition = GetPosition(OBJECT_SELF);
// Identify the direction we are facing
float fOrientation = GetFacing(OBJECT_SELF);
// Create a new location with this information
location myLocation = Location(oArea, vPosition, fOrientation);
See Also
| functions: | vector float |
author: Ryan Hunt, editor: Lilac Soul, additional contributor(s): George Kuff, Lilac Soul