User:Mr Lovenkraft

From Second Life Wiki
Revision as of 16:16, 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>


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>