58
MOVING
YOUR AVATAR
AROUND THE
WORLD
ATTACHMENTS
ANIMATION
CONTROLLING
YOUR
ATTACHMENTS
SUMMARY
ANIMATION OVERRIDES
The various AO scripts differ in relatively minor ways, but the basic idea is always the same: to watch
what your avatar is doing, and override the default animation with one of your choice. Listing 2.10 replaces
the default walking animation with a floating crossed-leg pose; this is possibly the simplest AO script. It
may look pretty complicated, but we'll walk through the pieces slowly. Place the script in any attachment,
such as a bracelet or a transparent hat. Most of the complexity comes from setting up permissions to
animate the avatar—extending the methods shown in Listing 2.10—and that is functionality you will use
in a lot of places.
Listing 2.10: WalkAO—Why Walk When You Can Float?
// the animation we're going to override
string AN_TRIGGER = "Walking";
// which animation are we overriding walking with?
string AN_OVERRIDE = "yoga_float";
integer gOverriding = FALSE; // are we running the override right now?
integer gHasPermission = FALSE; // did we get permission yet?
integer gEnabled = TRUE; // is the AO on?
animOverride() {
if (gHasPermission) {
string curAnimState = llGetAnimation(llGetOwner());
if (curAnimState == AN_TRIGGER && gEnabled) {
if (!gOverriding) { // already overriding? skip
gOverriding = TRUE;
llStartAnimation(AN_OVERRIDE);
}
} else {
if (gOverriding) {
llStopAnimation(AN_OVERRIDE);
gOverriding = FALSE;
}
}
}
}
default {
on_rez( integer _code ) {
llResetScript();
}
state_entry() {
gOverriding = FALSE;
gHasPermission = FALSE;
gEnabled = TRUE;
if ( llGetAttached() ) {
llRequestPermissions(llGetOwner(),
PERMISSION_TRIGGER_ANIMATION|
PERMISSION_TAKE_CONTROLS);
}
llSetTimerEvent(1.0);