Difference between revisions of "Ambient behaviour"
Axe Murderer (Talk | contribs) (Same paragraph appearing twice. Got rid of one.) |
Axe Murderer (Talk | contribs) m (→Local Variables (var_creature): Incorrect information, someone verify my assumption that PATROL == palindrome order is proper) |
||
Line 18: | Line 18: | ||
* 5 (AMBIENT_MOVE_WANDER): Move to random location within 10m of home location | * 5 (AMBIENT_MOVE_WANDER): Move to random location within 10m of home location | ||
* 6 (AMBIENT_MOVE_WANDER_FAR): Move to random location within 30m of home location | * 6 (AMBIENT_MOVE_WANDER_FAR): Move to random location within 30m of home location | ||
− | * 7 (AMBIENT_MOVE_PATH_PATROL): Patrol all waypoints using [[CommandMoveToMultiLocations]] (1,2,3 | + | * 7 (AMBIENT_MOVE_PATH_PATROL): Patrol all waypoints using [[CommandMoveToMultiLocations]] (1,2,3,2,1,...) |
* 8 (AMBIENT_MOVE_PATH_LOOP): Loop through all waypoints using [[CommandMoveToMultiLocations]] (1,2,3. 1,2,3) | * 8 (AMBIENT_MOVE_PATH_LOOP): Loop through all waypoints using [[CommandMoveToMultiLocations]] (1,2,3. 1,2,3) | ||
* 9 (AMBIENT_MOVE_ONCE): Walk through the waypoint set once (1-2-3)}} | * 9 (AMBIENT_MOVE_ONCE): Walk through the waypoint set once (1-2-3)}} |
Revision as of 17:52, 27 November 2009
Ambient behaviour begins when the player moves within 50m of a creature and ceases when the player remains more than 50m away for at least 40s. Ambient behaviour alternates between a movement phase and an animation phase, simulating a bubble of activity around the player. In a movement phase, the creature (optionally) moves to a new destination (typically a waypoint but it could be any object) and turns to face the same direction as the destination object. In an animation phase, the creature (optionally) performs one or more animations either in sequence or at random. Exact behaviour is controlled by local variables set on either the creature instance or template (see table below). All other local variables with the prefix AMBIENT_* are used internally by the ambient behaviour system (see script sys_ambient_h.nss) and should not be manually modified. Never directly modify AMBIENT_* local variables at run time using SetLocalInt - always use the functions Ambient_Start, Ambient_Stop, Ambient_OverrideBehaviour, and Ambient_RestoreBehaviour instead. Ambient behaviour is persisted when a game is saved and automatically resumes when a game is loaded.
Contents
Local Variables (var_creature)
Variable name | Type | Default | Description |
---|---|---|---|
AMBIENT_SYSTEM_STATE | int | 0 | Bitmask controlling ambient system operation. (ergo, values below are in hexadecimal).
|
AMBIENT_MOVE_PATTERN | int | 0 | Dictates how the creature moves. Add 100 to the values below make creature run instead of walk.
|
AMBIENT_MOVE_PREFIX | string | ap_<tag> | The prefix used to determine the waypoints the creature can travel to. Note that <tag> is a placeholder filled in at run-time with the tag of the creature. Hence, for example, if AMBIENT_MOVE_PREFIX is ap_<tag> and the creature's tag is cr_dog then the system will look for waypoints with tags ap_cr_dog_01, ap_cr_dog_02, etc. If no waypoint is found with the _01 extension, the system will search instead for all waypoints with tags matching the AMBIENT_MOVE_PREFIX value exactly (i.e. ap_cr_dog). This is useful in cases where you just want to add N waypoints all with the same tag. |
AMBIENT_ANIM_PATTERN | int | 0 | Index into ambient_ai.xls. Specifies the list of possible actions the creature can/will perform during an animation phase.
|
AMBIENT_ANIM_FREQ | float | -1.0 | Animation frequency. The part left of the decimal specifies the minimum and the part right of the decimal specifies the maximum number of random animations to play during an animation phase. So, for example, a value of 1.3 will play between 1 and 3 random animations from the animation pattern listed in ambient_ai.xls. A value of -1.0 plays all animations in the animation pattern in the order they are listed in ambient_ai.xls. Animation pattens that are highlighted in green on the worksheeet should always be played in order (i.e. AMBIENT_ANIM_FREQ is -1.0). |
AMBIENT_COMMAND | int | 0 | If non-zero, this value forces the creature to perform a specific command (instead of moving and animating).
|
AMBIENT_ANIM_PATTERN_OVERRIDE | int | 0 | Overrides AMBIENT_ANIM_PATTERN if non-zero. |
AMBIENT_ANIM_FREQ_OVERRIDE | int | 0 | Overrides AMBIENT_ANIM_FREQ if non-zero. |
AMBIENT_ANIM_STATE | int | 0 | Internal use by ambient behaviour system. Tracks number of animations left to play. |
AMBIENT_MOVE_COUNT | int | -1 | Internal use by ambient behaviour system. Tracks total number of destination points for a creature. |
AMBIENT_MOVE_STATE | int | 0 | Internal use by ambient behaviour system. Tracks the last waypoint creature moved to and direction of travel. |
AMBIENT_TICK_COUNT | int | 0 | Used internally, do not modify |
AMBIENT_ANIM_OVERRIDE_COUNT | int | 0 |
ambient_ai.xls
The actions used in an animation phase are listed in the ambient_anim_patterns worksheet of ambient_ai.xls. Each row defines an animation pattern, consisting of up to thirteen actions. Each action is composed of an animation (left of the decimal) and the number of loops it is played (right of decimal). For example, 619.02 will play a sleeping loop animation twice and 619.99 will play an infinitely looping sleeping animation. Non-looping animations require no loop-count (i.e. decimal) component. The list of all available animations is located in ANIM_base.xls.
sys_ambient_h
The script sys_ambient_h contains the implementation of the ambient behaviour system. The AMBIENT_* local variables should never be directly modified at run-time. Instead, use the following functions to customize a creature's ambient behaviour through script.
// Normally this function is called automatically to begin or resume ambient behaviour when a // creature perceives the player. However, it can be called explicitly to force a creature to begin // performing ambient behaviour or, if nAmbientEnable is 1, to enable ambient behaviour on a creature. void Ambient_Start(object oCreature = OBJECT_SELF, int nAmbientEnable = 0, int nMovePattern = 0, string sMovePrefix = ""); // Normally this function is called automatically to pause ambient behaviour after the party has // been out of the creature's sight for a while. However, this function can be used to force a // creature to temporarily cease ambient behaviour. Note that the creature will automatically // resume ambient behaviour when it perceives the player again. void Ambient_Pause(object oCreature = OBJECT_SELF, int bCheckVisibility = TRUE); // Turns off ambient behaviour on a creature. The creature will resume ambient behaviour only // after Ambient_Start() is called. void Ambient_Stop(object oCreature = OBJECT_SELF); // Overrides the ambient animation pattern and animation frequency defined by the creature's template. void Ambient_OverrideBehaviour(object oCreature, int nAnimPattern, float fAnimFreq); // Restores a creature's ambient animation behaviour to that defined in the creature's template. void Ambient_RestoreBehaviour(object oCreature);
Overriding Ambient Behaviour
Variable name | Type | Default | Description |
---|---|---|---|
AMBIENT_ANIM_PATTERN_OVERRIDE | int | 0 | Index into ambient_ai.xls. Specifies the list of possible actions the creature can/will perform during an animation phase.
|
AMBIENT_ANIM_FREQ_OVERRIDE | float | -1.0 | Animation frequency. The portion left of decimal specifies the minimum and the portion right of the decimal specifies the maximum number of animations to play during an animation phase. A value of -1.0 plays all animations in the animation pattern in the order listed in ambient_ai.xls. |
AMBIENT_ANIM_OVERRIDE_COUNT | int | Used internally, do not modify |