Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Library: Anxiousness Chair - Triggers Animations and Changes On_Touch

Kaneda Akebono
Junior Member
Join date: 7 Jun 2004
Posts: 14
06-23-2004 18:19
Someone posted a question on the forums, and I wrote a script for it. You can also use the premissions part of the code here to trigger animations on anything else if you want.

Anxiousness Chair v.1 is a script for any object you sit on that you want to use custom animations on. I also spent some time adding the ability to be able to scroll through all animations in the object by click on it. All you need to do is copy this script into the object and drag your animations onto it. Then change the variables at the top of the script to you liking. Made it as easy as possible so that even a noob should be able to use it without any difficulties.

I spent alot of time working bugs out, but it should be good to go now.

Enjoy. ;)

- Kaneda
CODE

//Anxiousness Chair v.1
//By: Kaneda Akenbono
//Enjoy, and I'd appreciate it if you left this on the script. :)
//
//Add the animations you want to your object.
//I pulled the stuff below into globals so you can easily modify this script without understanding any of the code. :)

vector Angle = <0,0,0>; //Enter a vector rotation for the sit...
vector SitLoc = <0,0,0.1>; //This is the sitTarget positioning... CANNOT EQUAL 0
string LoadText = "Anxiousnes Chair v.1 - Comment this out or change if you want..."; // The text you want to show when the object loads...
string Context = "Ride!"; //The text you want in the context menu...

//Globals!! WOOO!!
key user;
list animations;
integer animNum;
integer nextAnim = 1;
integer curAnim = 0;

//This part dynamically gathers all of the animations you've placed in the object for usage later...
initialize()
{
integer x;
list oldAnim;
animNum = llGetInventoryNumber(INVENTORY_ANIMATION);
for (x = 0; x < animNum; x++)
{
animations = oldAnim + [x];
oldAnim = animations;
}
}

default
{
state_entry()
{
initialize();
//For easy rotation in the llSitTarger enter the vector rotation below..
vector eul = Angle; //45 degrees around the z-axis, in Euler form..
eul *= DEG_TO_RAD; //convert to radians...
rotation quat = llEuler2Rot( eul ); //convert to quaternion...
llSay(0, LoadText);
//Text it says under the context menu...
llSetSitText(Context);
//Adjust the positioning of the user while siting... also need for llAvatarOnSit... if this value is equal to 0, it doesn't work, so set it to make it look right for your object
llSitTarget(SitLoc, quat);
}
touch_start(integer num_detected)
{
if (user = llAvatarOnSitTarget())
{
if (animNum > 1)
{
llStopAnimation(llGetInventoryName(INVENTORY_ANIMATION, curAnim));
llStartAnimation(llGetInventoryName(INVENTORY_ANIMATION, nextAnim));
curAnim = nextAnim;
if (nextAnim < (animNum - 1))
{
nextAnim++;
}
else
{
nextAnim = 0;
}
}
}
}
changed(integer change)
{
//If the user sits on the object...
if (change & CHANGED_LINK)
{
user = llAvatarOnSitTarget();
if (user)
{
llRequestPermissions(user, PERMISSION_TRIGGER_ANIMATION);
}
else
{
llStopAnimation(llGetInventoryName(INVENTORY_ANIMATION, 0));
}
}
}
run_time_permissions(integer perm)
{
if (perm)
{
//This starts the first animation...
llStartAnimation(llGetInventoryName(INVENTORY_ANIMATION, 0));
curAnim = 0;
}
}
}
Phil Murdock
PM Adult
Join date: 21 Jun 2004
Posts: 116
07-12-2004 14:56
Works Great thanks alot
Valadeza Anubis
Registered User
Join date: 25 Jun 2004
Posts: 31
Help needed
07-16-2004 12:29
This is a great script, thank you very much for posting it. I have a few questions, and bare with me, I know next to nothing about scripting and animations. I've used this script on two separate objects, two separate animations. While the one object carries out the animation perfectly, for some reason, other animations are not working in full. Animations that have the legs moving or anything below the waste changed, are not coming through, the objects force the Avatar's lower body to take a "sitting" pose as is normal for sitting on any object. However the animation attached to the object requires the legs to either be standing and posed, or moving in some way. Am I making an error? Am I missing something? Why do some animations make the Avatar stand and others do not when the animation is used separated from the item the legs are posed yet once attached to the script and object, the avatar only sits?

Thank you for any help you can provide.

