AIPlayer

consoledoc.h

A Player object not controlled by conventional input, but by an AI engine.

More...

AI

float

Distance from destination before stopping.

float

Distance tolerance on stuck check.

int

The number of ticks to wait before testing if the AIPlayer is stuck.

float

Distance considered in firing range for callback purposes.

Pathfinding

bool

Allow the character to walk on dry land.

bool

Allow the character to use jump links.

bool

Allow the character to use drop links.

bool

Allow the character to move in water.

bool

Allow the character to jump ledges.

bool

Allow the character to use climb links.

bool

Allow the character to use teleporters.

Public Static Attributes

bool

Disables rendering of all instances of this type.

bool

Disables selection of all instances of this type.

Public Functions

bool
checkInFoV(ShapeBase obj, float fov, bool checkEnabled)

Check whether an object is within a specified veiw cone. @obj Object to check. (If blank, it will check the current target). @fov view angle in degrees.(Defaults to 45) @checkEnabled check whether the object can take damage and if so is still alive.(Defaults to false)

bool
checkInLos(ShapeBase obj, bool useMuzzle, bool checkEnabled)

Check whether an object is in line of sight. @obj Object to check. (If blank, it will check the current target). @useMuzzle Use muzzle position. Otherwise use eye position. (defaults to false). @checkEnabled check whether the object can take damage and if so is still alive.(Defaults to false)

void

Use this to stop aiming at an object or a point.

void
clearMoveTrigger(uint slot)

Clears a movement trigger on an AI object.

void

Clear ALL movement triggers on an AI object.

int
findCover(Point3F from, float radius)

Tells the AI to find cover nearby.

int

Get the NavMesh object this AIPlayer is currently using.

void
followNavPath(SimObjectId obj)

Tell the AIPlayer to follow a path.

void
followObject(SimObjectId obj, float radius)

Tell the AIPlayer to follow another object.

Point3F

Returns the point the AIPlayer is aiming at.

int

Gets the object the AIPlayer is targeting.

int

Get the object's current AiPose.

Point3F

Get the AIPlayer's current destination.

float

Gets the move speed of an AI object.

bool
getMoveTrigger(uint slot)

Tests if a movement trigger on an AI object is set.

int

Return the NavMesh this AIPlayer is using to navigate.

string

Return the size of NavMesh this character uses for pathfinding.

Point3F

Get the AIPlayer's current pathfinding destination.

float
getTargetDistance(ShapeBase obj, bool checkEnabled)

The distance to a given object. @obj Object to check. (If blank, it will check the current target). @checkEnabled check whether the object can take damage and if so is still alive.(Defaults to false)

void

Tells the AI to re-plan its path. Does nothing if the character has no path, or if it is following a mission path.

void
setAimLocation(Point3F target)

Tells the AIPlayer to aim at the location provided.

void
setAimObject(GameBase targetObject, Point3F offset)

Sets the AIPlayer's target object. May optionally set an offset from target location.

void
setAiPose(int pose)

Sets the AiPose for an AI object.

void
setMoveDestination(Point3F goal, bool slowDown)

Tells the AI to move to the location provided.

void
setMoveSpeed(float speed)

Sets the move speed for an AI object.

void
setMoveTrigger(uint slot)

Sets a movement trigger on an AI object.

void
setNavSize(string size)

Set the size of NavMesh this character uses. One of "Small", "Regular" or "Large".

bool
setPathDestination(Point3F goal)

Tells the AI to find a path to the location provided.

void
stop()

Tells the AIPlayer to stop moving.

Detailed Description

A Player object not controlled by conventional input, but by an AI engine.

The AIPlayer provides a Player object that may be controlled from script. You control where the player moves and how fast. You may also set where the AIPlayer is aiming at – either a location or another game object.

The AIPlayer class does not have a datablock of its own. It makes use of the PlayerData datablock to define how it looks, etc. As the AIPlayer is an extension of the Player class it can mount objects and fire weapons, or mount vehicles and drive them.

While the PlayerData datablock is used, there are a number of additional callbacks that are implemented by AIPlayer on the datablock. These are listed here:

