Jump to content

Recommended Posts

Ive recently made my own dancer, and gotten it to play my animations and sounds! There is one issue however, the animations dont play one after the other but instead at random intervals. Is there a way i can fix this where they can play in succession? 

 

integer ON = 0;                    //STATE OF SCRIPT
//YOU EDIT THESE PARTS FOR NEW ANIMATIONS, SOUND CLIPS ETC. DO NOT TOUCH THE SCRIPT
list animation = ["Sync'D Motion__Originals - Boasty 01", "Sync'D Motion__Originals - Boasty 02","Sync'D Motion__Originals - Boasty 03","Sync'D Motion__Originals - Boasty 04","Sync'D Motion__Originals - Boasty 05"];     //ANIMATION NAMES
integer MaxSoundClips = 18;         //AMOUNT OF SONG CLIPS, NAME THEM 1,2,3,4,ETC 
integer SoundLength = 10;           //FIRST SERIES OF SOUND LENGTHS
integer LastSoundLength = 8;       //INCASE LAST SOUND CLIP IS SHORTER
integer SoundClipNumber = 0;       //FOR SOUND LOOP
integer AnimPos;

ResetToDefault()
{
    llStopSound();
    llSetTimerEvent(0.00);
    ON = 0;
    SoundClipNumber = 0;
    AnimPos = 0;
    llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
}

StopAnims() {
    integer x;
    for (x=0;x<llGetListLength(animation);x++) {
        llStopAnimation(llList2String(animation,x));
    }
}

    
default
{
    state_entry()
    {
        llListen(0, "", "", "");
    }
    
    attach(key id)
    {
        if(id)
        {
            llOwnerSay("Say 'on' or 'off'");
        }
        else ResetToDefault();
    }

    timer()
    {
        llPlaySound((string)(++SoundClipNumber),1.0);
        llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
        
        if(ON == 1){
            llSetTimerEvent(SoundLength); 
            ON = 2;
        }
        if(SoundClipNumber == MaxSoundClips) {
            llSetTimerEvent(LastSoundLength); 
            ON = 1; SoundClipNumber = 0;
        }
        llPreloadSound((string)(SoundClipNumber+1));
    }
    
    listen(integer channel, string name, key id, string message)
    {
        message = llToLower(message);
        if (ON == 0 && message == "on")
        {
            ON = 1;
            llRequestPermissions(id, PERMISSION_TRIGGER_ANIMATION);
            llSetTimerEvent(0.01);
        }
        else if(message == "off"){ResetToDefault();}
    }
    
    run_time_permissions(integer perm)
    {
        if (perm & PERMISSION_TRIGGER_ANIMATION)
        {
            llStopAnimation("sit");
            StopAnims();
            if ((ON == 1) || (ON == 2)) {
                llStartAnimation(llList2String(animation,AnimPos));
                AnimPos++;
            }
            if (AnimPos == llGetListLength(animation)) AnimPos = 0;
        }
    }
}
 

Share this post


Link to post
Share on other sites

It should be triggering your anims in order already, because you are incrementing AnimPos by one each time you enter the run_time_permissions event and then starting the next anim in the animation list.  You can check to be sure which anim should be playing by using llOwnerSay to tell you the value of AnimPos before you run the anim.  In fact, you can put diagnostic statements at a few key spots to narrow down whatever is misbehaving now.

You can simplify your script significantly by calling llRequestPermissions one time only, when you attach the dance object.  After that, the object will always have permissions, so you only need to stop the current anim and start the next one.  You don't need to go through the run_time_permissions event over and over again.  You also don't need to loop through stopping every single anim each time, since only the currently triggered one is running anyway, and you know which one that is.  Eliminate the StopAnims function and just call llStopAnimation for that one anim.  Finally, I may be missing something, but I don't see why ON ever needs to be anything other than 0 or 1.  I suspect that once you simplify the code a bit, you will discover whatever is making it behave improperly right now.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...