Scripting

= //Script It and It Will Work.... Maybe! LOL// =

Free Scripts [|Second Life Wiki Scripting Guide] Schome Script Wiki

=Get started scripting with Autoscript - Second Life Video TuTORial= media type="youtube" key="xW619vHfYeg" height="344" width="425" A [|Torley Linden] Machinima Posted by: Knowclue =//** Scripts **//= = Loop Sound = code format="alt2" //drop this script and your sound file into the object you wish to script. touch the object to start the sound. touch it again to stop it.

integer on = FALSE; string soundname = "soundfilename"; //put sound file name here

default { state_entry { on = FALSE; soundname = llGetInventoryName(INVENTORY_SOUND, 0); }

touch_start(integer total_number) { if(llDetectedKey(0) != llGetOwner) return; if(soundname != "") { if(on) llStopSound; else llLoopSound(soundname, 1); on = !on; } } }

code

= Smooth Sliding Door =

Introduction
It really annoys me that there are so many bad looking doors out there that jerk around. While you can use llSetPos for a sliding door you have no control at what speed it moves. This sliding door script i created because i wanted to time my sliding door movements with the door sounds i had. It uses llMoveToTarget to move the door, with the door temporally turning phantom as it moves. In laggy sims it will behave a little bit funky .. the door sometimes seeming to zoom off to the side before popping into the correct final position as the door becomes a physical object. However, even with that defect it still looks much better IMHO

written by: SimonT Quinnell
code format="code" // ******************************************************************** // // Basic Physical Sliding Door Script // by SimonT Quinnell // 11/07/2009 // // NOTE: If you are going to reposition the door, do it while the door is closed. // Otherwise it will try and use the old close position as a reference point. // // Licensed under the "OpenCollar License" // Ie. Licensed under the GPLv2, with the additional requirement that these scripts remain "full perms" in Second Life. // // ********************************************************************

// ******************************************************************** // CONSTANTS // ********************************************************************

// Movement Constants [|vector]     OFFSET = < -2.0, 0.0 , 0.0 >;      // Directional offset for moving the door [|float]      OPENTIME = 3.5 ;                 // Time taken to open door [|float]      CLOSETIME = 3.5 ;                // Time taken to close door

// Sound/volume to play on open and close, either a UUID or a name in the door contents [|string]     OPENSOUND = "" ; [|float]      OPENVOL = 1.0 ; [|string]     CLOSESOUND = "" ; [|float]      CLOSEVOL = 1.0 ;

// Misc. Constants [|float]      MAX_DISTANCE = 10.00 ;           // Maximum distance the touching avatar can be away

// ******************************************************************** // Variables // ********************************************************************

[|vector]     vPosition; [|rotation]   rRot; [|float]      omega= 0.0 ; [|vector]     vTargetPos; [|integer]    bOpen = FALSE; [|integer]    bMoving = FALSE;

// ******************************************************************** // Functions // ********************************************************************

