User:Mr Lovenkraft

From Second Life Wiki
Revision as of 16:57, 3 February 2008 by Mr Lovenkraft (talk | contribs)
Jump to navigation Jump to search

Open source codes from Mr Lovenkraft


I've just starting this page in the hopes of having quite a few codes open sourced for those of you who either can't find what you are looking for, or just want an easy place to look for codes :)


Removable prim clothing script

This script is written to be placed in the root prim of an object. <lsl> //Removable clothing by Mr Lovenkraft, free to use by anyone. //Fully open source, but credit going to Mr Lovenkraft for his effort :) key user; //Person touching the clothing. key owner; //The owner of course O.o integer diaChan; //Random Dialog channel to prevent other clothing items from listening.. integer listenNum; //Used to start a listen, and remove it. list buttons = ["Tear", "Look", "Flick", "Tug"];//Buttons to click on of course. integer touchable = TRUE; integer removeable; int()//The actual starting menu and calculating random channel to listen on. {

   touchable = FALSE;
   diaChan = llCeil(llFrand(-9999999));
   if(diaChan >= 0) //Just in case it returns 0, we want a negative listen :)
   {
       diaChan += llRound(llFrand(-9999999)); //Recalculate
   }
   listenNum = llListen(diaChan, "", "", "");//Listen handler to remove listen when done.
   llDialog(user, "What would you like to do?", buttons, diaChan); //Menu with the buttons o.o
   llSetTimerEvent(15); //Menu time out, in case someone doesn't pick an option :)

} default {

   on_rez(integer r)
   {
       owner = llGetOwner(); //Of course it gets the owner O.o
   }
   state_entry()
   {
       owner = llGetOwner(); //Again just in case it didn't get the point.
   }
   touch_start(integer total_number)
   {
       if(touchable) //If it hasn't been touched, let it be touched
       {
           user = llDetectedKey(0); //Makes the person touching, the owner.
           int(); //When touched, get the random channel.
       }
   }
   attach(key av)
   {
       if(av)
       {
           removeable = TRUE; //If actually on an av, allow clothing to request permissions for detach.
       }
       else
       {
           removeable = FALSE; //Oposite if no av :)
       }
   }
   run_time_permissions(integer perm)
   {
       if(perm & PERMISSION_ATTACH)
       {
           llWhisper(0, llKey2Name(user) + " rips " + llKey2Name(owner) +"'s clothing right off!");
           llDetachFromAvatar( ); //Detach from av of course.
       }
   }
   listen(integer chan, string name, key id, string msg)
   {
       if(llToLower(msg)=="tug") //We use llToLower(msg) so that it's not case sensitive. :)
       {
           llWhisper(0, llKey2Name(user) + " tugs on " + llKey2Name(owner) +"'s clothing.");
       }
       if(llToLower(msg)=="flick")
       {
           llWhisper(0, llKey2Name(user) + " flicks " + llKey2Name(owner) +"'s clothing.");
       }
       if(llToLower(msg)=="look")
       {
           llWhisper(0, llKey2Name(user) + " looks at " + llKey2Name(owner) +"'s clothing.");
       }
       if(llToLower(msg)=="tear")
       {
           if(removeable)
           {
               llRequestPermissions(owner, PERMISSION_ATTACH);
           }
           else
           {
               llWhisper(0, "Can not remove clothing that is not worn.");
           }
       }
       touchable = TRUE;
       llListenRemove(listenNum); //Stop listening to prevent lag :)
   }
   timer()
   {
       touchable = TRUE;
       llSetTimerEvent(0.0); //Stops the timer
       llWhisper(0, "Menu time out...");
   }

} </lsl>


Stop all animations: basic

