User Tools

Site Tools


cerea2:build:ambient

Ambinent animations

Creatures will walk waypoints regardless of the Spec variable. They will default on walking back to the spawn point unless something else is defined. To disable walking set the “NoWalk” variable to 1 on the creature (see Creatures)

See avatar page for more information how the avatar system works and what variables it sets to avatar creatures and how it uses this ambient walkwaypoint system.

Walking of waypoints

The basic idea is that creatures start walking from one waypoint to another and in the last waypoint it decides whether it needs to walk back using waypoints in the reverse order, or whether to go to the first waypoint and start over. The waypoint names used are WP_xxxx_nn or WN_xxxx_nn. The creature can also have WP_xxxx, WN_xxxx, POST_xxxx and NIGHT_xxxx waypoints, but those are only for backward compatibility and those waypoints do not support walking, or animations etc. The nn is number from 01 to 99. The xxxx is normally the tag of the creature, but in case the creature has variable WalkTag set then that is used instead of creature tag. This allows multiple creatures sharing the same waypoint list and still having unique tags (as required by the cerea2 system).

Note that waypoints without nn part do not support all features of the walk waypoint system, i.e. for example WP_SCRIPT, animations etc things do not work for them. It is always best to use the waypoint names with nn part even if there is only one waypoint (_01).

If there is “WADD_01”, “WADD_02” … “WADD_99” integer and string variables set those are used to set additional waypoint routes in to the creature. I.e. “WADD_01” integer value is used as a start point (waypoint index), and the “WADD_01” string value is used as a first tag for that path. This way additional paths can be added to the waypoint, which can be then selected later by jump or conditional wp points. Each of those are made to be loop (either by walking waypoint backwards back to start location, or looping from last to first wp in case those are close enough). If there is “WADD_NEXT_01”, “WADD_NEXT_02” … “WADD_NEXT_99” integer is set, then the waypoint list is assumed to be unidirectional, and after it is walked once, the next waypoint index is set to be value of that integer.

If you want to get speed and so on right, the WADD_NEXT_xx should point to the waypoint that is already defined before this, i.e. either to normal day or night waypoint sets (1, 900, 1000, 1900) or one of the WADD_yy where yy is smaller than xx.

I.e. if WADD_01 is set to “VESPER_GUARD_PATROL_”, and WADD_01 is set to 500 and WADD_NEXT_01 is set to 1, that means we have special waypoint path starting from index 500 following “VESPER_GUARD_PATROL_01” path and after doing that (for example walking around the vesper), it will jump back to the waypoint index 1 (i.e start of guards own waypoint path). Now if guard just has WP_xxxx waypoint (no path, just one waypoint), and that waypoint has variable “WP_SCRIPT” set to call to suitable script checking the time, and if hour has changed, it will call C_WalkSetNext(OBJECT_SELF, 500), otherwise it will call C_WalkPause(OBJECT_SELF, 60). This way the guard starts walking the VESPER_GUARD_PATROL_“ path every hour, and rest of the time it will stay in his current post location.

If there is WD2N_xxxx_nn waypoint set, then that is used when the night comes to move from the day waypoint set to the night waypoint set. The system will select the closest waypoint from the WD2N_ or normal night waypoint set and move to there, and follow that to the end. When it finally gets to the end it will jump to the first night waypoint (waypoint number 1000). This waypoint is stored starting waypoint number from 1900.

If there is WN2D_xxxx_nn waypoint set, then that is used when the day comes to move from the night waypoint set to the day waypoint set. The system will select the closest waypoint from the WN2D_ or normal day waypoint set and move to there, and follow that to the end. When it finally gets to the end it will jump to the first day waypoint (waypoint number 1). This waypoint is stored starting waypoint number from 900.

Also any waypoint can have WP_NEXT_xxxx and WP_PREV_xxxx string variables specifying the tags of waypoints and those will be used for that creature when walking waypoints instead of the nn+1 and nn-1 when walking waypoints or walking back waypoints (this allows using slightly different route on way back without adding lots of more waypoints). Those variables can also be stored on the creature in a form of WP_NEXT_yyyy and WP_PREV_yyyy where the yyyy is the waypoint whose next or previous waypoint needs to be overriden. WP_NEXT and WP_PREV without tags can also be put to the waypoint itself, so that will be used for any other creatures which do not have other next/prev waypoints set.

