Jump to content

Worn object which plays sound UUIDs and triggers an animation included in the object


Subsonic Oh
 Share

You are about to reply to a thread that has been inactive for 1236 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

As I'm a very noob when it comes to LSL, I looked at all old-school drinks in my inventory to edit their scripts, but their scripts are all not modifyable or use library animations.

That prim is attached to the body, it should play sound UUIDs and trigger a non-looped animation before a specific sound will be played, or.. together with that sound.

My basic idea would be like...

default 
	{
    state_entry() 
		{
        llPlaySound(" --SOUND UUID1-- ",1);
  		llSleep(15);
        llPlaySound(" --SOUND UUID2-- ",1);
  		llSleep(30);
        llPlaySound(" --SOUND UUID3-- ",1);
  		llSleep(20);
		llStartAnimation( --Inventory Animation or Animation UUID if possible?-- ); 
//i don't need llStopAnimation when it's not a looped animation, correct?
		llPlaySound(" --SOUND UUID4-- ",1);
  		llSleep(15);
        llResetScript();
	    }
	}

Could someone please help me with the LSL syntax? And how to use an inventory animation or animation-UUID? I  completely fail here :(

Link to comment
Share on other sites

Hmm ... I tried this, but it doesn't loop, it only plays the sound and animation once, doesn't reset. In my understanding, the reset should restart the script, or where is my mistake here?

 

default
{
    state_entry() 
    {
        }
   
        attach(key attached)
    {
        if (attached != NULL_KEY)   
        { 
        llRequestPermissions( llGetOwner(), PERMISSION_TRIGGER_ANIMATION );
		}
	}
  
 run_time_permissions(integer permissions)
    {
            llPlaySound(" ---Sound UUID--- ",1);
            llStartAnimation( llGetInventoryName( INVENTORY_ANIMATION, 0) );
            llSleep(15);
            llResetScript();
    }
}

 

Link to comment
Share on other sites

The code in the attach event is only executed when you put the object on or take it off.

When you reset the script it executes the code in the state_entry event (none, in this case) and then waits for some other event to get triggered (again, there's no event going to be triggered unless you take the object off and put it back on again, which will trigger the attach event).

Generally the best way to do something repeatedly is to use a timer event.

So, the sequence I'd suggest here is

  • attach: llResetScript
  • state_entry: llRequestPermissions
  • run_time_permissions: llSetTimerEvent (15.0)
  • timer: llPlaySound, llStartAnimation, and no llSleep

One difference with this scheme is that you will wait 15 seconds after calling llSetTimerEvent until the timer event itself is triggered. To have the sound and animation triggered immediately, you'd have to repeat the llPlaySound and llStartAnimation calls in the run_time_permissions event.

Edited by KT Kingsley
  • Thanks 1
Link to comment
Share on other sites

34 minutes ago, KT Kingsley said:

The code in the attach event is only executed when you put the object on or take it off.

When you reset the script it executes the code in the state_entry event (none, in this case) and then waits for some other event to get triggered (again, there's no event going to be triggered unless you take the object off and put it back on again, which will trigger the attach event).

Generally the best way to do something repeatedly is to use a timer event.

So, the sequence I'd suggest here is

  • attach: llResetScript
  • state_entry: llRequestPermissions
  • run_time_permissions: llSetTimerEvent (15.0)
  • timer: llPlaySound, llStartAnimation, and no llSleep

One difference with this scheme is that you will wait 15 seconds after calling llSetTimerEvent until the timer event itself is triggered. To have the sound and animation triggered immediately, you'd have to repeat the llPlaySound and llStartAnimation calls in the run_time_permissions event.

If there is any chance the item to be attached will also be rezzed by itself, take the time to check if the item is attached before requesting permissions... otherwise it will throw errors. That isn't necessary if the request permissions is in the attach event itself, but if it is anywhere else (like in a state_entry) then it is wise...

state_entry()
{
  // whatever other startup code there might be.....
  
  if (llGetAttached()) llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
}

attach(key id)
{
  if (id) llResetScript());
}

 

(BTW, I agree with KT about the method... I also prefer to do the permission request in state_entry since that will let you recompile the code while wearing the item and have it behave as intended while testing.)

Edited by Phate Shepherd
  • Thanks 1
Link to comment
Share on other sites

46 minutes ago, KT Kingsley said:

attach: llResetScript

Why? There's rarely ever a need to restart the whole script every time it's attached or detached.

Considering the simplicity of what's being done, everything could be done in a single attach event (or formally with the help of run_time_permissions).

default
{
    attach(key avatar_uuid)
    {
        if (avatar_uuid != NULL_KEY)
        {
            llRequestPermissions(avatar_uuid, PERMISSION_TRIGGER_ANIMATION);
            llPlaySound(" --SOUND UUID1-- ", 1);
            llSleep(15);
            llPlaySound(" --SOUND UUID2-- ", 1);
            llSleep(30);
            llPlaySound(" --SOUND UUID3-- ", 1);
            llSleep(20);
            llStartAnimation(" --Inventory Animation-- ");
            llPlaySound(" --SOUND UUID4-- ", 1);
        }
    }
}

Each time the script is attached (avatar_uuid is not set to NULL_KEY), the sequence will begin.

llRequestPermissions is made for the current owner and PERMISSION_TRIGGER_ANIMATIONS will be automatically granted because the object is attached.

Edited by Wulfie Reanimator
  • Thanks 1
Link to comment
Share on other sites

if you want the effects to happen repeatedly while wearing the object then you will need a timer

i will show a framework for a way to do this. I leave you to fill in the blanks
 

playeffects()
{
   play 1st effect
   play 2nd effect
   etc
}


attach(key id)
{
  if (id)
    request animation permission  
}

run_time_permissions()
{
    call playeffects
    set timer    
}

timer()
{
   call playeffects
}

 

  • Thanks 1
Link to comment
Share on other sites

I'm finally finished it. It's tested and working! Thanks all for your help, you're great! :)

Here's the working result:

float time = 15;
default
{
    state_entry() 
    {
    
        }
   
    attach(key attached)
    {
        if (attached != NULL_KEY)   
        { 
            llRequestPermissions( llGetOwner(), PERMISSION_TRIGGER_ANIMATION );
        }
    }

    run_time_permissions(integer p)
    {
        if(p & PERMISSION_TRIGGER_ANIMATION)
        {
            llSetTimerEvent(time);
        }
    }

    timer()
    {
        string curranim = llGetInventoryName( INVENTORY_ANIMATION, 0);
        llSleep(5.0);            
        llPlaySound(" --Sound-UUID1-- ",1);
        llStartAnimation( curranim );     
        llSleep(15);
        llPlaySound(" --Sound-UUID2-- ",1);
        llSleep(3.0);            
        llStartAnimation( curranim );     
        llSleep(21);
        llPlaySound(" --Sound-UUID3-- ",1);
        llSleep(30);
        llPlaySound(" --Sound-UUID4-- ",1);
        llSleep(0.5);            
        llStartAnimation( curranim );     
        llSleep(9.5);
        llPlaySound(" --Sound-UUID5-- ",1);
        llSleep(25);
        llPlaySound(" --Sound-UUID6-- ",1);
        llSleep(0.5);            
        llStartAnimation( curranim );    
        llSleep(19.5);   
    }    
}

A linked slave prim only contails a sound preloader and a llOwnerSay chat.

  • Like 3
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1236 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...