Difference between revisions of "User:Zai Lynch/Sandbox/LSL Goodies"

From Second Life Wiki
Jump to: navigation, search
m (notcard reader script (uncommented))
(TP via map)
Line 22: Line 22:
 
//                                                  //
 
//                                                  //
 
//        Simple Countdown Script                  //
 
//        Simple Countdown Script                  //
//            Released under                      //
+
//            released under                      //
 
//  Creative Commons Attribution-Share Alike 3.0    //
 
//  Creative Commons Attribution-Share Alike 3.0    //
 
//              by Zai Lynch                        //
 
//              by Zai Lynch                        //
Line 85: Line 85:
 
//                                                  //
 
//                                                  //
 
//          Basic Notecard-Reader                  //
 
//          Basic Notecard-Reader                  //
//            Released under                      //
+
//            released under                      //
 
//  Creative Commons Attribution-Share Alike 3.0    //
 
//  Creative Commons Attribution-Share Alike 3.0    //
 
//              by Zai Lynch                        //
 
//              by Zai Lynch                        //
Line 249: Line 249:
 
== Script 3 ==
 
== Script 3 ==
 
<div style="padding: 0.5em">
 
<div style="padding: 0.5em">
script
+
Set the description of the prim this script is attached to, to: ''SIMNAME/X/Y/Z''<br>
 +
The script will read the description and open the map at the defined position in case it is clicked.<br>
 +
Click and hold the prim clicked for more then 4 seconds in order to re-initialize the script.
 +
 
 +
<lsl>
 +
//////////////////////////////////////////////////////
 +
//                                                  //
 +
//            Teleport via Map                      //
 +
//            released under                      //
 +
//  Creative Commons Attribution-Share Alike 3.0    //
 +
//              by Zai Lynch                        //
 +
//                                                  //
 +
//////////////////////////////////////////////////////
 +
 
 +
string simname;
 +
vector pos;
 +
integer touchStartTime;
 +
 
 +
 
 +
 
 +
init()
 +
{
 +
    if (llGetObjectDesc() != "")
 +
    {
 +
    string desc = llGetObjectDesc();
 +
    simname = llGetSubString(desc,0,llSubStringIndex(desc,"/")-1);
 +
    desc = llGetSubString(desc,llSubStringIndex(desc,"/")+1,llStringLength(desc)+1);
 +
    integer x = (integer)llGetSubString(desc,0,llSubStringIndex(desc,"/")-1);
 +
    desc = llGetSubString(desc,llSubStringIndex(desc,"/")+1,llStringLength(desc)+1);
 +
    integer y = (integer)llGetSubString(desc,0,llSubStringIndex(desc,"/")-1);
 +
    desc = llGetSubString(desc,llSubStringIndex(desc,"/")+1,llStringLength(desc)+1);
 +
    integer z = (integer)llGetSubString(desc,0,llStringLength(desc)-1);
 +
    pos = <x,y,z>;
 +
    }
 +
    else
 +
    {
 +
        simname="Omidyar";
 +
        pos=<130,86,200>;
 +
    }
 +
}
 +
   
 +
 
 +
default
 +
{
 +
   
 +
    state_entry()
 +
    {
 +
        init();
 +
    }
 +
   
 +
    touch_start(integer num_detected)
 +
    {
 +
        touchStartTime = llGetUnixTime();
 +
    }
 +
   
 +
 
 +
    touch_end(integer num_detected)
 +
    {
 +
        if (llGetUnixTime() > touchStartTime + 4)
 +
        {
 +
            llSay(0,"Resetting...");
 +
            init();
 +
        }
 +
        else
 +
        llMapDestination(simname, pos, <1,1,1> );
 +
    }
 +
 
 +
}
 +
</lsl>
 
</div></div>
 
</div></div>
  

Revision as of 21:22, 5 June 2008


Intro

So just for the record: I'm a complete LSL n00b. So don't expect much from this page. 'Cause I love the Open Source concept, I'd like to share some of my scripts with other SL Residents =)
Since these are contributions to the SL Wiki, all scripts are released under Creative Commons Attribution-Share Alike 3.0 License.


Simple Countdown

This script displays a hovering countdown above the item it's placed in.


<lsl> ////////////////////////////////////////////////////// // // // Simple Countdown Script // // released under // // Creative Commons Attribution-Share Alike 3.0 // // by Zai Lynch // // // //////////////////////////////////////////////////////


integer DAYS = 28; // Days until the countdown finishs integer HOURS = 6; // Hours until the countdown finishs integer MINUTES = 42; // Minutes until the countdown finishs integer SECONDS = 12; // Seconds until the countdown finishs string TEXT = "The end of the world will come in"; // Additional text defining the event string FINISHED = "uh oh..."; // Text displayed when event happened vector COLOR = <1,1,1>; // Color of the displayed text


countdown() {

   llSetText(TEXT+"\n"+(string)(SECONDS/86400)+" days, "
       +(string)((SECONDS%86400)/3600)+" hours, "
       +(string)(((SECONDS%86400)%3600)/60)+" minutes, "
       +(string)(((SECONDS%86400)%3600)%60)+ "seconds.",COLOR,1);

}


default {

   state_entry()
   {
       SECONDS = SECONDS + MINUTES * 60 + HOURS * 3600 + DAYS * 86400;
       llSetTimerEvent(1);
       countdown();
   }


   timer()
   {
       if (SECONDS > 0)
       {
           SECONDS = SECONDS - 1;
           countdown();
       }
       else 
       {
           llSetText(FINISHED, COLOR,1);
           llSetTimerEvent(0);
       }
   }

} </lsl>


Basic Notecard-Reader

This script reads notecards placed in the same prim as the script itself.