Also any waypoint can have WP_RUN_NEXT_xxxx and WP_RUN_PREV_xxxx int variables specifying that the next leg should use running speed instead of walking speed. Those variables can also be stored on the creature in form of WP_RUN_NEXT_yyyy and WP_RUN_PREV_yyyy where yyyy is the waypoint tag. The WP_RUN_NEXT and WP_RUN_PREV can be also put to the waypoint without tag of the creature. If WP_RUN is set on the creature then creature runs between all waypoints.

If the override is used then it is used as new base and the last number there is either incremented or decremented (if going backward) until no more waypoints of that base is found. After that we return back to the previous base tag value and continue from the next index there unless WP_JUMP_NEXT_xxxx or WP_JUMP_PREV_xxxx are set in the waypoint or WP_JUMP_NEXT_yyyy or WP_JUMP_PREV_yyyy was set in the creature to have value 1 (integer). Those variables can also be stored to waypoint without tags, i.e. WP_JUMP_NEXT or WP_JUMP_PREV. If those variables are set then the override acts as jump, not as subroutine, meaning that when that path is finished we do not continue the current path.

If there is string variable WP_SCRIPT_NEXT_xxxx or WP_SCRIPT_PREV_xxxx in the waypoint or WP_SCRIPT_NEXT_yyyy or WP_SCRIPT_PREV_yyyy in the creature, then it is assumed to be script that is called at that point (for the creature) and it is assumed to call C_WalkSetNext function to set the next waypoint. Waypoint can also have WP_SCRIPT_NEXT, WP_SCRIPT_PREV or WP_SCRIPT string variables which are used by all creatures at that point.

Note that it needs to set the walkpoint numbers in the proper range (0..999 for day, and 1000..1999 for night, or 2000.. for day or night), otherwise the walk waypoint system will automatically switch to correct night / day path.

Note also that script is only called AFTER the creature has reached the waypoint, and have done all animations etc, and just before it is starting to walk to the next waypoint (i.e. the script is used to select next waypoint).

Example

xxxx = cr_tk_foo

Variable on cr_tk_foo Value
WP_NEXT_WP_cr_tk_foo_04 cw_tk_guard_01
WP_NEXT_cw_tk_guard_20 WP_cr_tk_foo_05
Waypoint tag Description
WP_cr_tk_foo_01 Default starting location of creature cr_tk_foo.
WP_cr_tk_foo_02 Route for cr_tk_foo from start location to
WP_cr_tk_foo_03 the location where the guard route starts.
WP_cr_tk_foo_04 The end of the unique route for cr_tk_foo
cw_tk_guard_01 Guard route around the perimiter _01 .. _20
cw_tk_guard_20 End of the guard route, about same as cw_tk_guard_01.
WP_cr_tk_foo_05 Route back from guard location to the start place.
WP_cr_tk_foo_06 This overlaps WP_cr_tk_foo_04/03/02/01.
WP_cr_tk_foo_07
WP_cr_tk_foo_08 This is very close to the WP_cr_tk_foo_01.

Animations on waypoints

Each waypoint can have ACTION or ACTION_xxxx string variable which specifies the animation string for that waypoint. The creature can have ACTION_yyyy where yyyy is the tag of the waypoint whose animation it want's to override. The string contains semicolon separated list of items each having comma or slash separated items. If used in item properties, you must use slash as a separator between items, as comma is reserved for the toplevel. Comma can be used in the waypoints, but in there it might be preffable to use slash so it can be easily copy&pasted to the item power.

The first item is always the type of action, i.e. “animation”, “facing”, “stealth”, “detect”, “parry”, “power attack”, “improved power attack”, “counterspell”, “flurry of blows”, “rapid shot”, “combat expertise”, “improved combat expertise”, “defensive cast”, “dirty fighting”, “orient on dialog”, “bumpable”, “cast”, “attack”, “walk”, “run”, “follow”, “rest”, “destroyitem”, “createitem”, “equip”, “unequip”, “drop”, “pickup”, “open”, “close”, “lock”, “unlock”, “placeable open”, “placeable close”, “placeable lock”, “placeable unlock”, “sound”, “pause”, “speak”, “voice”, “set local int”, “set local string”, “set local float” or ”#“ (comment).

