User:Cow Taurog/Walk sound

From Second Life Wiki
< User:Cow Taurog
Revision as of 02:38, 4 September 2009 by Cow Taurog (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This script will loop a sound while you're pressing the forward key (walking). Drop it into any attachment. Click it to toggle on/off, hold to bring up a menu of loops to choose from. If you add/remove loops, the name and the key for that song must be in the same position in both of the lists. <lsl> // -Options- list glNames=[

   "Jump",
   "Insane",
   "Rollout",
   "Purple",
   "Blueberry",
   "Stand up"]; // List of menu buttons

list glKeys=[

   "4b41e5b0-effa-5183-8247-488b67f9349e",
   "e3be4540-8d19-2f20-ad19-66929c6419a3",
   "9b004577-b55c-2459-2a0c-eaaf0ae786ab",
   "e2eba00c-0556-6d33-f4e7-54626b502c1e",
   "674ce8ee-9e64-238a-e695-19c3ee8d8527",
   "3eaa225b-d9d2-6d83-c41e-0f9091584ab0"]; // List of sound UUIDs

float gfHold=2; // How long to click and hold for the menu (default is 2) float gfVol=1; // Volume (default is 1)

// -Declarations- integer listen0; // Listen handle integer giChan; // Menu channel integer giHold; // Counter key gkSound; // Selected sound

// -Default state- default{

   on_rez(integer param){llResetScript();}
   changed(integer change){if(change&CHANGED_OWNER){llResetScript();}}
   state_entry(){llStopSound();gkSound=llList2Key(glKeys,0);state waiting;}

}

// -Waiting state- state waiting{

   on_rez(integer param){llResetScript();}
   changed(integer change){if(change&CHANGED_OWNER){llResetScript();}}
   state_entry(){
       giChan=llRound(llFrand((3000-1000)+3000));
       llStopSound();
       llRequestPermissions(llGetOwner(),PERMISSION_TAKE_CONTROLS);
   }
   run_time_permissions(integer perm){if(perm&PERMISSION_TAKE_CONTROLS){llTakeControls(CONTROL_FWD,TRUE,TRUE);}}
   control(key id,integer level,integer edge){integer pressed=level&edge;if(pressed&CONTROL_FWD){state running;}}
   touch_start(integer num){if(llDetectedKey(num-1)==llGetOwner()){giHold=FALSE;llSetTimerEvent(gfHold);}}
   touch_end(integer num){if(giHold==FALSE){llSetTimerEvent(0);state off;}}
   timer(){
       giHold=TRUE;
       llSetTimerEvent(0);
       listen0=llListen(giChan,"",llGetOwner(),"");
       llDialog(llGetOwner(),"Pick a sound...",glNames,giChan);
   }
   listen(integer chan,string name,key id,string mess){
       gkSound=llList2Key(glKeys,llListFindList(glNames,[mess]));
       llListenRemove(listen0);
   }

}

// -Running state- state running{

   on_rez(integer param){llResetScript();}
   changed(integer change){if(change&CHANGED_OWNER){llResetScript();}}
   state_entry(){llLoopSound(gkSound,gfVol);llRequestPermissions(llGetOwner(),PERMISSION_TAKE_CONTROLS);}
   run_time_permissions(integer perm){if(perm&PERMISSION_TAKE_CONTROLS){llTakeControls(CONTROL_FWD,TRUE,TRUE);}}
   control(key id,integer level,integer edge){integer released=~level&edge;if(released&CONTROL_FWD){state waiting;}}
   touch_start(integer num){if(llDetectedKey(num-1)==llGetOwner()){giHold=FALSE;llSetTimerEvent(gfHold);}}
   touch_end(integer num){if(giHold==FALSE){llSetTimerEvent(0);state off;}}
   timer(){
       giHold=TRUE;
       llSetTimerEvent(0);
       listen0=llListen(giChan,"",llGetOwner(),"");
       llDialog(llGetOwner(),"Pick a sound...",glNames,giChan);
   }
   listen(integer chan,string name,key id,string mess){
       gkSound=llList2Key(glKeys,llListFindList(glNames,[mess]));
       llListenRemove(listen0);
   }

} // -Off state- state off{

   on_rez(integer param){llResetScript();}
   changed(integer change){if(change&CHANGED_OWNER){llResetScript();}}
   state_entry(){llStopSound();}
   touch_start(integer num){if(llDetectedKey(num-1)==llGetOwner()){giHold=FALSE;llSetTimerEvent(gfHold);}}
   touch_end(integer num){if(giHold==FALSE){llSetTimerEvent(0);state waiting;}}
   timer(){
       giHold=TRUE;
       llSetTimerEvent(0);
       listen0=llListen(giChan,"",llGetOwner(),"");
       llDialog(llGetOwner(),"Pick a sound...",glNames,giChan);
   }
   listen(integer chan,string name,key id,string mess){
       gkSound=llList2Key(glKeys,llListFindList(glNames,[mess]));
       llListenRemove(listen0);
   }

} </lsl>