4 - regarding animations

9
Regarding Animations Intended Audience: 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. //This is like queue for spells and actions in RPG games. //Important thing to remember is that some actions play indefinitely(endlessly), and must be cleared out with ClearAllActions(). //In Action Queue go all commands that start with the word Action (maybe other commands also) 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

Upload: witcher2

Post on 02-Feb-2016

215 views

Category:

Documents


0 download

DESCRIPTION

4 - Regarding Animations

TRANSCRIPT

Page 1: 4 - Regarding Animations

Regarding Animations

Intended Audience: 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 QueueThe 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. //This is like queue for spells and actions in RPG games. //Important thing to remember is that some actions play indefinitely(endlessly), and must be cleared out with ClearAllActions(). //In Action Queue go all commands that start with the word Action (maybe other commands also)

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.

//-^In NWN2 there is one more option(don’t know if there is in NWN1, isn’t mentioned here) - PlayCustomAnimation. Example: PlayCustomAnimation(OBJECT_SELF,"talklaugh", 1); // ActionPlayAnimation and PlayAnimation can only play animations from Globals tab (ANIMATION_*). PlayCustomAnimations can play some different animations, as seen above.

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

NWScript:------

Page 2: 4 - Regarding Animations

void main()

{

object oTarget = GetNearestObjectByTag("WAYPOINT1");

ActionMoveToObject(oTarget);

ActionPlayAnimation(ANIMATION_LOOPING_MEDITATE, 1.0, 6.0);

}----------

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:--------

void main()

{

object oTarget = GetNearestObjectByTag("WAYPOINT1");

ActionMoveToObject(oTarget);

ActionPlayAnimation(ANIMATION_LOOPING_MEDITATE, 1.0, 6.0);

ActionDoCommand(SetLocalInt OBJECT_SELF, "Done_Meditation", 1);

}--------

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:

Page 3: 4 - Regarding Animations

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 ConstantsYou 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:-----

SetSpawnInCondition(NW_FLAG_AMBIENT_ANIMATIONS);

Page 4: 4 - Regarding Animations

SetSpawnInCondition(NW_FLAG_IMMOBILE_AMBIENT_ANIMATIONS); ----------

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:-----------

// will turn the lightable object on and off when selected

Page 5: 4 - Regarding Animations

// placed in its OnUsed event

void main()

{

if (GetLocalInt (OBJECT_SELF,"NW_L_AMION") == 0)

{

SetLocalInt (OBJECT_SELF,"NW_L_AMION",1);

PlayAnimation (ANIMATION_PLACEABLE_ACTIVATE);

SetPlaceableIllumination (OBJECT_SELF, TRUE);

RecomputeStaticLighting (GetArea(OBJECT_SELF));

}

else

{

SetLocalInt (OBJECT_SELF,"NW_L_AMION",0);

PlayAnimation (ANIMATION_PLACEABLE_DEACTIVATE);

SetPlaceableIllumination (OBJECT_SELF, FALSE);

RecomputeStaticLighting (GetArea(OBJECT_SELF));

}

}-------------------

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.

Page 6: 4 - Regarding Animations

- 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:---------------- // set in a door's OnHeartbeat script, this will cause

// it to close and lock itself at dusk

// and unlock itself at dawn

// I think that maybe one possibility is not covered – if it is dusk and door is closed but not locked. There should maybe be added one more else if for that, and make it just lock the door(because it is already closed. It would be like this:/* else if (GetIsDusk() && !GetIsOpen (OBJECT_SELF)) { SetLocked (OBJECT_SELF, TRUE)) }*/

void main()

{

if (GetIsDusk() && GetIsOpen (OBJECT_SELF))

{

ActionCloseDoor (OBJECT_SELF)

// SetLocked is set in an ActionDoCommand because we

// want it to be in the door's queue... we want the

// ActionCloseDoor to be completed before locking the door

ActionDoCommand (SetLocked (OBJECT_SELF, TRUE))

Page 7: 4 - Regarding Animations

}

else if (GetIsDawn() && GetLocked (OBJECT_SELF))

{

SetLocked (OBJECT_SELF, FALSE);

}

}---------------------------