void onReachDestination(AIPlayer obj) Called when the player has reached its set destination using the setMoveDestination() method. The actual point at which this callback is called is when the AIPlayer is within the mMoveTolerance of the defined destination.

void onMoveStuck(AIPlayer obj) While in motion, if an AIPlayer has moved less than moveStuckTolerance within a single tick, this callback is called. From here you could choose an alternate destination to get the AIPlayer moving again.

void onTargetEnterLOS(AIPlayer obj) When an object is being aimed at (following a call to setAimObject()) and the targeted object enters the AIPlayer's line of sight, this callback is called. The LOS test is a ray from the AIPlayer's eye position to the center of the target's bounding box. The LOS ray test only checks against interiors, statis shapes, and terrain.

void onTargetExitLOS(AIPlayer obj) When an object is being aimed at (following a call to setAimObject()) and the targeted object leaves the AIPlayer's line of sight, this callback is called. The LOS test is a ray from the AIPlayer's eye position to the center of the target's bounding box. The LOS ray test only checks against interiors, statis shapes, and terrain.

// Create the demo player object
%player = new AiPlayer()
{
  dataBlock = DemoPlayer;
  path = "";
};

see:

Player for a list of all inherited functions, variables, and base description

AI

float mMoveTolerance 

Distance from destination before stopping.

When the AIPlayer is moving to a given destination it will move to within this distance of the destination and then stop. By providing this tolerance it helps the AIPlayer from never reaching its destination due to minor obstacles, rounding errors on its position calculation, etc. By default it is set to 0.25.

float moveStuckTolerance 

Distance tolerance on stuck check.

When the AIPlayer is moving to a given destination, if it ever moves less than this tolerance during a single tick, the AIPlayer is considered stuck. At this point the onMoveStuck() callback is called on the datablock.

int moveStuckTestDelay 

The number of ticks to wait before testing if the AIPlayer is stuck.

When the AIPlayer is asked to move, this property is the number of ticks to wait before the AIPlayer starts to check if it is stuck. This delay allows the AIPlayer to accelerate to full speed without its initial slow start being considered as stuck.

note:

Set to zero to have the stuck test start immediately.

float AttackRadius 

Distance considered in firing range for callback purposes.

Pathfinding

bool allowWalk 

Allow the character to walk on dry land.

bool allowJump 

Allow the character to use jump links.

bool allowDrop 

Allow the character to use drop links.

bool allowSwim 

Allow the character to move in water.

bool allowLedge 

Allow the character to jump ledges.

bool allowClimb 

Allow the character to use climb links.

bool allowTeleport 

Allow the character to use teleporters.

Public Static Attributes

bool isRenderable 

Disables rendering of all instances of this type.

bool isSelectable 

Disables selection of all instances of this type.

Public Functions

checkInFoV(ShapeBase obj, float fov, bool checkEnabled)

Check whether an object is within a specified veiw cone. @obj Object to check. (If blank, it will check the current target). @fov view angle in degrees.(Defaults to 45) @checkEnabled check whether the object can take damage and if so is still alive.(Defaults to false)

checkInLos(ShapeBase obj, bool useMuzzle, bool checkEnabled)

Check whether an object is in line of sight. @obj Object to check. (If blank, it will check the current target). @useMuzzle Use muzzle position. Otherwise use eye position. (defaults to false). @checkEnabled check whether the object can take damage and if so is still alive.(Defaults to false)

clearAim()

Use this to stop aiming at an object or a point.

clearMoveTrigger(uint slot)

Clears a movement trigger on an AI object.

Parameters:

slot

The trigger slot to set.

clearMoveTriggers()

Clear ALL movement triggers on an AI object.

findCover(Point3F from, float radius)

Tells the AI to find cover nearby.

Parameters:

from

Location to find cover from (i.e., enemy position).

radius

Distance to search for cover.

return:

Cover point ID if cover was found, -1 otherwise.

findNavMesh()

Get the NavMesh object this AIPlayer is currently using.

return:

The ID of the NavPath object this character is using for pathfinding. This is determined by the character's location, navigation type and other factors. Returns -1 if no NavMesh is found.