<lsl> //Stop all animations by Mr Lovenkraft //Useful learning codes from the large inventory of Mr Lovenkraft ;) list anims; key av; default {

   touch_start(integer total_number)
   {
       llRequestPermissions(llDetectedKey(0), PERMISSION_TRIGGER_ANIMATION);//Dur, requests permissions.
       av = llDetectedKey(0); //Person to stop animations for.
   }
   run_time_permissions(integer perm)//Runs if we get permissions.
   {
       anims = []; //Clears the list of any past animations.
       anims = llGetAnimationList(av); //Gets the current users animations playing.
       integer index = llGetListLength(anims); //The amount of animations for stopping.
       integer i; //Starting place for our loop.
       for(i=0; i<index; i++)//Runs through for each animation in the list.
       {
           llStopAnimation(llList2String(anims, i)); //Stops the animation in the list at point i.
       }
   }

} </lsl>


Single pose: pose ball

Single animation poseball that uses the animation in the inventory <lsl> //Basic Poseball script default {

   state_entry()
   {
       llSitTarget(<0.0, 0.0, -0.5>, ZERO_ROTATION);//Sets a sit target to actually work
   }
   changed(integer change) 
   {
       if (change & CHANGED_LINK) 
       { 
           key av = llAvatarOnSitTarget();
           if (av)//If there is an av on it
           {
               llRequestPermissions(av, PERMISSION_TRIGGER_ANIMATION);//Ask permissions
           }
       }
   }
   run_time_permissions(integer perm)
   {
       if(perm & PERMISSION_TRIGGER_ANIMATION)
       {
           llStopAnimation("sit");//Stops the default sit
           llStartAnimation(llGetInventoryName(INVENTORY_ANIMATION,0));//Start the animation inside the prim
       }
   }

} </lsl>


Cycle pose ball: touch cycle

<lsl> //Multi poseball/pole by Mr lovenkraft //Open sourced ;) list anims; key av; integer pos; integer listSize; integer sat_on; int() {

   if(sat_on)
   {
       llRequestPermissions(av, PERMISSION_TRIGGER_ANIMATION);//Request permissions to get the next animation
   }
   else
   {
       llWhisper(0, "No one sitting on this object.");
   }

} default {

   state_entry()
   {
       pos = 0;
       anims = [];
       llSitTarget(<0.0, 0.0, 0.1>, ZERO_ROTATION);//Sets the sit pose for the target
   }
   changed(integer change)//something has changed with this object
   {
       if(change & CHANGED_INVENTORY)//if only the inventory is changed of course ;)
       {
           pos = 0;//start the post over
           anims = []; //clear the list
           integer i;
           integer totA = llGetInventoryNumber(INVENTORY_ANIMATION);//gets the total animations
           for(i=0; i<totA; i++)
           {
               anims += [llGetInventoryName(INVENTORY_ANIMATION, i)];//adds each animation name to list
           }
           llOwnerSay("Animaions inside: " + llList2CSV(anims));//Tell the owner how many animations inside
       }
       if(change & CHANGED_LINK)
       {
           av = llAvatarOnSitTarget();
           if(av) //if there is really someone sitting on it
           {
               sat_on = TRUE; //If someone is sitting make it true
               int();//Start animation
           }
           else
           {
               sat_on = FALSE;
           }
       }
   }
   run_time_permissions(integer perm)//got permissions from user
   {
       if(perm & PERMISSION_TRIGGER_ANIMATION)
       {
           llStopAnimation(llGetInventoryName(INVENTORY_ANIMATION, pos));//Stop last animation
           pos += 1;//go to next in list
           if(pos >= listSize)//if at the end of the list
           {
               pos = 0;
           }
           llStopAnimation("sit");
           llStartAnimation(llGetInventoryName(INVENTORY_ANIMATION, pos));//Start the next animation
       }
   }
   touch_start(integer total_number)
   {
       listSize = llGetListLength(anims);
       int(); //start the new animation
   }

} </lsl>


Basic notecard access list

This is an example notecard, goes in the room prim of lockable object

Mr Lovenkraft
Fname2 Lastname2
Fname3 Lastname3

