Difference between revisions of "Ambient behaviour"
BryanDerksen (Talk | contribs) (porting over from extranet) |
BryanDerksen (Talk | contribs) m (→Overriding Ambient Behaviour: minor formatting fix) |
||
Line 102: | Line 102: | ||
! Local Variable Name || Type || Default Value || Description | ! Local Variable Name || Type || Default Value || Description | ||
|- | |- | ||
− | AMBIENT_ANIM_PATTERN_OVERRIDE || | + | | 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. 0 = no animations. |
|- | |- | ||
− | | AMBIENT_ANIM_FREQ_OVERRIDE || | + | | 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 | | AMBIENT_ANIM_OVERRIDE_COUNT || int || || Used internally, do not modify | ||
|} | |} |
Revision as of 21:28, 27 June 2009
Contents
Overview
By default, a creature will begin or resume performing ambient behaviour when it perceives the player and cease performing ambient behaviour after the party has remained out of sight for 40 seconds. Ambient behaviour alternates between a movement phase and an animation phase. 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 on the creature template (see below). All other local variables on the creature template with the prefix AMBIENT_* are used internally by the ambient behaviour system (sys_ambient_h.nss) and should not be manually modified. Ambient behaviour is persisted when a game is saved and automatically resumes when a game is loaded.
Local Variables (var_creature)
Local Variable Name | Type | Default Value | Description |
---|---|---|---|
AMBIENT_SYSTEM_STATE | int | 0 | Bitmask controlling ambient system operation.
|
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. |
AMBIENT_COMMAND | int | 0 | Forces creatures to repeatedly perform a specific action.
|
AMBIENT_ANIM_STATE | int | Used internally, do not modify | |
AMBIENT_MOVE_COUNT | int | Used internally, do not modify | |
AMBIENT_MOVE_STATE | int | Used internally, do not modify | |
AMBIENT_TICK_COUNT | int | Used internally, do not modify |
ambient_ai.xls
The actions used in an animation phase are listed in 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 duration 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
Local Variable Name | Type | Default Value | 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. 0 = no animations. |
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 |