Jump to content
Sign in to follow this  
Sunbleached

Sound for each animation Script

Recommended Posts

Hello! I want to create a script that allows you to play different sounds with each animation (e.g. running, walking, swimming...) based on the simple walker script. How it should look like? Is it possible to assign a separate sound for each animation with such script? Perhaps you will advise to be based on another script? Thank you.

Here is the script on which I'm based:

string walk_sound = "34eae688-8b2d-d86c-5c1e-4e3eb865ca0d";
string stop_sound = "81603357-2b3c-bc7a-5d15-eb20fcca22a1";
string run_sound = "b1c0f5e2-45e5-e0b2-926a-fd60520ed4ee";

float volume = 1.0;

integer i = TRUE;

key owner;

default
{
    state_entry()
    {
        llSetTimerEvent(.3);
    }
    timer()
    {
        string anim = llGetAnimation(llGetOwner());
        if ((anim == "Walking") || (anim == "CrouchWalking"))
        {
            llLoopSound(walk_sound,volume);
            i=FALSE;
        }
        else if ((anim == "Running"))
        {
            llLoopSound(run_sound,volume);
            i=FALSE;
        }
        else
        {
            llStopSound();
            if (i == FALSE)
            {
                llTriggerSound(stop_sound,volume);
            }
            i=TRUE;
        }
    }
}

 

Share this post


Link to post
Share on other sites

Well the code you found really nearly shows, how it could be done. But, you need more to handle it correct, most important run_time_permissions

Take a look at http://wiki.secondlife.com/wiki/LlGetAnimation

Use llLoopSound to given animation as below:

//  PSEUDO CODE EXAMPLE
if (gLastAnimation != newAnimation)
{
    if (newAnimation=="Walking")
        llLoopSound( SOUND_WALK, 1.0);
    if (newAnimation=="Running")
        llLoopSound( SOUND_RUN 1.0);
        
    // Remember to store gLastAnimation
     gLastAnimation = newAnimation;
} 

 

 

Edited by Rachel1206
  • Like 1

Share this post


Link to post
Share on other sites
On 25.07.2017 at 5:17 PM, Rachel1206 said:

Well the code you found really nearly shows, how it could be done. But, you need more to handle it correct, most important run_time_permissions

Take a look at http://wiki.secondlife.com/wiki/LlGetAnimation

Use llLoopSound to given animation as below:


//  PSEUDO CODE EXAMPLE
if (gLastAnimation != newAnimation)
{
    if (newAnimation=="Walking")
        llLoopSound( SOUND_WALK, 1.0);
    if (newAnimation=="Running")
        llLoopSound( SOUND_RUN 1.0);
        
    // Remember to store gLastAnimation
     gLastAnimation = newAnimation;
} 

Hello Rachel! Thanks to you, I have made great progress. I cross-linked your script and the script taken from here http://wiki.secondlife.com/wiki/LlGetAnimation . But something is wrong. The sound for some reason only appears when I stop after moving. I think the error is somewhere at the beginning of my script. Since it is not intended for sounds, and I have not been able to completely adapt it. Please look may advise what to do. I will be grateful for any help.  That's what I cooked up:

Quote


string SOUND_WALK = "34eae688-8b2d-d86c-5c1e-4e3eb865ca0d";
string SOUND_RUN = "b1c0f5e2-45e5-e0b2-926a-fd60520ed4ee";
 
key gOwner;
string gLastAnimation;
 

 
Initialize(key id) {
    if (id == NULL_KEY) {
        llSetTimerEvent(0.0); 
    }
    else { 
        llRequestPermissions(id, PERMISSION_TRIGGER_ANIMATION);
        gOwner = id;
    }
}
 
 

 
default
{
    state_entry() {
        
        if (llGetAttached() != 0) {
            Initialize(llGetOwner());
        }
    }
 
    attach(key id) {
        Initialize(id);
    }
 
    run_time_permissions(integer perm) {
        if (perm & PERMISSION_TRIGGER_ANIMATION) {
            llSetTimerEvent(0.25); 
        }
    }
 
    timer() {
        string newAnimation = llGetAnimation(gOwner);
 
        if (gLastAnimation != newAnimation) 
        { 
            if (newAnimation == "Walking") 
            {
                llLoopSound( SOUND_WALK, 1.0);
            }
             if (gLastAnimation == "Running") 
             
             { 
                llLoopSound( SOUND_RUN, 1.0);
            }
            
          else
            {
                llStopSound();
                }
 
            gLastAnimation = newAnimation;
        }
    }
}

 

 

 

Share this post


Link to post
Share on other sites

walking has newanimation while running has lastanimation ?

or ...try changing timer to ..

 timer()
  {
        string newAnimation = llGetAnimation(gOwner);      // the define here resets the string each pulse
        if (newAnimation == "Walking")
        {   llLoopSound( SOUND_WALK, 1.0);          
        }
        else if (newAnimation == "Running")              
        {   llLoopSound( SOUND_RUN, 1.0);           
        }
        else
            llStopSound();
    }

Edited by Xiija
  • Like 1

Share this post


Link to post
Share on other sites

