BioWare Atari
BioWare Info BioWare Games Support Forums Visit the BioWare Store
Neverwinter Nights Home
Neverwinter Nights Home

Regarding Animations

Intended Audience: For Builders
By David Gaider

[Printer Friendly / Syntax Highlight]

You basically have two choices when adding animations to your creatures in the game. Adding them directly or using the automatic functions in the generic AI.

Adding Animations Directly
The first thing to realize when you are dealing with scripting animations is that not all creatures have all animations. As a rule of thumb, if the creature is a PC race (human, elf, dwarf, half-orc, gnome or halfling), then it will have all the animations. If the creature is a humanoid monster (bugbear, goblin, etc.) then very likely it has most if not all animations. Non-humanoid monsters and especially birds will be very limited in their animations.

The Action Queue
The second thing to know when scripting animations is how to use the action queue. There are a number of scripting commands which start with the word 'Action'... when a creature calls these commands on themselves, it places the action into a queue. It will finish one action completely and then move onto the next in line... up until the point there are no more actions or a ClearAllActions() command is issued.

The reason this is important is that there are two main commands that deal with animations: ActionPlayAnimation and just PlayAnimation. ActionPlayAnimation places the command to perform the animation in the queue... PlayAnimation tells the creature to do the animation immediately as soon as it is reached in the script, overriding anything else going on in the queue.

If I wanted to script someone to move to a particular waypoint and then meditate for 6 seconds, it would look like this:

NWScript:

The creature would then move to the waypoint and wait until he got there before he began playing his meditation animation.

If I wanted to set a variable when he was finished all that, I would also have to add it into the queue. You can do this with the ActionDoCommand(). This places a non-Action command into the queue.

NWScript:

If I did the SetLocalInt command without putting it into the queue, then it would fire as soon as that point in the script was reached... probably well before the creature even reached the waypoint.

The two commands for animations are as follows:


void ActionPlayAnimation (int nAnimation, float fSpeed=1.0, float fSeconds=0.0)
- The 'nAnimation' is Constant for the animation being played.
- 'fSpeed' is the speed at which the animation is played... you could have a creature turn its head very slowly or very quickly, for instance... 1.0 is normal speed.
- 'fSeconds' is only used for looping animations (like the meditation)... it determines how long you wish the animation to be played. If left blank on a looping animation, it will play that animation until told to do something else.


void PlayAnimation (int nAnimation, float fSpeed=1.0, float fSeconds=0.0)
As mentioned, this is the same as the ActionPlayAnimation command, except that the animation is not placed in the queue... it is played immediately.


Animation Constants
You can find a list of all the animation constants (used in the 'nAnimation' portion of the command) by selecting the 'Constants' button in your script editor... all the constants begin with ANIMATION_*.

There are two types of animations: 'fire-and-forget' (or FNF), which only plays once and no duration is needed, and 'looping' which play as long as needed and a duration is required for.

A reminder once again: NOT ALL MODELS HAVE ALL ANIMATIONS. Just to mention, too, that the animations listed in the constants are not every animation that a model is capable of (there is a dying animation, after all, as well as combat animations and others)... this is just the current list of the ones that can be played via script.

Using Generic AI Animations

For a quick and easy solution to adding some life to your placed creatures, the generic AI has two functions that you can use.

In the generic OnSpawn script ("nw_c2_default9"), there is a whole list of commands that are all commented out (they are preceded with a '//' double slash that colors them green and prevents them from being compiled). To use the built-in animations, you simply need to comment back in (remove the '//') one of the following commands:

NWScript:

Don't worry about the comments that are on the same line with these commands... that just tells what they do. Simply erase the double-slash at the beginning of the line.

Then you re-compile the script and save it as a different file. And that's it... that's all you have to do.

What do these do?

Basically they are called in the OnHeartbeat event (meaning the script will 'activate' every 6 seconds). The script checks to make sure that the creature is not asleep, not in combat, not in conversation and no enemy is in sight... if all those are okay, it plays the animations.

'Ambient animations' means that the creature will move about randomly, occasionally stopping to turn to nearby friends (creatures with a friendly reputation) and play what social animations it has (and, yes, this will work on any type of creature.. it will do what it can for those creatures who don't have the full range).

'Immobile ambient animation' does the same thing... without the random movement. The creature stays in place.

So you can put down several of these types of creatures, for instance, and they will turn to each other at random intervals and seem to chat, laugh, argue... and even mill around and mingle, with the ambient animations.

Do the placeable object animations work the same way?

Yes. You can tell a chest to open by having it run its ANIMATION_PLACEABLE_OPEN, or a lamp post to turn off using ANIMATION_PLACEABLE_DEACTIVATE. A few things to keep in mind:

1) For placeable objects that are sources of illumination (such as the lamp post), it is not enough to just use its ANIMATION_PLACEABLE_DEACTIVATE or ANIMATION_PLACEABLE_ACTIVATE. That just affects the glowing part of the animation, itself. You must also use the SetPlaceableIllumination command set to TRUE and tell the area it's in to RecomputeStaticLighting.

The following is an example of placeable illumination use:

NWScript:

2) Doors are not placeable objects. First thing you should know about them is that if the door is unlocked, a creature who is told to move to a point on the other side of one will automatically open it.
Bayond that, the commands for doors are as follows:

  • - ActionOpenDoor: If used in the script of a creature, it will move to the door and open it (if it is unlocked). If used in the script of the door (or the command is sent to the door object via AssignCommand), then the door will open itself.
  • - ActionCloseDoor: As above, only the door is closed.
  • - ActionLockObject: If used in the script of a creature, it will move to the object (can be a door or placeable) and attempt to use its Open Locks skill to unlock it. ONLY call it in the script of a creature!
  • - ActionUnlockObject: As above, except the door or object is unlocked.
  • - SetLocked: This is the command you use if you want a door or object to be set to locked or unlocked without the aid of a creature or skill. If 'bLocked' is set to TRUE, the object will be locked... if set to FALSE, it will be unlocked. (example: if called in a door's own script, SetLocked (OBJECT_SELF, TRUE) will cause it to be locked.)
NWScript:

 

 

Mass Effect Now Available
Neverwinter Nights 2 Forums
Hide/Show

English
Deutsch
Français
Español
Italiano

Hide/Show

View Latest Screenshots 

View Latest Screenshots
Hide/Show

Multiplayer Games at Neverwinter Connections

Today
Schedule a Game...



Current time is: (set time)
Sat, 19 July 2008 07:18PM

Hide/Show

Buy Premium Modules

Top NWN: HotU Modules:
1. TORTURED HEARTS II.
2. More...

Top NWN: SoU Modules:
1. TORTURED HEARTS II.
2. More...

Top CEP Modules:
1. The Lord of Terror The Diablo Campa...
2. More...

Top Modules - NWVault:
1. Hall of Fame
2. More...

Total Modules: 4423

Hide/Show

4,052,294 BioWare Users:
  102 Logged In
  13 Hidden
  484 Guests

1873 Playing Online
  100% NWN
  100% NWN: SoU
  100% NWN: HotU

544 Registered Guilds

7,708,368 posts in forums

Newest Forum Topics:
1. Question about download content (Mass Effect PC Version General Discussion (Spoilers will be moved))

2. 1Up review and E3 screens (Dragon Age: Origins General Discussion)

3. Collision Boxes not showing ? (NWN2: Builders - NWN2 Toolset)

4. Name Generation in Character Cre... (NWN2: Custom Content)

5. Will Characters Leave? (Dragon Age: Origins General Discussion)