Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Multi-Pose Animation Stand

Teddy Wishbringer
Snuggly Bear Cub
Join date: 28 Nov 2004
Posts: 208
03-08-2006 08:11
After getting frustrated going through all the hundreds of animations in my inventory on at a time (dbl-click, play locally, close, dbl-click, play locally, etc...) I decided I wanted a stand that I could put all my animations (aka poses) into, and like a animation vendor, simply click on a next and back button to cycle through them all.

I've made the script public and free, and heavily commented it so anyone with basic scripting experience should be able to follow along. This is my second script written from scratch, and I'm quite thrilled to present it to you for your use.

Instructions:

Create a prim for the stand, and two prims for the next and back buttons. Make sure those buttons are labelled 'next' and 'back'. Link all three prims together making the stand the root prim. To do this, make sure the stand is the last prim selected before linking them. Put the code below into the linked object, as well as as many poses in your inventory as you want.

The stand will whisper the number of poses loaded in the stand, and to play them, it's just a matter of right clicking on the stand and select 'Pose'. The next and back buttons will change animations, and hover text will tell you the name of the pose currently playing.

Enjoy!

Teddy.

CODE
// Animation Stand (Stand Script)
// by Teddy Wishbringer
//
// Thanks go to Argent Stonecutter for assistance in streamlining and bug squishing. :)
//
// Allows owner to cycle through all the animations stored within the stand by
// clicking on BACK and NEXT buttons. This script goes in the stand, which
// should be the root prim in the linkset. Linkset requires two additional
// prim buttons (forward and backward) with each named 'next' and 'back' respectively.
//
// NOTE: This script is made free, and may be destributed as long as you
// do not charge for it, the comments remain untouched and this script
// remains end-user modifiable.


// User adjustable settings

vector animation_offset = <0,0,1.5>; // Animation offset from stand
string base_float_text = "Now playing animation: "; // Float text prefix
vector color_float_text = <1,1,1>; // Floating text colour
float alpha_float_text = 1.0; // Floating text alpha transparency

// System settings - Do Not Change Anything Below!

integer animation_qty; // Number of animations available
integer animation_current; // Inventory number of current animation
string animation_name; // Name of current animation
string new_animation_name; // Name of next animation.
string float_text; // Used when we evaluate the entire floating text message
key avatar; // Key of the avatar who's sitting on me

update_inventory()
{
llSetText("Updating animation list...", color_float_text,alpha_float_text);
animation_qty = llGetInventoryNumber(INVENTORY_ANIMATION); // Check how many anims we have?
if (animation_qty > 0)
{
llWhisper(0, "Total animations loaded in this stand: " + (string)animation_qty);
set_anim(0);
}
else
{
llSetText("No Animations Found.. Offline", color_float_text,alpha_float_text);
}
}

// Set the next animation available as the active one
set_anim(integer inventory_number)
{
// Get the name of the animation is inventory position (inventory_number)
new_animation_name = llGetInventoryName(INVENTORY_ANIMATION,inventory_number);
// Update the floating text to display new animation, and the number out of total available
float_text = base_float_text + new_animation_name + "\n(" + (string)(animation_current + 1) + " of " + (string)animation_qty + ")";
llSetText(float_text, color_float_text,alpha_float_text);

// Get the key of the avatar on the stand (or if none is present)
avatar = llAvatarOnSitTarget();

if (avatar != NULL_KEY) // Is avatar is still posing, if so then..
{
llStopAnimation(animation_name); // Stop current animation
llStartAnimation(new_animation_name); // Start next animation
}
// Set the new animation name as the current
animation_name = new_animation_name;
}

default
{

on_rez(integer num)
{
llResetScript(); // Reset the script
}

state_entry()
{
update_inventory(); // Perform an inventory update and determine how many animations we have

if (animation_qty > 0)
{
llSetSitText("Pose");
llSitTarget(animation_offset,ZERO_ROTATION);
animation_name = llGetInventoryName(INVENTORY_ANIMATION, 0);
set_anim(animation_current);
}

}

// If touched, detect touch location and do the right thing
touch_start(integer num)
{
// Get the name of the prim touched
string where = llGetLinkName(llDetectedLinkNumber(0));

if (where == "next") // The next button was pressed
{
animation_current++; // Increment the animation inventory pointer
if ((animation_current + 1) > animation_qty) // Have we reached the last animation in the object?
{
animation_current = 0; // We have, so wrap around back to the first one
}
set_anim(animation_current);
}
else if (where == "back") // The back button was pressed
{
animation_current--; // Decrement the animation inventory pointer
if (animation_current < 0) // Have we reached the first animation in the object?
{
animation_current = animation_qty - 1; // We have, so wrap around to the last one
}

set_anim(animation_current); // Update the animation played by the stand
}
}

changed(integer change)
{
if (change & CHANGED_INVENTORY) // Test for a changed inventory
{
update_inventory();
}

// The object's sit target has been triggered
if (change & CHANGED_LINK) // Test for a changed link
{
avatar = llAvatarOnSitTarget();
if(avatar != NULL_KEY) // Is that changed link an avatar?
{
llRequestPermissions(avatar,PERMISSION_TRIGGER_ANIMATION);
}
else
{
if (llGetPermissionsKey() != NULL_KEY)
{
llStopAnimation(animation_name);
}
}
}
}

run_time_permissions(integer perm)
{
if (perm & PERMISSION_TRIGGER_ANIMATION)
{
llStopAnimation("sit");
llStartAnimation(animation_name);
}
}
}
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Discussion Thread
03-09-2006 20:47
/54/3a/92620/1.html
_____________________
i've got nothing. ;)
madddyyy Schnook
SLGuides Virtual Worlds
Join date: 2 Jan 2006
Posts: 207
03-07-2007 04:50
there are 2 errors in the copy and paste... spaces between words..

you may want to repost for people who dont know how to correct... thanx