For the animations the second item is always the duration of the animation (float). If this is looping animation then this is given as duration, if this is non looping (i.e. fire and forget type animation) then this is the time when next animation is played. The third argument is either number matching ANIMATION_* items in the nwscript.nss or the string if using custom animation (name of the gr2 file). The fourth argument is the float value specifying the speed of the animation. It defaults to 1.0 if not given. At least for custom animations the -1.0 plays animation backwards (FIXME not sure if that works for normal animations, check this later).

In case it is custom animation then the optional last argument specifies whether it is looping animation (1) or whether it is only run once (0).

For facing there is two optional arguments. The first argument specifies the duration of the turn (i.e. how long to wait before going to next action). This defaults to 1.0 second. The second argument specifies the direction where to set facing either as absolute number(0-359 degrees) or as relative to the waypoint with a +/- before the number (+/- 0 to 359 degrees ) or relative to current facing with a @ sign (@+/- 0 to 359 degrees), it defaults to the direction of the waypoint.

For “detect”, “stealth”, “parry”, “power attack”, “improved power attack”, “counterspell”, “flurry of blows”, “rapid shot”, “combat expertise”, “improved combat expertise”, “defensive cast”, “dirty fighting”, “orient on dialog”, “unbumpable” there is one argument which specifies whether the mode is enabled (1, default) or not (0).

For cast the second argument is the spell to cast. Third argument is fake casting 1 to fakecast 0 to cast for real. Fourth argument is cheatcasting 1 to cheat(do not need to have the spell) 0 to not cheat. Fifth argument either target tag or the word “self”. For “self” the target of the spell is the caster. The spell is then cast either at the target or the relative location.

For attack the second argument is the duration to keep attacking, the third argument is argument is either target tag or the word “self”. For “self” use own location. The creature then attacks the target.

For “rest” the creature will do a quick rest without animation.

For “equip” the second parameter is the item tag to equip and the third the slot.

For “unequip” the second parameter is the slot.

For “createitem” the second parameter is the resref of item and the optional third is the number to create, else create one.

For “destroyitem” the second parameter is the tag of the item to destroy in creatures inventory. The tag can contain wildcard “*” at the end.

For “pickup” the second parameter is the tag of the item to pickup. the third parameter is the maximum distance to get it. The tag can contain wildcard “*” at the end.

For “drop” the second parameter is the tag of the item to drop. Always drop item on the current location.

For “open”, “close”, “lock”, “unlock”, “placeable open”, “placeable close”, “placeable lock”, and “placeable unlock” the second parameter is the tag of the door/placeable to open/close/lock/unlock, and the third argument is the max distance of the door. If tag is empty then the closest door/placeable is opened / closed / locked / unlocked, and the max distance is 10 meters.

For “sound” the second parameter is the sound file to play.

For “pause” the second parameter is the duration how long the NPC will wait there (do nothing). Note that the duration can also be negative, in which case the following actions will be moved backwards in time, i.e. if you do “pause,10;animation,2,100;pause,1;animation,2,101;pause,-15” then the creature will start walking immediately because the total length of the animation is 0 seconds. Then after 10 seconds it will run 2 second animation of turn head left, and then after a second from that another animation of turn head right. The final “pause,-15” will simply changes the time to be used when running the animation, and before the moving is started. One problem with this approach is that most of the animations also stop the NPC, and it will start moving only after it thinks it should be approaching next waypoint.

For “speak” the second parameter is the string to say, and third parameter is the volume integer (default is talk == 0).

For “voice” the second parameter is the voice chat ID (VOICE_CHAT_*), default is VOICE_CHAT_HELLO (34).

For “walk” the second argument is the duration to keep walking, the third argument is argument is either target tag or the word “xyz”, “dir”, “abs”, “self” or “target”. If use “xyz”, the next tree arguments specify relative distances of x,y,z in meters from the location. In “dir” and “abs” the next two arguments are direction in degrees and distance in meters. In “dir” the directions are relative to current facing and in “abs” the direction is absolute. For “self” use own location. For “target” use the current target of the creature. The creature then walks to/toward the target and delays next action until duration has passed.