-Vala
Damanios Thetan
looking in
Join date: 6 Mar 2004
Posts: 992
07-20-2004 09:21
Usually, the reason of animations only playing on the top part of the body, is because the av is sitting.

When you sit on an object the 'sit' animation is triggered automatically. This probably forces the av in 'sitting mode'.

It's probably a good idea to stop the 'sit' animation, before starting any others.

Put this line of code on a line above the

"//This starts the first animation... " comment in the script:

CODE
llStopAnimation("sit");
Phil Murdock
PM Adult
Join date: 21 Jun 2004
Posts: 116
07-21-2004 15:39
When i link this in a prim to other prims with this script and animations in them and try and run the animation I get errors from the other linked animations.

Anybody know a fix for this?
CrowCatcher Valen
Senior Member
Join date: 2 May 2003
Posts: 290
Phil is Right...
07-25-2004 13:25
I've been trying to help him with this for a few hours now and for some reason it keeps returning a permission not set error line. I'm perplexed. Anyone else having this problem?
_____________________
"Everything except God has some natural superior; everything except unformed matter has some natural inferior."...
"Without sin, the universe is a Solemn Game: and there is no good game without rules."

C.S. Lewis
Damanios Thetan
looking in
Join date: 6 Mar 2004
Posts: 992
07-29-2004 07:35
If you have multiple linked prims, each with a sit script. The 'changed' event is actually sent to all prims, but there's only one (the one you actually sit on), who's the one gaining the permission to perform anims. (Don't ask me why this happens). So when you stand up, all scripts start their 'llStopAnimation', but only one is allowed. The rest of the prims scream error messages...

To fix this, ask if you have any avatar permissions set. The easiest way i found out it:

CODE

// check if the permissions were actually set for this prim
// by checking we have a valid av
if (llGetPermissionsKey() != NULL_KEY) {

llStopAnimation("my_sit_anim");
}



Or something in that order.

This will fix most multiple 'sit' objects that have problems with either anims or control takeover.
Kurt Zidane
Just Human
Join date: 1 Apr 2004
Posts: 636
07-31-2004 16:33
cool! but how dose "if (llGetPermissionsKey() != NULL_KEY) {

llStopAnimation("my_sit_anim";);
}" plug into the current script? Sore newbie coder asking newbie q.
DoteDote Edison
Thinks Too Much
Join date: 6 Jun 2004
Posts: 790
08-03-2004 18:12
I spent several hours figuring how to make this work without errors when multiple prims are linked with the same script in each prim (so all of your friends can sit and cycle through poses.) The challenge was to stop the permissions errors or the stuck-in-a-pose problem after unseating.

Basically, I removed the part of changed() that detects a link change - when the user sits or stands. I put the permissions into the click_start() along with a llAvatarOnSitTarget() == NULL_KEY test to see if the user is seated. If not seated, the click does nothing (though it should really say, "please, sit first.";) If seated, clicks cycle the anims and begin a llSetTimerEvent( 1.0 ). The purpose of the timer is to detect when the user stands. In timer(), if the test llAvatarOnSitTarget() == NULL_KEY is true, the current animation stops.

With the change, multiple linked prims containing this script perform with no errors.

Look me up at the silver tower in Europa if you have any scripting questions. While I'm fairly new to the language, I love to trouble-shoot and figure these things out. A problem solved is knowledge gained.
Kurt Zidane
Just Human
Join date: 1 Apr 2004
Posts: 636
08-05-2004 13:15
I"m sorry I didn't tell you, but I figured out how to get the script to properly recognize when some one sits and stands. So it doesn't need to check the user status every 30 seconds. I'll be poasting my vertion of the script if Kaneda Akebono ok it. I don't want to step on his toes.
Tifosa Twang
Registered User
Join date: 26 Mar 2006
Posts: 25
Fix?
07-08-2007 17:39
This is an old script roaming around SL, so I'm hoping there may be a fix. I am using the script, but keep getting the following error:

PERMISSION_TRIGGER_ANIMATION permission not set
Object: Script trying to stop animations but PERMISSION_TRIGGER_ANIMATION permission not set

Does anyone happen to know the fix?

Thanks!
Tifosa Twang
Registered User
Join date: 26 Mar 2006
Posts: 25
Is there a fix?
07-08-2007 17:44
I came across this script and am hoping someone may have solved for the errors. I am using it with an animated script and am getting the following error:

Object: Script trying to stop animations but PERMISSION_TRIGGER_ANIMATION permission not set

