User:Zai Lynch/Sandbox/LSL Goodies

From Second Life Wiki
Jump to: navigation, search


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

script


Zai landing.png