This also goes in your object you wish to lock/unlock etc <lsl> list allowed = []; string allow_list = "Allow"; key owner; key note_card; integer line; integer list_pos; integer i; integer locked; int(integer on) {

   if(on==0)
   {
       llWhisper(0, "Locked, only allowed may use.");
       locked = TRUE;
   }
   if(on==1)
   {
       llWhisper(0, "Unlocked, anyone may use.");
       locked = FALSE;
   }
   if(on==3)
   {
       allowed = [];
       note_card = llGetNotecardLine(allow_list, line);
   }

} default {

   on_rez(integer r)
   {
       list_pos = 0;
       line = 0;
       int(3);
       owner = llGetOwner();
   }
   state_entry()
   {
       int(3);
       list_pos = 0;
       line = 0;
       llListen(0, "", owner, "");
       note_card = llGetNotecardLine(allow_list, line);
       llOwnerSay((string)llGetFreeMemory());
   }
   changed(integer change)
   {
       if(change & CHANGED_INVENTORY)
       {
           int(3);
       }
   }
   listen(integer chan, string name, key id, string msg)
   {
       if(llToLower(msg)=="lock")
       {
           int(0);
       }
       if(llToLower(msg)=="unlock")
       {
           int(1);
       }
   }
   touch_start(integer t)
   {
       if(locked)
       {
           string Ntest = llDetectedName(0);
           integer index = llListFindList(allowed, [Ntest]);
           if(index != -1)
           {
               llWhisper(0,"Opened for: "+llList2String(allowed, index)+".");
           }
           else
           {
               llWhisper(0, "You are not on the access list.");
           }
       }
       else
       {
           llWhisper(0, "Opened.");
       }
   }
   dataserver(key Qid, string data)
   {
       if (Qid == note_card)
       {
           if (data != EOF)
           {
               allowed += data;
               line += 1;
               note_card = llGetNotecardLine(allow_list, line);
           }
           else
           {
               line = 0;
               llOwnerSay("Done.");
               llOwnerSay(llList2CSV(allowed));
               llOwnerSay("Memory left: "+(string)llGetFreeMemory());
           }
       }
   }

}

</lsl>


Greeter: landmark/notecard giver

This uses two scripts, one for detect and give, and one for handling the list and seeing if that person has been given a notecard/landmark.

Greeter <lsl> //Greeter by Mr Lovenkraft key owner; integer counter; //Total amount of people greeted key user; //Person to greet default {

   on_rez(integer r)
   {
       llResetScript();
   }
   state_entry()
   {
       counter = 0;
       llMessageLinked(LINK_THIS, 0, "clear", NULL_KEY); //Clears the greeted list
       owner = llGetOwner(); //Gets the new owner
   }
   collision_start(integer c)
   {
       user = llDetectedKey(0); //Person colliding with the object is the user
       if(counter >= 70)//If our counter goes to 70 or higher (this prevents the list from getting to big)
       {
           llMessageLinked(LINK_THIS, 0, "clear", NULL_KEY);//Clear the list again
           counter = 0;//Reset the counter
       }
       llMessageLinked(LINK_THIS, 10, llDetectedName(0), NULL_KEY);//Sends the name to be greeted
   }
   link_message(integer sender, integer num, string str, key id)
   {
       if(str=="give")
       {
           llGiveInventory(user, llGetInventoryName(INVENTORY_NOTECARD, 0));//Give notecard
           llGiveInventory(user, llGetInventoryName(INVENTORY_LANDMARK, 0));//Give landmark
           counter += 1;//Add one to our counter
       }
   }

} </lsl>

User handler: List to keep track of people, so that it prevents multiple copies to the same user <lsl> list names;//Names of people greeted since last reset string test;//Name to test with the list integer index; default {

   on_rez(integer r)
   {
       llResetScript();
   }
   state_entry()
   {
       names = [];//Clear the names on rez
   }
   link_message(integer sender, integer num, string str, key id)
   {
       if(str == "clear")
       {
           names = [];//Resets the list
       }
       if(num == 10)
       {
           test = str;//Makes the name sent by the greeter the test
           index = llListFindList(names, [test]); //Checks to see if it is in the list
           if(index == -1)//If not found in the list
           {
               names += str;//Add the name to the list if not found
               llMessageLinked(LINK_THIS, 0, "give", NULL_KEY);//Greet the new user
           }
       }
   }

} </lsl>