For “run” the second argument is the duration to keep run, the third argument is argument is either target tag or the word “xyz”, “dir”, “abs” “self”, or “target”. If use “xyz”, the next tree arguments specify relative distances of x,y,z in meters from the location. In “dir” and “abs” the next two arguments are direction in degrees and distance in meters. In “dir” the directions are relative to current facing and in “abs” the direction is absolute. For “self” use own location. For “target” use the current target of the creature. The creature then runs to/toward the target and delays next action until duration has passed.

For “follow” the second argument is the duration how long to follow (and if no time limit given then follow for ever), and the third argument is the distance how far in meters to follow. This will always follow the current target.

For “set local int”, “set local string”, “set local float” the second argument is the variable to set and the third argument is the value to set it. If the value is not given, then the variable is deleted. The variables are set on the NPC. This can be used to set “IgnoreOn*” variables and such in the NPC. For integer variables you can use value of ”++“ or ”–“ to increment or decrement the variable by one.

“roll”, “skill”, and “ability” will roll dice, do skill check or do a ability check specified in the second argument.

“repeat” will repeat the animation from the beginning (only for PCs). The second argument (float) tells how much to wait between animations before restarting it again. The third argument tells how many times to repeat. The repeat is immediately canceled if the PC have moved during the wait period. This must be last action, as rest of the action string is ignored after this.

“sit” sits on nearest sittable chair of correct size for object, if none valid sit on ground.

“randomwalk” does random walk on the area. Not yet implemented, this will get arguments and so on, i.e. will change.

“jumptorandom” jumps to a random walkable location on area. Not yet implemented, might change.

“gotorandom” will will try to walk to random walkable location on area. Not yet implemented, might change.

After all actions on the waypoint are done then the creature starts walking towards the next waypoint.

(FIXME) document expression syntax.

Action Arguments
animation duration(0.0), animation, speed(1.0)
animation duration(0.0), custom-animation, speed(1.0), loop(0)
facing duration(1.0), direction(facing-of-waypoint)
facing duration(1.0), +/- direction(facing-of-waypoint)
facing duration(1.0), @+/- direction(current facing)
stealth enabled(1)
detect enabled(1)
parry enabled(1)
power attack enabled(1)
improved power attack enabled(1)
counterspell enabled(1)
flurry of blows enabled(1)
rapid shot enabled(1)
combat expertise enabled(1)
improved combat expertise enabled(1)
defensive cast enabled(1)
dirty fighting enabled(1)
orient on dialog enabled(1)
bumpable enabled(1)
cast spell-num, fake(0), cheat(0), location*(self)
attack duration, location*
rest
destroyitem tag-of-item-to-destroy
createitem resref, count(1)
equip tag-of-item-to-equip, slot-where-to-equip
unequip slot-from-where-to-unquip
drop tag-of-item-to-drop
pickup tag-of-item-to-pickup(*), max-distance(10.0)
open tag-of-door(*), max-distance(10.0)
close tag-of-door(*), max-distance(10.0)
lock tag-of-door(*), max-distance(10.0)
unlock tag-of-door(*), max-distance(10.0)
placeable open tag-of-door(*), max-distance(10.0)
placeable close tag-of-door(*), max-distance(10.0)
placeable lock tag-of-door(*), max-distance(10.0)
placeable unlock tag-of-door(*), max-distance(10.0)
sound sound-file-name
pause duration
speak string,volume(0)
voice voice-id(34)
# anything
run duration, location*
walk duration, location*
follow duration(forever), distance(5.0)
set local int variable, value()
set local int variable, ++
set local int variable, –
set local string variable, value()
set local float variable, value()
roll dice specification
skill skill name
ability ability name
repeat wait time(0.0), repeat count(inf)
sit duration, maxrange(10.0)
randomwalk
gotorandom
jumptorandom

Location is specified as:

Location keyword Arguments
“xyz” x, y, z
“dir” direction, distance
“abs” direction, distance
“self”
“target”
tag

i.e. if it is something else than “xyz”, “dir”, “abs”, “self”, or “target”, then it is assumed to be a tag of placeable, waypoint, door etc.

Implementation

When the creature is initialized the creature is filled with set of variables which specify the set of waypoints to use. For each step there is variable called WPmm stored which points to the WP object for the mm step. Then there is also WAmm string for the waypoint actions and WAmm float that specifies the waypoint timing for actions and WWmm walk timing between waypoint mm and mm + 1. String variable WSmm is used to store the script name to be called at that point, and the script can set the next waypoint (the current waypoint has already been updated at that point, so if script sets the waypoint number then it is used instead of the next one). If WRmm is set then the leg between waypoint mm and mm + 1 is run instead of walked.