MoveDoor {    [|if] ( !bOpen ) {  // Initial conditions rRot = [|llGetRot] ; vPosition = [|llGetPos] ;

// Target Position omega=OPENTIME/ [|llVecDist] ( < 0, 0 , 0 >,OFFSET ) ; vTargetPos = vPosition+OFFSET*rRot;

// Set the timer to cleanup position .. nesessary for laggy sims [|llSetTimerEvent] ( OPENTIME ) ;

bOpen = [|TRUE] ; [|if] ( OPENSOUND != "" ) [|llTriggerSound] ( OPENSOUND, OPENVOL ) ; } [|else] {        // Target Position omega=CLOSETIME/ [|llVecDist] ( < 0, 0 , 0 >,OFFSET ) ; vTargetPos = vPosition;

// Set the timer to cleanup position .. nesessary for laggy sims [|llSetTimerEvent] ( CLOSETIME ) ;

bOpen = FALSE; [|if] ( CLOSESOUND != "" ) [|llTriggerSound] ( CLOSESOUND, CLOSEVOL ) ; }

// Set Door Physical and move it    bMoving = [|TRUE] ; [|llSetStatus] ( [|STATUS_PHANTOM], [|TRUE] ) ; [|llSetStatus] ( [|STATUS_PHYSICS], [|TRUE] ) ; [|llMoveToTarget] ( vTargetPos,omega ) ; }

[|default] {    [|state_entry] {  // Initial conditions rRot = [|llGetRot] ; vPosition = [|llGetPos] ; }

[|touch_start] ( [|integer] num_detected ) {        [|key]         keyTouchingAvatar = [|llDetectedKey] ( 0 ) ; [|float]      distance = [|llVecDist] ( [|llGetPos] , [|llDetectedPos] ( 0 )) ;

[|if] ( distance < MAX_DISTANCE && !bMoving ) MoveDoor ; }

[|timer] {        // Clean up Position bMoving = FALSE; [|llSetTimerEvent] ( 0.0 ) ; [|llSetStatus] ( [|STATUS_PHYSICS], FALSE ) ; [|llSetStatus] ( [|STATUS_PHANTOM], FALSE ) ; [|llSetPrimitiveParams] ([ [|PRIM_POSITION], vTargetPos, [|PRIM_ROTATION] , rRot ]) ; } } code

= Non-Physics Vehicle Scrip =

The non-[|physical] [|script], [|created] by [|Derek Jones], accompanied the [|Battleship Galaxy], a cruiser created by [|Nick Fairlight] back in 2003. The script underwent many edits by other [|members] of the community before becoming completely finished August 5, 2003. The code is as follows:

code //Redesign of the Moving Ship Script (also by Derek Jones)

//Script to move non-physical objects via control inputs

//Original Script created by Derek Jones on 08/05/03

//Variations by Jericho Powers, Christopher Omega and Nick Fairlight

//Newly Modified Version created 6/24/04

//Say "Engage" to start the script, "Disengage" to stop, and click the object for control. Say "stop" to stop all movement.

//Some code has been edited out for the open source release, including speed, which was controlled by other objects in my custom ship

//To use, drop on any object, preferably one with no rotation for best effect.

rotation grot; //The current Rot rotation gtarrot; //Destination rot (steps) vector gcurpos; //Current position vector gtopos; //Target position vector increment = <1, 0, 0>; //Forward steps per interval vector increment2 = <0, 0, 1>; //Steps for vertical movement per interval float interval = 0.1; //Time between steps key gowner; //Key of pilot (used for recodnizing the owner from another) string copilot; //Name of co-pilot vector currentpos; //Vector currently located vector setposz; //Vertical increment going up vector setposaz; //Vertical increment going down string speed; //The Speed Setting integer LEVELS = 0; //Levels (duh lol) default {   state_entry {

gowner=llGetOwner;//gowner is default as the owner. copilot = ""; //Fill the name of the co-pilot //llMessageLinked(LINK_SET, 0, speed, "a"); state enginesoff; } } state enginesoff {   state_entry {       llReleaseControls; llSay(0, "Engines offline."); llListen(0, "", gowner, ""); llListen(0, copilot, "", ""); }   listen(integer channel, string name, key id, string message) {       if(message=="Engage") {         llSay(0, "Script engaging..."); state engineson; }   } } state engineson {   state_entry {       LEVELS = CONTROL_FWD | CONTROL_BACK   | CONTROL_UP | CONTROL_DOWN | CONTROL_LEFT | CONTROL_RIGHT; speed = "Default Speed: No Control"; llSay(0, "Script on and idle"); //llSay(0, "Speed set to "+speed); llListen(0, "", gowner, ""); llListen(0, copilot, "", "");

}

touch_start(integer total) {       if((llDetectedKey(0)==gowner)) {

integer perm = llGetPermissions; if (perm) {               llReleaseControls; }           else {               llRequestPermissions(llDetectedKey(0), PERMISSION_TAKE_CONTROLS); }       if((llKey2Name(llDetectedKey(0))==copilot)) {

integer perm = llGetPermissions; if (perm) {               llReleaseControls; }           else {               llRequestPermissions(llDetectedKey(0), PERMISSION_TAKE_CONTROLS); }   }

}   run_time_permissions(integer perm) {        if (perm == PERMISSION_TAKE_CONTROLS) {           llSay(0, "Permissions granted."); //speed = "Default Speed"; //llMessageLinked(LINK_SET, 0, "Speed: "+speed, "a"); llTakeControls(LEVELS, TRUE, FALSE); }       else {           state engineson; }   }

listen(integer channel, string name, key id, string message) {        if(message == "stop") {           llSay(0, "Halting movement..."); llSetTimerEvent(0); }       if(message == "Disengage") {           llSay(0, "Script Shutdown Beginning"); llSleep(3); llResetScript; }

//if(message=="Default Speed"){ // llSay(0, "Switching to default speed of ship"); //speed = "Default Speed"; //llMessageLinked(LINK_SET, 0, "Speed: "+speed, "a"); //increment = <1,0,0>; //increment2 = <0, 0,1>; //interval = .10; //}

//if(message=="Low Speed"){ // llSay(0, "Switching to lowest speed of ship"); //speed = "Low Speed"; //llMessageLinked(LINK_SET, 0, "Speed: "+speed, "a"); //increment = <.1,0,0>; //increment2 = <0, 0,.1>; //interval = .20; //}       //if(message=="High Speed"){ // llSay(0,"Switching to highest speed of ship"); //speed = "High Speed"; //llMessageLinked(LINK_SET, 0, "Speed: "+speed, "a"); //increment = <3,0,0>; //increment2 = <0, 0,3>; //interval = .10; //}       //if(message=="Ludicrus Speed"){ // llSay(0, "Sir, we've never gone that fast before. I'm not sure if the ship can take it! Ah hell I'll do it anyways :-p"); //speed = "Ludicrus Speed"; //llMessageLinked(LINK_SET, 0, "Speed: "+speed, "a"); //increment = <10,0,0>; //increment2 = <0, 0,10>; //interval = .1; //}       //if(message=="superup") //{          //  currentpos=llGetPos; //llSay(0,"The ship will now go to the set height of 477 Meters. Please sit down and remained seated until notified to get up."); //llSleep(2); //state superup; //}       //if(message=="Default Level") //{          // currentpos=llGetPos; //setposaz=+<0, 0, 50>; //llSay(0, "The ship will now go to the height of "+(string)setposaz.z+" Meters. "); //llSleep(2); // state defaultlevel; //}       //if(message=="Water Level") //{           //currentpos=llGetPos; //setposz=+<0, 0, 9.018>; //llSay(0, "The ship will now go to the height of "+(string)setposz.z+" Meters. Please sit down and remained seated until notified to get up."); //llSleep(2); //state waterlevel; //}

}   control(key id, integer level, integer edge) {       if(level & CONTROL_FWD) {           llSetTimerEvent(0); llSay(0, "Cruising Forward"); increment.x = llFabs(increment.x); llSetTimerEvent(interval); }       if(level & CONTROL_BACK) {           llSetTimerEvent(0); llSay(0, "Cruising Backward"); increment.x = -1*llFabs(increment.x); llSetTimerEvent(interval); }       if(level & CONTROL_UP) {           llSetTimerEvent(0); llSay(0, "Increasing Altitude"); state goingup;

}       if(level & CONTROL_DOWN) {           llSetTimerEvent(0); llSay(0, "Decreasing Altitude"); state goingdown; }       if(level & CONTROL_LEFT) {           llSetTimerEvent(0); llSay(0, "Shifting Left"); integer i = 0; while(i<9) {           grot = llGetRot; gtarrot = grot*<0.00000, 0.00000, 0.08716, 0.99619>; llSetRot(gtarrot); i++; }   }        if(level & CONTROL_RIGHT) {           llSetTimerEvent(0); llSay(0, "Shifting Right"); integer i = 0; while(i<9) {           grot = llGetRot; gtarrot = grot*<0.00000, 0.00000, -0.08716, 0.99619>; llSetRot(gtarrot); i++; }   } }

timer {       grot = llGetRot; gcurpos = llGetPos; gtopos = increment*grot + gcurpos; llSetPos(gtopos); }

} //state superup //{  // state_entry //{     //  llSetTimerEvent(.1); // }   //timer //{     //  if(llGetPos!=) //{       //llSetPos(); // }   //else if(llGetPos==) // { //llSay(0, "It is now safe to stand up."); //   llSetTimerEvent(0); // state engineson; //} //} //} //state defaultlevel //{ //  state_entry // {    //    llSetTimerEvent(.1); // }   //timer //{     //  if(llGetPos!=setposaz) // {      // llSetPos(setposaz); //}   //else if(llGetPos==setposaz) // {        //llSay(0, "Reached height"); //llSetTimerEvent(0); // state engineson; //} //} //} //state goingup //{  // state_entry //{     //  increment2.z = llFabs(increment2.z); // llSetTimerEvent(interval); // llListen(0, "", gowner, ""); // llListen(0, copilot, "", ""); //}    //listen(integer channel, string name, key id, string message) //{     //   if(message=="status") // {        //   vector currentpos=llGetPos; //llSay(1431, "We are currently located at "+(string)currentpos.x+" -- "+(string)currentpos.y+" -- "+(string)currentpos.z+"."); //llSleep(1); //} //if(message=="stop"){ //    llShout(1431, "Stopping altitude increasment"); //  llSetTimerEvent(0.0); // state engineson; //}   //}   // timer //{     //   grot = llGetRot; //gcurpos = llGetPos; //gtopos = increment2*grot + gcurpos; //llSetPos(gtopos); //} //}

//state goingdown //{  // state_entry //{     //  llListen(0, "", gowner, ""); //llListen(0, copilot, "", ""); // increment2.z = -1*llFabs(increment2.z); //llSetTimerEvent(interval); //}   //listen(integer channel, string name, key id, string message) //{

// if(message=="status") // {         //  vector currentpos=llGetPos; //llSay(1431, "We are currently located at "+(string)currentpos.x+" -- "+(string)currentpos.y+" -- "+(string)currentpos.z+"."); //llSleep(1); //} //else if(message=="stop") //{  //     llShout(1431, "Stopping altitude decreasment"); // llSetTimerEvent(0.0); // state engineson; //}   //}

//timer //{     //   grot = llGetRot; // gcurpos = llGetPos; //gtopos = increment2*grot + gcurpos; //llSetPos(gtopos); //} //} //state waterlevel //{ //  state_entry //{     //  llSetTimerEvent(.1); // }  // timer //{     //  if(llGetPos!=setposz) // {       //llSetPos(setposz); //}  // else if(llGetPos==setposz) //   { //llSay(0, "It is now safe to stand up."); //   llSetTimerEvent(0); // state engineson; //} //} //}

code