User:Fred Gandt/Scripts/Continued 1

From Second Life Wiki
Jump to navigation Jump to search
FG jpg.jpg

My Contributions

I have implemented a V# system to make it more obvious if a script is updated. The V# forms part of the title of each script.

If you have any comments about the content of this page please post them HERE

More Pages

Free Scripts (content constantly updating)

More Free Scripts (this page)

Even More Free Scripts (content constantly updating)

Even More More Free Scripts (content constantly updating)

Even More More More Free Scripts (content constantly updating)

Legal Stuff

The legal stuff about contributing to this wiki (worth reading).

Tuition

Tuition scripts, notes, videos and screenshots etc. (hardly any content yet)

Free Scripts

Limited Use L$ Gift Giver ( V1 )

TAKE CARE WITH THIS ONE. IT WILL DEDUCT L$ FROM YOUR ACCOUNT ONCE YOU GRANT PERMISSIONS

I WAS ASKED TO MAKE IT THIS WAY. IT WAS DESIGNED TO BE REZZED FOR SHORT PERIODS OF TIME

IF TOO MANY AGENTS USE IT THE MEMORY WILL RUN OUT AND IT WILL FAIL

<lsl>// V1 //

key owner; // Global variable to store the owner UUID (key)

integer perms; // Global to store the condition of the request for permissions.

integer count; // Global counter.

list visitors; // This stores the keys of all the agents who take the gift. They will be allowed only one gift.

integer ammount = 1; // Change this figure to the required ammount to give away (e.g. 5). Then drop in your object.

default {

   on_rez(integer param)
   {
       llResetScript(); // Clear all lists and reset all variables. This action will also clear the permissions.
   }
   changed(integer change)
   {
       if(change & CHANGED_OWNER) // If the script or object changes ownership the script will not be able
       llResetScript();           // to deduct cash from the previous owners account.
   }
   state_entry()
   {
       owner = llGetOwner(); // Store the owners key.
       llRequestPermissions(owner, PERMISSION_DEBIT); // !! THIS MEANS IT WILL TAKE YOUR MONEY !!
   }
   run_time_permissions(integer perm)
   {
       if(perm & PERMISSION_DEBIT) // Have we got the permissions we requested?
       perms = TRUE; // Store the result of success.
       else
       llRequestPermissions(owner, PERMISSION_DEBIT); // If not we ask for them again.
   }
   touch_end(integer nd)
   {
       do // Loop through the detected touchers to cover the rare cases when
       {  // more than one agent touches the object at the same time.
           key toucher = llDetectedKey(count);
           if(llListFindList(visitors, [toucher]) == -1) // Check if the agent has touched us before by searching the list for a match.
           {
               if(perms) // Check if we have permissions.
               {
                   llGiveMoney(toucher, ammount); // Ker-ching!!
                   visitors += [toucher]; // That's all buster! NEXT!!
               }
           }
       }
       while((++count) < nd); // Increment the counter and loop while it is less than the number of touchers detected.
       count = 0; // Reset the counter.
   }

}</lsl>

Linked Multi-Prim Drawers (2 scripts) ( V4 )

NOW RECORDS ROTATIONS AS WELL.

Could also be used for doors etc.

Instructions (Copy to NC or Script)

<lsl>// V4 //

// INSTRUCTIONS FOR USE (there are two scripts that make up the set)

// Make your chest of drawers and link the whole set together with the body (any prim that doesn't move) of the chest as the root.

// Name every prim used as a part of a drawer (include handles, drawer fronts, bases etc.) "drawer " plus a number.

// All the prims of one drawer should now all be named the same. e.g. "drawer 1".

// Name every drawer a different number. e.g. "drawer 1", "drawer 2" etc.

// With all the parts named correctly, edit the object so that all the drawers are closed.

// At this point you might want to take a copy.

// Be sure that no prims are named "drawer (something)" unless they are supposed to be (according to the above).

// Drop both the scripts (at the same time or "Linkypooz" first) into the root of the object.

// You will get further instructions in local chat. Follow them.</lsl>

Drawer Script

<lsl>// V4 //

// This script needs to be named "Linkypooz".

vector open_pos;

vector closed_pos;

rotation open_rot;

rotation closed_rot;

integer OPEN;

key owner;

integer my_response_num;

integer my_link_num;

Drawer() {

   if(OPEN)
   llSetPrimitiveParams([PRIM_POSITION, closed_pos, PRIM_ROTATION, (closed_rot / llGetRootRotation())]);
   else
   llSetPrimitiveParams([PRIM_POSITION, open_pos, PRIM_ROTATION, (open_rot / llGetRootRotation())]);
   OPEN = (!OPEN);

}