followNavPath(SimObjectId obj)

Tell the AIPlayer to follow a path.

Parameters:

obj

ID of a NavPath object for the character to follow.

followObject(SimObjectId obj, float radius)

Tell the AIPlayer to follow another object.

Parameters:

obj

ID of the object to follow.

radius

Maximum distance we let the target escape to.

getAimLocation()

Returns the point the AIPlayer is aiming at.

This will reflect the position set by setAimLocation(), or the position of the object that the bot is now aiming at. If the bot is not aiming at anything, this value will change to whatever point the bot's current line-of-sight intercepts.

return:

World space coordinates of the object AI is aiming at. Formatted as "X Y Z".

getAimObject()

Gets the object the AIPlayer is targeting.

return:

Returns -1 if no object is being aimed at, or the SimObjectID of the object the AIPlayer is aiming at.

getAiPose()

Get the object's current AiPose.

return:

StandPose=0, CrouchPose=1, PronePose=2, SprintPose=3.

getMoveDestination()

Get the AIPlayer's current destination.

return:

Returns a point containing the "x y z" position of the AIPlayer's current move destination. If no move destination has yet been set, this returns "0 0 0".

getMoveSpeed()

Gets the move speed of an AI object.

return:

A speed multiplier between 0.0 and 1.0.

getMoveTrigger(uint slot)

Tests if a movement trigger on an AI object is set.

Parameters:

slot

The trigger slot to check.

return:

a boolean indicating if the trigger is set/unset.

getNavMesh()

Return the NavMesh this AIPlayer is using to navigate.

getNavSize()

Return the size of NavMesh this character uses for pathfinding.

getPathDestination()

Get the AIPlayer's current pathfinding destination.

return:

Returns a point containing the "x y z" position of the AIPlayer's current path destination. If no path destination has yet been set, this returns "0 0 0".

getTargetDistance(ShapeBase obj, bool checkEnabled)

The distance to a given object. @obj Object to check. (If blank, it will check the current target). @checkEnabled check whether the object can take damage and if so is still alive.(Defaults to false)

repath()

Tells the AI to re-plan its path. Does nothing if the character has no path, or if it is following a mission path.

setAimLocation(Point3F target)

Tells the AIPlayer to aim at the location provided.

Parameters:

target

An "x y z" position in the game world to target.

setAimObject(GameBase targetObject, Point3F offset)

Sets the AIPlayer's target object. May optionally set an offset from target location.

Parameters:

targetObject

The object to target

offset

Optional three-element offset vector which will be added to the position of the aim object.

// Without an offset
%ai.setAimObject(%target);

// With an offset
// Cause our AI object to aim at the target
// offset (0, 0, 1) so you don't aim at the target's feet
%ai.setAimObject(%target, "0 0 1");

setAiPose(int pose)

Sets the AiPose for an AI object.

Parameters:

pose

StandPose=0, CrouchPose=1, PronePose=2, SprintPose=3. Uses the new AiPose variable from shapebase (as defined in its PlayerData datablock).

setMoveDestination(Point3F goal, bool slowDown)

Tells the AI to move to the location provided.

Parameters:

goal

Coordinates in world space representing location to move to.

slowDown

A boolean value. If set to true, the bot will slow down when it gets within 5-meters of its move destination. If false, the bot will stop abruptly when it reaches the move destination. By default, this is true.

note:

Upon reaching a move destination, the bot will clear its move destination and calls to getMoveDestination will return "0 0 0".

setMoveSpeed(float speed)

Sets the move speed for an AI object.

Parameters:

speed

A speed multiplier between 0.0 and 1.0. This is multiplied by the AIPlayer's base movement rates (as defined in its PlayerData datablock)

setMoveTrigger(uint slot)

Sets a movement trigger on an AI object.

Parameters:

slot

The trigger slot to set.

setNavSize(string size)

Set the size of NavMesh this character uses. One of "Small", "Regular" or "Large".

setPathDestination(Point3F goal)

Tells the AI to find a path to the location provided.

Parameters:

goal

Coordinates in world space representing location to move to.

return:

True if a path was found.

stop()

Tells the AIPlayer to stop moving.