<lsl> ////////////////////////////////////////////////////// // // // Basic Notecard-Reader // // released under // // Creative Commons Attribution-Share Alike 3.0 // // by Zai Lynch // // // //////////////////////////////////////////////////////


// Constants

integer CHANNEL = 2130214; list MENU = ["Forward", "Backward", "Load", "Play", "Stop", "Time"];

// Variables list gMenuNC; integer gLine = 0; integer gTime = 5; string gNC = "";


zlGenerateList() {

   integer i;
   integer n = llGetInventoryNumber(INVENTORY_NOTECARD);
   string name;
   gMenuNC = [];
   if (n > 0)
   {
       for (i=0; i<n; i++)
       {
           name = llGetInventoryName(INVENTORY_NOTECARD, i);
           if (llStringLength(name) < 25)
               gMenuNC = gMenuNC + [name];
           else 
           {
               llSay(0, "Name: "+name + " is to long.");
               llRemoveInventory(name);
               llSay(0, "Notecard removed.");
           }
       }
   }
   if (gNC == "") gNC=llGetInventoryName(INVENTORY_NOTECARD,0);

}


default {

   state_entry()
   {
       zlGenerateList();
       llListen(CHANNEL, "", llGetOwner(), "");
       llListen(CHANNEL+1, "", llGetOwner(), "");
   }
   
   on_rez(integer start_param)
   {
       llResetScript();
   }
   
   changed(integer change)
   {
       if (change == CHANGED_INVENTORY) zlGenerateList();
   }
   
   touch_start(integer num)
   {
       if (llDetectedKey(0) == llGetOwner()) llDialog(llGetOwner()," ",MENU,CHANNEL);
   }
   
   listen(integer cha, string name, key id, string msg)
   {
       if (cha == CHANNEL)
       {
           if (msg == "Stop") 
           {
               llSetTimerEvent(0);
               llDialog(llGetOwner()," ",MENU,CHANNEL);
           }
           if (msg == "Play") 
           {
               llSetTimerEvent(gTime); 
               llGetNotecardLine(gNC, gLine); 
               llDialog(llGetOwner()," ",MENU,CHANNEL);
           }
           if (msg == "Forward") 
           {
               gLine = gLine + 1; 
               llGetNotecardLine(gNC, gLine); 
               llDialog(llGetOwner()," ",MENU,CHANNEL); 
               llSetTimerEvent(0);
           }
           if ((msg == "Backward") && (gLine > 0)) 
           {
               gLine = gLine - 1; 
               llGetNotecardLine(gNC, gLine); 
               llDialog(llGetOwner()," ",MENU,CHANNEL); 
               llSetTimerEvent(0);
           }
           if (msg == "Load") 
               llDialog(llGetOwner(), " ", gMenuNC, CHANNEL+1);
           if (msg == "Time") 
               state listening;
       }
       if (cha == (CHANNEL+1))
       {
           gNC = msg;
           gLine = 0;
           llDialog(llGetOwner()," ",MENU,CHANNEL);
       }
   }
   
   timer()
   {
       gLine = gLine+1;  
       llGetNotecardLine(gNC, gLine);
   }
   
   dataserver(key qid, string data)
   {
       llSay(0, data);        
   }
   
   state_exit()
   {
       llSetTimerEvent(0);
   }
       

}

state listening {

   state_entry()
   {
       llSetTimerEvent(30);
       llListen(0, "", llGetOwner(), "");
       llSay(0,"Please tell me the desired updatetime in seconds.");
   }
   
   listen(integer cha, string name, key id, string msg)
   {
       gTime = (integer)msg;
       llSay(0, "Time set.");
       state default;
   }    
   
   timer()
   {
       llSay(0,"Sorry, the request timed out.");
       state default;
   }
   
   state_exit()
   {
       llSetTimerEvent(0);
       llDialog(llGetOwner()," ",MENU,CHANNEL);
   }

} </lsl>


Script 3

Set the description of the prim this script is attached to, to: SIMNAME/X/Y/Z
The script will read the description and open the map at the defined position in case it is clicked.
Click and hold the prim clicked for more then 4 seconds in order to re-initialize the script.

<lsl> ////////////////////////////////////////////////////// // // // Teleport via Map // // released under // // Creative Commons Attribution-Share Alike 3.0 // // by Zai Lynch // // // //////////////////////////////////////////////////////

string simname; vector pos; integer touchStartTime;


init() {

   if (llGetObjectDesc() != "")
   {
   string desc = llGetObjectDesc();
   simname = llGetSubString(desc,0,llSubStringIndex(desc,"/")-1);
   desc = llGetSubString(desc,llSubStringIndex(desc,"/")+1,llStringLength(desc)+1);
   integer x = (integer)llGetSubString(desc,0,llSubStringIndex(desc,"/")-1);
   desc = llGetSubString(desc,llSubStringIndex(desc,"/")+1,llStringLength(desc)+1);
   integer y = (integer)llGetSubString(desc,0,llSubStringIndex(desc,"/")-1);
   desc = llGetSubString(desc,llSubStringIndex(desc,"/")+1,llStringLength(desc)+1);
   integer z = (integer)llGetSubString(desc,0,llStringLength(desc)-1);
   pos = <x,y,z>;
   }
   else
   {
       simname="Omidyar";
       pos=<130,86,200>;
   }

}


default {

   state_entry()
   {
       init();
   }
   
   touch_start(integer num_detected)
   {
       touchStartTime = llGetUnixTime();
   }
   
   touch_end(integer num_detected)
   {
       if (llGetUnixTime() > touchStartTime + 4)
       {
           llSay(0,"Resetting...");
           init();
       }
       else 
       llMapDestination(simname, pos, <1,1,1> );
   }

} </lsl>


Zai landing.png