default {

   state_entry()
   {
       owner = llGetOwner();
       closed_pos = llGetLocalPos();
       closed_rot = llGetLocalRot();
       my_link_num = llGetLinkNumber();
       my_response_num = ((integer)llGetSubString(llGetLinkName(my_link_num), 7, -1));
   }
   touch_start(integer nd)
   {
       if(llDetectedKey(0) == owner)
       {
           if(my_link_num != 1)
           {
               open_pos = llGetLocalPos();
               open_rot = llGetLocalRot();
               llSetLocalRot(closed_rot);
               llSetPos(closed_pos);
               state normal;
           }
           else
           llRemoveInventory(llGetScriptName());
       }
   }

} state normal {

   state_entry()
   {
       llOwnerSay("/me is active!");
   }
   touch_start(integer nd)
   {
       llMessageLinked(LINK_SET, my_response_num, "", "");
   }
   link_message(integer sender, integer num, string str, key id)
   {
       if(num == my_response_num)
       Drawer();
   }

}</lsl>

Script Delivery Script

<lsl>// V4 //

default {

   state_entry()
   {
       integer count;
       integer links = llGetNumberOfPrims();
       do
       {
           string name = llGetLinkName(count);
           if(llGetSubString(name, 0, 5) == "drawer")
           {
               key link_key = llGetLinkKey(count);
               llGiveInventory(link_key, "Linkypooz"); // This is why the other script needs to be called "Linkypooz"
           }                                           // You can change it if you like.
       }
       while((++count) < (links + 1));
       llOwnerSay("\n\nNow take the object to inventory and re-rez.
       \n\nOpen an edit on the object.
       \n\nGo to the tools menu and, at the bottom of the menu click \"Set Scripts Running in Selection\".
       \n\nEdit all the prims of the drawers from the closed position/rotation to the open position/rotation.
       \n\nWhen all the prims of the drawers are set open (you can do one prim at a time or all together, which ever you prefer), touch each prim.
       \n\nWhen the prim is touched it will automatically close.
       \n\nWhen all the prims of all the drawers are in the closed position/rotation the scripts are fully set up.
       \n\nThey will chat that they are active when ready.
       \n\nNow touch the root and the script in it will self delete.
       \n\nThat's all!!");
       llRemoveInventory(llGetScriptName());
   }

}</lsl>

Auto Set Group Joiner ( V1 )

<lsl>// V1 //

key group_key;

Function() {

   group_key = llList2Key(llGetObjectDetails(llGetKey(), [OBJECT_GROUP]), 0);
   if(group_key != NULL_KEY)
   llHTTPRequest("http://world.secondlife.com/group/" + ((string)group_key), [], "");
   else
   {
       llSay(0, "Since you are not wearing a group tag I am not set to any group.
       \nWear a group tag and try again.
       \nThis script will self delete.");
       llRemoveInventory(llGetScriptName());
   }

}

default {

   state_entry()
   {
       Function();
   }
   on_rez(integer param)
   {
       Function();
   }
   http_response(key q, integer status, list metadata, string body)
   {
       if(status == 200)
       {
           integer name_start = (llSubStringIndex(body, "<title>") + 7);
           integer name_end = (llSubStringIndex(body, "</title>") - 1);
           integer tex_key_start = (llSubStringIndex(body, "imageid") + 18);
           integer tex_key_end = (tex_key_start + 35);
           string group_name = llGetSubString(body, name_start, name_end);
           llSetObjectName("Join " + group_name);
           key group_tex = llGetSubString(body, tex_key_start, tex_key_end);
           if(group_tex != NULL_KEY)
           llSetTexture(group_tex, ALL_SIDES);
           else
           llSetTexture(TEXTURE_BLANK, ALL_SIDES);
       }
       else
       {
           llHTTPRequest("http://world.secondlife.com/group/" + ((string)group_key), [], "");
       }
   }
   touch_start(integer nd)
   {
       llSay(0, "/me by clicking this link\nsecondlife:///app/group/" + ((string)group_key) + "/about");
   }

}</lsl>

Percentage Paying (optional) Tip Jar ( V1 )

Pays the percentage (if chosen) to the founder of the group you set the object to.

UNDER CERTAIN CONDITIONS (That you set and agree to) THIS SCRIPT WILL TAKE MONEY FROM YOUR ACCOUNT

<lsl>// V1 //

key owner;

integer debit_perms = FALSE;

integer pay_price = 0;

list pay_buttons = [20, 50, 100, 250];

integer percentage = 50; // Percentage to pay to the founder of the group the object is set to.

key beneficiary;

string default_message = "/me is very grateful for the generous contribution from ";

string beneficiary_message = "% of which has been paid to the founder of ";

key group_key;

string group_name;

Function() {

   owner = llGetOwner();
   string owner_name = llKey2Name(owner);
   string object_name = (owner_name + "'s Money Box");
   llSetObjectName(object_name);
   llSetPayPrice(pay_price, pay_buttons);
   if(percentage)
   llRequestPermissions(owner, PERMISSION_DEBIT);

}

default {

   on_rez(integer param)
   {
       Function();
   }
   state_entry()
   {
       Function();
   }
   run_time_permissions(integer perms)
   {
       if(perms & PERMISSION_DEBIT)
       {
           debit_perms = TRUE;
           group_key = llList2Key(llGetObjectDetails(llGetKey(), [OBJECT_GROUP]), 0);
           if(group_key != NULL_KEY)
           llHTTPRequest("http://world.secondlife.com/group/" + ((string)group_key), [], "");
       }
       else
       llRequestPermissions(owner, PERMISSION_DEBIT);
   }
   http_response(key q, integer status, list metadata, string body)
   {
       if(status == 200)
       {
           integer name_start = (llSubStringIndex(body, "<title>") + 7);
           integer name_end = (llSubStringIndex(body, "</title>") - 1);
           integer founder_key_start = (llSubStringIndex(body, "founderid") + 20);
           integer founder_key_end = (founder_key_start + 35);
           beneficiary = llGetSubString(body, founder_key_start, founder_key_end);
           group_name = llGetSubString(body, name_start, name_end);
       }
       else
       {
           llHTTPRequest("http://world.secondlife.com/group/" + ((string)group_key), [], "");
       }
   }
   money(key id, integer amount)
   {
       string message = "";
       integer dividend;
       string payer = llKey2Name(id);
       if(!percentage)
       {
           message = (default_message + payer);
       }
       else
       {
           dividend = llFloor((((float)amount)/100.0) * ((float)percentage)); // I'm very tired and my eyes are sticky!
           if(dividend)
           {
               if(debit_perms)
               {
                   message = (default_message + payer + ".\n" + ((string)percentage) + beneficiary_message + group_name);
                   llGiveMoney(beneficiary, dividend);
               }
               else
               {
                   message = (default_message + payer);
               }
           }
       }
       llSay(PUBLIC_CHANNEL, message);
   }

}</lsl>

Floating Text LEFT/RIGHT Alignment ( V1 )

This script can turn a list of individual lines of text into a left or right aligned floating text display

<lsl>// V1 //

// SetTextAlign // Begin //

// Thank you to Silicon Plunkett for the "samples" the script uses to measure the width of the strings. // He made a great effort to work these values out and I would have been at a massive disadvantage without them. // This may never have existed.

string SetTextAlign(integer A, integer D, list S) {

   list samples = [" ", "![]{}|:;'.,ijlIJ", "\/<>`()rtf", "*#\"yszxcvETYLZ", "_?upahkbnRPAFKCV", "~$^+qeodgmDB", "w=QUOSGHXN", "%WM", "@"];
   list result = [];
   string separate = "";
   if(A)
   {
       list scores = [];
       list scores_max = [];
       string line = "";
       string sample = "";
       string letter = "";
       string spaces = "";
       string to_pad = "";
       float score = 0.0;
       float max_score = 0.0;
       float next = 0.0;
       integer length = 0;
       integer s_length = 0;
       integer count = 0;
       integer count_a = 0;
       integer count_b = 0;
       integer count_c = 0;
       integer ssi = 0;
       integer padem = 0;
       integer space_count = 0;
       separate = "\n";
       length = llGetListLength(S);
       do
       {
           line = llList2String(S, count);
           s_length = llStringLength(line);
           count_a = 0;
           score = 0.0;
           do
           {
               letter = llGetSubString(line, count_a, count_a);
               count_b = 0;
               do
               {
                   count_c = 0;
                   do
                   {
                       sample = llList2String(samples, count_c);
                       ssi = llSubStringIndex(sample, letter);
                       if(ssi != -1)
                       {
                           if(count_c == 0)
                           score += 1.0;
                           else if(count_c == 1)
                           score += 1.5;
                           else if(count_c == 2)
                           score += 2.0;
                           else if(count_c == 3)
                           score += 2.5;
                           else if(count_c == 4)   // Thanx to some advice from a veritable genius ( Xzaviar Qarnac ) -
                           score += 3.0;           // - I have realised something very important about loops.
                           else if(count_c == 5)   // Since this realization I have cut out alot of potential drag.
                           score += 3.5;           // Thank you Xzaviar.
                           else if(count_c == 6)
                           score += 4.0;
                           else if(count_c == 7)
                           score += 4.5;
                           else
                           score += 5.0;
                           count_c = 9;    // This line is what I realized was needed.
                       }
                   }
                   while((++count_c) < 9);
               }
               while((++count_b) < 1);
           }
           while((++count_a) < s_length);
           scores += [score];
       }
       while((++count) < length);
       scores_max = llListSort(scores, 1, FALSE);
       max_score = llList2Float(scores_max, padem);
       scores_max = [];
       do
       {
           next = llList2Float(scores, padem);
           spaces = "";
           space_count = 0;
           do
           {
               spaces += " ";
           }
           while((((float)(++space_count)) + next) < max_score);
           to_pad = llList2String(S, padem);
           if(D)
           result += [(to_pad + spaces)];
           else
           result += [(spaces + to_pad)];
       }
       while((++padem) < length);
       scores = [];
   }
   else
   result = S;
   return llDumpList2String(result, separate);

}

// SetTetAlign // End //

default {

   state_entry()
   {
       float alpha = 1.0;
       vector color = <0.0,1.0,1.0>; // Turquoise!

// The text to display must be fed to the function as a list of strings each being one line (as below).

       list source = ["Hello there, Avatar!", "My script can align your text to the left or right.", "Touch me for a copy of it."];

       llSetText(SetTextAlign(TRUE, TRUE, source), color, alpha);

// SetTextAlign(Align (TRUE or FALSE), Direction (TRUE = left : FALSE = right), source).

   }
   touch_start(integer nd)
   {
       integer countnd = 0;
       do
       {
           key toucher = llDetectedKey(countnd);
           llGiveInventory(toucher, llGetScriptName()); // FREE!!! Enjoy.
       }
       while((++countnd) < nd);
   }

}</lsl>

Grid Status Updater ( V10 )

Checks the Second Life Grid Status every ten minutes to see if there are any new issues. If there are it will IM you.

Drop this script onto any prim that is currently not expected to do something else (e.g. a wall or floor etc) and let it run. If it is in an attachment it will work fine but, only while you are logged in. The script will maintain the name of the prim (or object if in a root) but when sending an update will use a special name set by you. This is simply more aesthetically pleasing. Getting an update from "Ceiling Fan" can seem a little odd.

<lsl>// V10 //

string feed_url = "http://status.secondlifegrid.net/feed/";

string alert_name = "Grid Status Update"; // The name for the prim when it sends an update.

string my_proper_name; // Used to store the "normal" name of the prim.

key owner;

string last;

key iq;

default {

   state_entry()
   {
       my_proper_name = llGetObjectName();
       owner = llGetOwner();
       llSetTimerEvent(600.0);
       iq = llHTTPRequest(feed_url, [], "");
   }
   timer()
   {
       iq = llHTTPRequest(feed_url, [], "");
   }
   http_response(key q, integer status, list meta, string body)
   {
       if(q == iq)
       {
           if(status == 200)
           {
               integer index;
               body = llGetSubString(body, (llSubStringIndex(body, "<item>") + 6), -1);
               string latest = llStringTrim(llGetSubString(body, (llSubStringIndex(body, "<description><![CDATA[") + 22),
                               (llSubStringIndex(body, "]]></description>") - 1)), STRING_TRIM);
               if(latest != last)
               {
                   last = latest;
                   while(index != -1)
                   {
                       index = llSubStringIndex(latest, "’");
                       if(index != -1)
                       latest = llInsertString(llDeleteSubString(latest, index, (index + 6)), index, "'");
                   }
                   index = 0;
                   while(index != -1)
                   {
                       index = llSubStringIndex(latest, ">");
                       if(index != -1)
                       latest = llInsertString(llDeleteSubString(latest, index, (index + 4)), index, ">");
                   }
                   index = 0;
                   while(index != -1)
                   {
                       index = llSubStringIndex(latest, "&");
                       if(index != -1)
                       latest = llInsertString(llDeleteSubString(latest, index, (index + 4)), index, "&");
                   }
                   index = llSubStringIndex(latest, "[...]");
                   if(index != -1)
                   latest = llInsertString(llDeleteSubString(latest, index, (index + 4)), index, "...");
                   string issue = llGetSubString(body, (llSubStringIndex(body, "<title>") + 7), (llSubStringIndex(body, "</title>") - 1));
                   string dnt = llGetSubString(body, (llSubStringIndex(body, "<pubDate>") + 9), (llSubStringIndex(body, "</pubDate>") - 10));
                   string date = (llGetSubString(dnt, 0, -7) + " (UTC)");
                   string time = llGetSubString(dnt, -5, -1);
                   llSetObjectName(alert_name);
                   llInstantMessage(owner, "/me \n\nISSUE --> " + issue + 
                                           "\n\nTIME --> " + time + ", " + date +
                                           "\n\nLATEST --> " + latest +
                                           "\n\nVISIT --> " + llGetSubString(feed_url, 0, -6));
                   llSetObjectName(my_proper_name);
               }
           }
           else
           {
               llSleep(60.0);
               iq = llHTTPRequest(feed_url, [], "");
           }
       }
   }

}</lsl>

Touch Texture Setter ( V2 )

Fill out the UUID for the texture to set. Drop the script in the prim to texture. The texture then sets on each face touched. A long held touch will delete the script.

<lsl>// V2 //

key texture_uuid = "f05755e7-d31c-116d-9cf2-a4840bdfc56b";

integer tc;

key owner;

default {

   state_entry()
   {
       owner = llGetOwner();
   }
   touch_end(integer nd)
   {
       while(nd)
       {
           if(llDetectedKey(--nd) == owner)
           {
               tc = 0;
               llSetTexture(texture_uuid, llDetectedTouchFace(nd));
           }
       }
   }
   touch(integer nd)
   {
       while(nd)
       {
           if(llDetectedKey(--nd) == owner)
           {
               if((++tc) == 20)
               llRemoveInventory(llGetScriptName());
           }
       }
   }

}</lsl>

Enzeroizer (Rotation Fixer) ( V2 )

Drop this into the root of your linked object and it will self seed to all links in a set (object). After re-rezzing the object and setting the scripts running it will set the rotations to whatever they were but with the smallest 3 decimal places made 000. e.g. <75.458392, 128,038754, 298.836580> will become <75.458000, 128,038000, 298.836000>. This will make minor rotational drifts that occur due to one of our favorite bugs less of an issue. I have done light testing and think it's fine. Make a copy of you object before using this script just in case it goes wrong. I will post an updated version using llGetLinkPrimitiveParams when server 1.38 is rolled out and actually working.

<lsl>// V2 //

SelfSeed() // The function name. {

   string name = llGetScriptName(); // Store the name of this script to save calling for it over and over.
   integer links_in_set = llGetObjectPrimCount(llGetKey()); // Store how many links there are.
   integer count = 2; // Establish a counter that will start at the next link in the set.
   do // This is the point from which we loop if the while condition is met.
   llGiveInventory(llGetLinkKey(count), name); // Deliver a copy of this script to the link number "count".
   while((++count) <= links_in_set); // Increment "count" and check if it is still less than or equal to the number of links.

} // If "count" is not more than the number of links loop back to "do".

Enzeroize() // The function name. {

   vector rot = (llRot2Euler(llGetLocalRot())*RAD_TO_DEG); // Store the local rotation of the prim as a vector.
   // Below : Take each of the axes (X, Y & Z) and typecast to a string. Chop the last 3 characters off the string and add 3 zeros.
   // Then typecast the result to a float and use each as the appropriate float in a vector which is then converted to a rotation and set.
   llSetLocalRot(llEuler2Rot(<((float)(llDeleteSubString(((string)rot.x), -3, -1) + "000")),
                              ((float)(llDeleteSubString(((string)rot.y), -3, -1) + "000")),
                              ((float)(llDeleteSubString(((string)rot.z), -3, -1) + "000"))>*DEG_TO_RAD));

}

default // Create a state. {

   state_entry() // On entering the state...
   {
       if(llGetLinkNumber() == 1) // ...Check if we are the root.
       {
           SelfSeed(); // Call the "SelfSeed()" function.
           Enzeroize(); // Call the "Enzeroize()" function.
           // Below : Issue instruction in chat to the owner of the object.
           llOwnerSay("\nTake me to your inventory and re-rez me." +
                      "\nThen open an edit on me and goto your \"Tools\" menu." +
                      "\nNear the bottom of the menu click \"Set Scripts Running In Selection\"." +
                      "\nAll the scripts will self delete after Enzeroizing.");
       }
       else // If not in the root...
       Enzeroize(); // ...Call the "Enzeroize()" function.
       llRemoveInventory(llGetScriptName()); // Whether in the root or not, this script removes itself from the prim.
   }

}</lsl>

More Scripts...

Free Scripts (content constantly updating)

More Free Scripts (this page)

Even More Free Scripts (content constantly updating)

Even More More Free Scripts (content constantly updating)

Even More More More Free Scripts (content constantly updating)

If you have any comments about the content of this page please post them HERE