The WPmm can also be integer in which case it means we immediately go to the that WP number or it can be location in which case it means we move to that location as for the next WP (normally it is the spawning point of the creature).

The waypoint timings are used to jump NPC around in case nobody is on the area, in which case it is useless to do animations etc. The timing is number of seconds needed to do animations on step mm and estimated time to walk from this waypoint to the next. After this time is elapesed the NPC is virtually jumped to the next waypoint, and if that waypoint is on the another area, then NPC is really jumped to the that waypoint.

The NPC starts walking from step specified either in the WD or WN depending wheather it is day or night. The current step is stored number to the WS variable. There is no going backwards, the backwards journey is stored as separate steps to the object. When object variable for step WPmm is not found, then the integer variable WPmm is looked for and that is used as next step.

When day to night transition happens and WN is set then closest night waypoint (including transition waypoints in the WD2N waypoint set) is searched and the WS is set to that. Similar thing happens on the day break. Night step numbers start at 1000. Transition waypoint sets starts from 900 and 1900. Waypoints with numbers over 2000 are not part of night or day paths, i.e. if the waypoint indexes from that range are used, then those are used regardless of the day or night cycle.

Note that the WD is always set if the creature is initialized and it will have the spawn location stored there if nothing else is not found. This causes creatures to walk back to the place where they were spawned in case there is nothing else for them to do. If path does not have more than one waypoint and no actions, then WP_SIMPLE is set and that disables more complicated path processing including most of the heartbeats.

If variable NoWalk is set on creature then the walking of waypoints is stopped. This can be used to disable walking for of the creature.

Variable WT is set to the be time when the next action is needed to be added. In normal case that means that we came to the given waypoint (or at least we check whether we are there). When that time expires the creature is again put to walking towards next waypoint. When it reaches the waypoint then animations and actions are put to the action queue (with suitable delays), with the final item starting walking towards the next waypoint. The WT is then calculated based time to be used on those, and set it so that we will give next intructions at that time. This can also be used to temporarely pause the animations and walking, i.e. setting WT to be far enough in the future, and clearing all actions, means that the creature will not do anything before that time, and then it will resume from the next waypoint.

Variable Type Value
WD int 1
WP1 object WP_cr_tk_foo_01
WP2 object WP_cr_tk_foo_02
WP3 object WP_cr_tk_foo_03
WP4 object WP_cr_tk_foo_04
WP5 object cw_tk_guard_01
WP6 object cw_tk_guard_02
WP7 object cw_tk_guard_03
WP8 object cw_tk_guard_04
WP9 object cw_tk_guard_05
WP10 object cw_tk_guard_06
WP11 object cw_tk_guard_07
WP12 object cw_tk_guard_08
WP13 object cw_tk_guard_09
WP14 object cw_tk_guard_10
WP15 object cw_tk_guard_11
WP16 object cw_tk_guard_12
WP17 object cw_tk_guard_13
WP18 object cw_tk_guard_14
WP19 object cw_tk_guard_15
WP20 object cw_tk_guard_16
WP21 object cw_tk_guard_17
WP22 object cw_tk_guard_18
WP23 object cw_tk_guard_19
WP24 object cw_tk_guard_20
WP25 object WP_cr_tk_foo_05
WP26 object WP_cr_tk_foo_06
WP27 object WP_cr_tk_foo_07
WP28 object WP_cr_tk_foo_08
WP29 int 1
WA1 float y.yy
float y.yy
WA28 float y.yy
WW1 float x.xx
float x.xx
WW28 float x.xx

The y.yy is the calculated time to be used for the actions, and the x.xx is calculated using formula (dist / speed), where the dist is distance between waypoints, speed is the speed of the creature speed (GetMovementRate or 1.75 for default, taken from Speed variable from the creature). Speed can also be stored as Speed_xxxx either to waypoint or to the creature, where xxxx is the tag of the other (i.e. if it is stored in creature then xxxx is the tag of waypoint).

When doing actual using of the WW variables a random element is used to randomize the timings a bit (+- 10%).

cerea2/build/ambient.txt · Last modified: 2015/05/03 12:32 by 127.0.0.1