Combining Animations In A Script
|
|
Dade Laville
Registered User
Join date: 30 Dec 2007
Posts: 12
|
05-29-2009 07:41
I posted this on the animation tips forum and it was suggested to post here and see if anyone could help.
I was just wondering how to play an animation in a script and then continue on to the next animation and so on. I need it to be when they sit on the object. I've tried sleeping the script and a timer, but the animations won't stop after getting off the object. I have stopped all previous animations before starting the next and it still continues animating when I get off the object. Any help would be appreciated.
Thanks, Dade
|
|
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
|
05-29-2009 08:21
if the animation continue you haven't stopped it the proper way! Please read: http://wiki.secondlife.com/wiki/Category:LSL_Animation
_____________________
From Studio Dora
|
|
Dade Laville
Registered User
Join date: 30 Dec 2007
Posts: 12
|
05-29-2009 09:35
I've read it. I've tried the llStopAnimation in various ways using it in llSleep and timers. The animation stops just fine, when there is one. But, with multiple animations, if I get off the object, the script contines to run through the animations. How can I check to see if they are still sitting and where would I put that check?
|
|
Ravanne Sullivan
Pole Dancer Extraordinair
Join date: 10 Dec 2005
Posts: 674
|
05-29-2009 10:43
Do not use llSleep to try and time animations, it stops the script for the sleep period and may mask events such as getting off the poseball. What you want to do is use a timer to run the animation for the desired time, when the animation time expires stop that running animation before starting the next one. When the av gets off the poseball you need to stop the currently running animation, stop all loops and timers and run llRequestPermissions("last seated av key", FALSE);
This should do what you want. REmember stop each animation before starting the next, stop the last animation when the av stands and then clear permissions. Also make sure to check for animation permission before starting or stopping any animation.
|
|
Ravanne Sullivan
Pole Dancer Extraordinair
Join date: 10 Dec 2005
Posts: 674
|
05-29-2009 11:14
From: Dade Laville How can I check to see if they are still sitting and where would I put that check? You use a changed function. Check for CHANGED_LINK and then check for llAvatarOnSitTarget(). changed(integer change) { if change & CHANGED_LINK) { if (llAvatarOnSitTarget() != NULL_KEY) { //Do stuff if someone is sitting on me. } if (llAvatarOnSitTarget() != NULL_KEY) { //Do stuff if someone is not sitting on me or has just gotten off. } } }
|
|
Dade Laville
Registered User
Join date: 30 Dec 2007
Posts: 12
|
05-29-2009 11:54
From: Ravanne Sullivan You use a changed function. Check for CHANGED_LINK and then check for llAvatarOnSitTarget().
changed(integer change) { if change & CHANGED_LINK) {
if (llAvatarOnSitTarget() != NULL_KEY) { //Do stuff if someone is sitting on me. }
if (llAvatarOnSitTarget() != NULL_KEY) { //Do stuff if someone is not sitting on me or has just gotten off. } } } I tried using that and it just doesn't get past that call to start the animations and timer. Is there anyway you can show me exactly where to put that call? In the changed group...in the timer... This is what I tried: vector offset = <0,0,0>; string currentani = "first"; string ani1 = "first"; string ani2 = "second"; string ani3 = "third"; default { state_entry() { llRequestPermissions(llGetOwner(),PERMISSION_TRIGGER_ANIMATION); llSitTarget(offset, ZERO_ROTATION); } run_time_permissions(integer perms) { } touch_start(integer total_number) { } changed(integer change) { key sitting = llAvatarOnSitTarget(); if (change == CHANGED_LINK) { if(sitting != NULL_KEY) { if(currentani == "first"  { llStopAnimation("sit"  ; llStartAnimation("first"  ; llSetTimerEvent(10.0); currentani = ani1; } else { llRequestPermissions(sitting, FALSE); } } else { llStopAnimation(ani1); llStopAnimation(ani2); llStopAnimation(ani3); } } } timer() { if(currentani == ani1) { llStopAnimation(ani1); llStartAnimation(ani2); currentani = ani2; } else if(currentani == ani2) { llStopAnimation(ani2); llStartAnimation(ani3); currentani = ani3; } else if(currentani == ani3) { llSetTimerEvent(0.0); } } }
|
|
Ravanne Sullivan
Pole Dancer Extraordinair
Join date: 10 Dec 2005
Posts: 674
|
05-29-2009 13:55
Try this, it will cycle thru the animations and stop on the last one. It clears the last animation, stops the cycle timer and revokes permission. It should be easy to add to the list of animations just by adding them to the ani list. vector offset = <0,0,1>; //<0, 0, 0> will clear the sit target not set one. integer index = 0; integer oldIndex = 0; list ani = ["first", "second", "third"]; key oldAV = NULL_KEY; default { state_entry() { llSitTarget(offset, ZERO_ROTATION); } changed(integer change) { if (change & CHANGED_LINK) { if(llAvatarOnSitTarget() != NULL_KEY) { oldAV = llAvatarOnSitTarget(); llRequestPermissions(llAvatarOnSitTarget(),PERMISSION_TRIGGER_ANIMATION); index = 0; if(llGetPermissions() & PERMISSION_TRIGGER_ANIMATION) { llStopAnimation("sit"  ; llStartAnimation(llList2String(ani, index)); llSetTimerEvent(3.0); } } else { if(llGetPermissions() & PERMISSION_TRIGGER_ANIMATION) { llStopAnimation(llList2String(ani, index)); llStopAnimation(llList2String(ani, oldIndex)); index = 0; llSetTimerEvent(0.0); llRequestPermissions(oldAV,FALSE); } } } } timer() { index += 1; oldIndex = index - 1; if (index >= llGetListLength(ani)) { index = 0; llSetTimerEvent(0.0); return; } if(llGetPermissions() & PERMISSION_TRIGGER_ANIMATION) { llStopAnimation(llList2String(ani, index) -1); llStartAnimation(llList2String(ani, index)); } } }
|
|
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
|
05-29-2009 14:02
That is all screwed up  There is not such a thing as: llRequestPermissions(sitting, FALSE); You should have a: llRequestPermissions(llAvatarOnSitTarget(), PERMISSION_TRIGGER_ANIMATION); in the changed event i.e. when you sit down the script request permission. The request will trigger a "run_time_permissions(integer perm)" event when the permission is granted. In this event you start your animation. Not before. Here is a snippet to show how it can be done: changed(integer change) { if (change & CHANGED_LINK) { sitter = llAvatarOnSitTarget(); if ( sitter != NULL_KEY ) { llRequestPermissions( sitter, PERMISSION_TRIGGER_ANIMATION); } else { integer perm=llGetPermissions(); if ((perm & PERMISSION_TRIGGER_ANIMATION) && llStringLength(animation)>0) llStopAnimation(animation); } } }
run_time_permissions(integer perm) { if (perm & PERMISSION_TRIGGER_ANIMATION) { llStopAnimation("sit"); if ( llGetInventoryType( anOn ) == INVENTORY_ANIMATION ) animation = anOn ; else animation= "stand"; llStartAnimation(animation); } }
_____________________
From Studio Dora
|
|
Dade Laville
Registered User
Join date: 30 Dec 2007
Posts: 12
|
05-29-2009 15:20
From: Dora Gustafson That is all screwed up  There is not such a thing as: llRequestPermissions(sitting, FALSE); You should have a: llRequestPermissions(llAvatarOnSitTarget(), PERMISSION_TRIGGER_ANIMATION); in the changed event i.e. when you sit down the script request permission. The request will trigger a "run_time_permissions(integer perm)" event when the permission is granted. In this event you start your animation. Not before. Here is a snippet to show how it can be done: changed(integer change) { if (change & CHANGED_LINK) { sitter = llAvatarOnSitTarget(); if ( sitter != NULL_KEY ) { llRequestPermissions( sitter, PERMISSION_TRIGGER_ANIMATION); } else { integer perm=llGetPermissions(); if ((perm & PERMISSION_TRIGGER_ANIMATION) && llStringLength(animation)>0) llStopAnimation(animation); } } }
run_time_permissions(integer perm) { if (perm & PERMISSION_TRIGGER_ANIMATION) { llStopAnimation("sit"); if ( llGetInventoryType( anOn ) == INVENTORY_ANIMATION ) animation = anOn ; else animation= "stand"; llStartAnimation(animation); } }
Thanks for the snippet. However, it returns alot of errors (name not within scope errors). I know I'm probably supposed to put my animations name in there but I am confused as to where. I'm sorry, I am very new to this and trying to get it right. Also, I'd like to get the last animation (which is a loop) to continue playing until they get up or to kill all animations when they get up and not move to the next one.
|
|
Dade Laville
Registered User
Join date: 30 Dec 2007
Posts: 12
|
05-29-2009 16:22
OK, I managed to get the script to do what I want it to do (go through the animations and only stop when not on object anymore. I know it's probably sloppy but it works. However, it only works for the owner. How do I get it to work for everyone else? The new script: vector offset = <0,0,0>; //<0,0,1.8>; string currentani = "first"; string ani1 = "first"; string ani2 = "second"; string ani3 = "third"; integer phase = FALSE; default { state_entry() { llRequestPermissions(llGetOwner(),PERMISSION_TRIGGER_ANIMATION); llSitTarget(offset, ZERO_ROTATION); } touch_start(integer total_number) { } changed(integer change) { key sitting = llAvatarOnSitTarget(); if (change == CHANGED_LINK) { if(phase == FALSE) { llStopAnimation("sit"  ; llStartAnimation(ani1); llSetTimerEvent(10.0); phase = TRUE; } else { llStopAnimation(ani1); llStopAnimation(ani2); llStopAnimation(ani3); llSetTimerEvent(0.0); phase = FALSE; } } } run_time_permissions(integer perms) { } timer() { if(currentani == ani1) { llStopAnimation(ani1); llStartAnimation(ani2); currentani = ani2; } else if(currentani == ani2) { llStopAnimation(ani2); llStartAnimation(ani3); currentani = ani3; } else if(currentani == ani3) { llSetTimerEvent(0.0); } } }
|
|
Ravanne Sullivan
Pole Dancer Extraordinair
Join date: 10 Dec 2005
Posts: 674
|
05-29-2009 16:52
Please take a look at the script I posted earlier, it will show you how many of the functions you need are used. From: Dade Laville vector offset = <0,0,0>; THIS WILL CLEAR THE SIT TARGET NOT SET IT. string currentani = "first"; string ani1 = "first"; string ani2 = "second"; string ani3 = "third"; integer phase = FALSE; default { state_entry() { llRequestPermissions(llGetOwner(),PERMISSION_TRIGGER_ANIMATION); YOU ARE REQUESTING THE ANIMATION PERMISSION FOR THE OWNER NOT THE AVATAR SITTING ON THE POSE BALL. llSitTarget(offset, ZERO_ROTATION); SEE ABOVE llSitTarget(<0,0,0>, ZERO_ROTATION); will clear the sit target. } touch_start(integer total_number) NOT NEEDED AT ALL. { } changed(integer change) { key sitting = llAvatarOnSitTarget(); YOU SET THIS VARIABLE BUT MAKE NO MEANINGFUL USE OF IT. if (change == CHANGED_LINK) THIS WILL NOT DO WHAT YOU THINK. IT WILL ONLY WORK IF ANIMATION PERMISSION IS THE ONLY PERMISSION SET. SHOULD BE if (change & CHANGED_LINK) { if(phase == FALSE) { llStopAnimation("sit"  ; llStartAnimation(ani1); llSetTimerEvent(10.0); phase = TRUE; } else { llStopAnimation(ani1); llStopAnimation(ani2); llStopAnimation(ani3); llSetTimerEvent(0.0); phase = FALSE; } } } run_time_permissions(integer perms) NOT DOING ANYTHING IN THIS SCRIPT { } timer() { if(currentani == ani1) { llStopAnimation(ani1); llStartAnimation(ani2); currentani = ani2; } else if(currentani == ani2) { llStopAnimation(ani2); llStartAnimation(ani3); currentani = ani3; } else if(currentani == ani3) { llSetTimerEvent(0.0); } } }
|
|
Dade Laville
Registered User
Join date: 30 Dec 2007
Posts: 12
|
05-29-2009 20:34
From: Ravanne Sullivan Please take a look at the script I posted earlier, it will show you how many of the functions you need are used. I've tried getting permissions everywhere and it says that the avatar can't be found. Where exactly would I put the permission line in on my script. I'm sorry for being such a noob.
|
|
Ravanne Sullivan
Pole Dancer Extraordinair
Join date: 10 Dec 2005
Posts: 674
|
05-29-2009 23:57
From: Dade Laville I've tried getting permissions everywhere and it says that the avatar can't be found. Where exactly would I put the permission line in on my script. I'm sorry for being such a noob. changed(integer change) { if (change & CHANGED_LINK) { if(llAvatarOnSitTarget() != NULL_KEY) { oldAV = llAvatarOnSitTarget(); llRequestPermissions(llAvatarOnSitTarget(),PERMISS ION_TRIGGER_ANIMATION); AFTER THE CHANGED EVENT AND AFTER YOU HAVE CHECKED THAT THE CHANGED LINK WAS TRIGGERED BY AN AVATAR SITTING ON THE POSEBALL
|
|
Dade Laville
Registered User
Join date: 30 Dec 2007
Posts: 12
|
05-30-2009 00:26
From: Ravanne Sullivan changed(integer change) { if (change & CHANGED_LINK) { if(llAvatarOnSitTarget() != NULL_KEY) { oldAV = llAvatarOnSitTarget(); llRequestPermissions(llAvatarOnSitTarget(),PERMISS ION_TRIGGER_ANIMATION);
AFTER THE CHANGED EVENT AND AFTER YOU HAVE CHECKED THAT THE CHANGED LINK WAS TRIGGERED BY AN AVATAR SITTING ON THE POSEBALL I'm sorry that I just can't seem to get it. I tried what you said and even entered a llOwnerSay to test the script. It never makes it past the "if(llAvatarOnSitTarget() != NULL_KEY)". Here is what I have (and yes, I know things are sloppy.): vector offset = <0,0,0>; //will use the offset later string currentani = "first"; string ani1 = "first"; string ani2 = "second"; string ani3 = "third"; integer phase = FALSE; key oldAV = NULL_KEY; default { state_entry() { llSitTarget(offset, ZERO_ROTATION); //will set offset later } changed(integer change) { if (change & CHANGED_LINK) { if(llAvatarOnSitTarget() != NULL_KEY) { llOwnerSay("working"  ; //put this here to see if it's working and it never makes it to this step. llRequestPermissions(llAvatarOnSitTarget(),PERMISSION_TRIGGER_ANIMATION); oldAV = llAvatarOnSitTarget(); if(phase == FALSE) { llStopAnimation("sit"  ; llStartAnimation(ani1); llSetTimerEvent(10.0); phase = TRUE; } else { llStopAnimation(ani1); llStopAnimation(ani2); llStopAnimation(ani3); llSetTimerEvent(0.0); phase = FALSE; } } } } timer() { if(currentani == ani1) { llStopAnimation(ani1); llStartAnimation(ani2); currentani = ani2; } else if(currentani == ani2) { llStopAnimation(ani2); llStartAnimation(ani3); currentani = ani3; } else if(currentani == ani3) { llSetTimerEvent(0.0); } } }
|
|
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
|
05-30-2009 01:42
From: Dade Laville Thanks for the snippet. However, it returns alot of errors (name not within scope errors). I know I'm probably supposed to put my animations name in there but I am confused as to where. I'm sorry, I am very new to this and trying to get it right.
Also, I'd like to get the last animation (which is a loop) to continue playing until they get up or to kill all animations when they get up and not move to the next one. Of course the snippet don't compile, that is because it is only a part of a script  It seems to me you are trying to make a fairly complicated script without knowing some very basic things about scripting. My first advise to you is: find some pose ball with a full permission script. Take that script, look at it, change it and play with it. My second advise: Use the Second Life Wiki to read about anything you want explained. If you can't find a full permission pose ball script, I have one I can give you in world
_____________________
From Studio Dora
|
|
Dade Laville
Registered User
Join date: 30 Dec 2007
Posts: 12
|
05-30-2009 08:39
From: Dora Gustafson Of course the snippet don't compile, that is because it is only a part of a script  It seems to me you are trying to make a fairly complicated script without knowing some very basic things about scripting. My first advise to you is: find some pose ball with a full permission script. Take that script, look at it, change it and play with it. My second advise: Use the Second Life Wiki to read about anything you want explained. If you can't find a full permission pose ball script, I have one I can give you in world lol I know it wasn't a complete script. I added that snippet to my existing script. I think I have a full perm poseball. I am sorry that I couldn't understand this though. Thanks for all the advice. 
|
|
Ravanne Sullivan
Pole Dancer Extraordinair
Join date: 10 Dec 2005
Posts: 674
|
05-30-2009 09:17
llAvatarOnSitTarget() will not work unless a sit target is set, using a vector of <0,0,0> will not set a sit target it will clear it as I have posted several times. Use something like <0,0,.1> or some other vector that is none zero.
The script I posted in an earlier section will work for you, I have tested it and it does just what you have stated you want to do. Try it, look at how it works, deconstruct it. The best way to learn to script is to take a script that works and does what you want or does something similar and take it apart to see how it is doing that.
|
|
Dade Laville
Registered User
Join date: 30 Dec 2007
Posts: 12
|
05-30-2009 12:13
From: Ravanne Sullivan llAvatarOnSitTarget() will not work unless a sit target is set, using a vector of <0,0,0> will not set a sit target it will clear it as I have posted several times. Use something like <0,0,.1> or some other vector that is none zero.
The script I posted in an earlier section will work for you, I have tested it and it does just what you have stated you want to do. Try it, look at how it works, deconstruct it. The best way to learn to script is to take a script that works and does what you want or does something similar and take it apart to see how it is doing that. Awesome. Sorry I wasn't catching what you were saying about the vector. Thanks so much for smacking me in the head a few times. It was much appreciated. 
|