@Sunbleached  Try building it up step by step.   Check with this little script first, and once you're happy with the messages it's giving you, then try adding the sounds.

key kOwner;
string strOldAnim;

default {

	attach(key id) {
		if(id){
			kOwner = id;
			llSetTimerEvent(1.0);
		}
	}

	timer() {
		string strNewAnim = llGetAnimation(kOwner);
		if(strNewAnim != strOldAnim){
			llOwnerSay("the old animation was "+strOldAnim+" but the new one is "+strNewAnim);
			//then start playing the appropriate sound, if applicable.
		}
		strOldAnim = strNewAnim;
	}
}

 

  • Like 1

Share this post


Link to post
Share on other sites

@Rachel1206 @Xiija @Innula Zenovka

Hey, guys! Great news! Thanks to the universal efforts the script is ready! More precisely its beta version but added already seven animations / sounds. So meet if someone interested! Here it is in all its glory. Of course, bugs and glitches are possible. Just in case, at the bottom credits are indicated, (if anyone against please tell!)
Thank you all very much.

// SOUND FOR EACH ANIMATION SCRIPT (beta-version!)
// LISTING EDIT.
// DATE PRE-FINISHED: JULY 28TH 2017
// BASED ON: SIMPLE AO SCRIPT.
// YOU CAN FIND FREE EXAMPLE HERE:
// http://wiki.secondlife.com/wiki/LlGetAnimation
// THIS SCRIPT ALLOWS YOU TO PLAY DIFFERENT SOUNDS ON EACH ANIMATION
// WHEN YOU WALK,RUN,JUMP,FALLING,FLYING ETC.
// ITS A BETA, THOUGH. YOU CAN ADD MORE SOUNDS FOR ANIMATIONS.

// ADDING MORE SOUNDS FOR ANIMATIONS HERE:
// YOU CAN REPLACE UUID'S BETWEEN QUOTES WITH YOUR OWN!

string SOUND_JUMP = "4a42727e-a5fc-d37c-f758-606264ce87b4";
string SOUND_RUN = "b1c0f5e2-45e5-e0b2-926a-fd60520ed4ee";
string SOUND_WALK = "e98a51a7-176f-8f7e-eece-639fcc55f535";
string SOUND_FLYING = "35c41372-4405-4057-b2e0-a04a593037c2";
string SOUND_LANDING = "9755f397-79b1-02b0-45ac-afcfbf136de9";
string SOUND_FALLING_DOWN = "2ddcfbb3-13ca-1678-03e4-3941208c8048";
string SOUND_STANDING_UP = "8c4f4e07-ea30-b0a3-34ec-1f587eb70d47";

// PLEASE, DO NOT MAKE ANY CHANGES, UNTILL ...

key gOwner;
string gLastAnimation; 
 

 
Initialize(key id) {
    if (id == NULL_KEY) {
        llSetTimerEvent(0.0);
    }
    else { 
        llRequestPermissions(id, PERMISSION_TRIGGER_ANIMATION);
        gOwner = id;
    }
}
 
 

default
{
    state_entry() {
       
        if (llGetAttached() != 0) {
            Initialize(llGetOwner());
        }
    }
 
    attach(key id) {
        Initialize(id);
    }
 
    run_time_permissions(integer perm) {
        if (perm & PERMISSION_TRIGGER_ANIMATION) {
            llSetTimerEvent(0.25); 
        }
    }
 
  timer() {
        string newAnimation = llGetAnimation(gOwner);
 
 {
     if (newAnimation == "Jumping") 
            {
                llLoopSound( SOUND_JUMP, 1.0);
            }
            
            else if (newAnimation == "Flying")
            {
                llLoopSound( SOUND_FLYING, 1.0);
            }
            
            else if (newAnimation == "Walking")
            {
                llLoopSound( SOUND_WALK, 1.0);
            }
            
            else if (newAnimation == "Running") 
             
             { 
                llLoopSound( SOUND_RUN, 1.0);
            }
            else if (newAnimation == "Landing")
            {
                llLoopSound( SOUND_LANDING, 1.0);
            }
            else if (newAnimation == "Falling Down")
            {
                llLoopSound( SOUND_FALLING_DOWN, 1.0);
            }
            else if (newAnimation == "Standing Up")
            {
                llLoopSound( SOUND_STANDING_UP, 1.0);
            }
// ... HERE! YOU CAN ADD NEW ANIMATIONS TO BE SOUNDED!

// E.G. :
//          else if (newAnimation == "Standing Up")
//          {
//              llLoopSound( SOUND_STANDING_UP, 1.0);
//          }

// OK, ITS DONE NOW!!!    
        
          else
            {
                llStopSound();
                }
 
            gLastAnimation = newAnimation; 
        }
    }
}
// PLEASE, ENJOY THIS SCRIPT!!! :D

// CREDITS:
// IDEA: SUNBLEACHED
// POWERED BY: Rachel1206, Xiija, Innula Zenovka
// THE END

Thank you all very much. Again :D

Edited by Sunbleached
  • Like 3

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.

Sign in to follow this  

×
×
  • Create New...