Can anyone help? Thanks!
koala Loon
Registered User
Join date: 15 Jun 2007
Posts: 7
04-21-2008 13:11
thanks for share anyway..
it doesn't work on me neither..;(
anybody can fix it?
Chatlan Mapholisto
Registered User
Join date: 7 Dec 2007
Posts: 7
04-22-2008 05:10
I think this will work.

if (llGetPermissionsKey() == user)
{
llStopAnimation("my_sit_anim";);
}

If it doesn't, check this.

if (PERMISSION_TRIGGER_ANIMATION & llGetPermissions())
{
llStopAnimation("my_sit_anim";);
}
Johnnytreadlightly Nightfire
Registered User
Join date: 1 Jun 2008
Posts: 11
fix I think
05-17-2009 00:08
I don't post here very often, almost never, but I took the liberty of combining the ao overriding poseball script also found on the forums with this handy animation changing script to make what I hope is a very nice poseball script for everyone to use. Please forgive the sloppiness, it may not be pretty but so far it works great! :-)


CODE



string anim2run;//animation in inventory


list anim2stop;//default or AO sit animation
float sleep = 0.5;//duration of llSleep in seconds
//Anxiousness Chair v.1
//By: Kaneda Akenbono
//Enjoy, and I'd appreciate it if you left this on the script.
//
//Add the animations you want to your object.
//I pulled the stuff below into globals so you can easily modify this script without understanding any of the code.

vector Angle = <-90,0,-90>; //Enter a vector rotation for the sit...
vector SitLoc = <0, 0.7, -0.25>; //This is the sitTarget positioning... CANNOT EQUAL 0
//string LoadText = "Anxiousnes Chair v.1 - Comment this out or change if you want..."; // The text you want to show when the object loads...
string Context = "Sit"; //The text you want in the context menu...

//Globals!! WOOO!!
key user;
list animations;
integer animNum;
integer nextAnim = 1;
integer curAnim = 0;

//This part dynamically gathers all of the animations you've placed in the object for usage later...
stop_anim(){
if(llGetListLength(anim2stop) > 0)
llStopAnimation((string)anim2stop);
//If there is a name in the list then it stops that animation
}

initialize()
{
integer x;
list oldAnim;
animNum = llGetInventoryNumber(INVENTORY_ANIMATION);
for (x = 0; x < animNum; x++)
{
animations = oldAnim + [x];
oldAnim = animations;
}
}

default
{
state_entry()
{
llSetTouchText("");
initialize();
//For easy rotation in the llSitTarger enter the vector rotation below..
vector eul = Angle; //45 degrees around the z-axis, in Euler form..
eul *= DEG_TO_RAD; //convert to radians...
rotation quat = llEuler2Rot( eul ); //convert to quaternion...

//Text it says under the context menu...
llSetSitText(Context);
//Adjust the positioning of the user while siting... also need for llAvatarOnSit... if this value is equal to 0, it doesn't work, so set it to make it look right for your object
llSitTarget(SitLoc, quat);
}
touch_start(integer num_detected)
{
if (user = llAvatarOnSitTarget())
{
if (animNum > 1)
{
llStopAnimation(llGetInventoryName(INVENTORY_ANIMATION, curAnim));
llStartAnimation(llGetInventoryName(INVENTORY_ANIMATION, nextAnim));
curAnim = nextAnim;
if (nextAnim < (animNum - 1))
{
nextAnim++;
}
else
{
nextAnim = 0;
}
}
}
}
changed(integer change)
{
//If the user sits on the object...
if (change & CHANGED_LINK)
{
user = llAvatarOnSitTarget();
if (user)
{
llRequestPermissions(user, PERMISSION_TRIGGER_ANIMATION);
}
else
{
llStopAnimation(llGetInventoryName(INVENTORY_ANIMATION, 0));
}
}
}
run_time_permissions(integer perm)
{
if (perm)
{
//This starts the first animation...
anim2stop = [];//Clears the list
llStopAnimation("sit");
llSleep(sleep);//need sleep to give avatar time to cycle from stand to default sit to AO sit
anim2stop = llGetAnimationList(llAvatarOnSitTarget());
stop_anim();//This runs the subroutine up top .


llStartAnimation(llGetInventoryName(INVENTORY_ANIMATION, 0));
curAnim = 0;
}
}
}

Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
::eyeroll::
05-17-2009 00:18
well if the OP (nearly 5 years ago, without many of the functions we have to use now) could use inconsistent indentation I suppose none is an improvement (it's consistent at least)
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -