Difference between revisions of "User:Fred Gandt/Scripts/Continued 1"

From Second Life Wiki
Jump to navigation Jump to search
m (→‎More Pages: added link)
Line 12: Line 12:


'''[[User:Fred_Gandt/Scripts/Continued_2| Even More Free Scripts]]'''
'''[[User:Fred_Gandt/Scripts/Continued_2| Even More Free Scripts]]'''
'''[[User:Fred_Gandt/Scripts/Continued_3| Even More More Free Scripts]]'''


=== Legal Stuff ===
=== Legal Stuff ===

Revision as of 22:00, 5 March 2010

FG jpg.jpg

My Contributions

More Pages

Free Scripts

Even More Free Scripts

Even More More Free Scripts

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

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>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)

Could also be used for doors etc.

Instructions (Copy to NC or Script)

<lsl>// 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) into the root of the object.

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

Drawer Script

<lsl>// This script needs to be named "Linkypooz".

vector open;

vector closed;

integer OPEN;

key owner;

integer my_response_num;

integer my_link_num;

Drawer() {

   vector pos;
   if(OPEN)
   pos = closed;
   else
   pos = open;
   llSetPos(pos);
   OPEN = (!OPEN);

}

default {

   state_entry()
   {
       owner = llGetOwner();
       closed = llGetLocalPos();
   }
   touch_start(integer nd)
   {
       if(llDetectedKey(0) == owner)
       {
           open = llGetLocalPos();
           llSetPos(closed);
           state normal;
       }
   }

} state normal {

   state_entry()
   {
       my_link_num = llGetLinkNumber();
       my_response_num = ((integer)llGetSubString(llGetLinkName(my_link_num), 7, -1));
       llOwnerSay(" is active!");
   }
   touch_start(integer nd)
   {
       if(my_link_num == 1)
       {
           llRemoveInventory(llGetScriptName());
       }
       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>// This script can be called "cats ass" for all I care! lolz.

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");
           }
       }
       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 to the open position.
       \n\nWhen all the prims of the drawers are set open, touch each prim(you can do one prim at a time or all together, which ever you prefer).
       \n\nWhen the prim is touched it will automatically close.
       \n\nWhen all the prims of all the drawers are in the closed position the scripts are fully set up.
       \n\nThey will chat that they are active when ready.
       \n\nNow touch the root (or any other non drawer prim) and the script in it will self delete.
       \n\nThat's all!!");
       llRemoveInventory(llGetScriptName());
   }

}</lsl>

Auto Set Group Joiner

<lsl>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

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>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

THIS IS A FIRST DRAFT AND IS A LITTLE MORE INTENSIVE THAN I HOPE TO MAKE IT

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

<lsl>// SetTextAlign // Begin //

// Thank you to Silicon Plunkett for the following list of "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.

list samples = [" ", "![]{}|:;'.,ijlIJ", "\/<>`()rtf", "*#\"yszxcvETYLZ", "_?upahkbnRPAFKCV", "~$^+qeodgmDB", "w=QUOSGHXN", "%WM", "@"];

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

   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.
                       }
                       else
                       {
                           ; // Not sure yet. I'll think of something! lolz
                       }
                   }
                   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).

// I will be adding a couple of extra features to this very soon.

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

}</lsl>

Single Prim Double Doors

Bit jumpy because of the script delay caused by llSetPrimitiveParams

Just drop the scripts into a fresh prim and it will become the doors.

Both can be made to allow only owner use by writing the word "owner" in the prim description before resetting the script.

Sliding Doors

<lsl>integer open;

key owner;

string owner_lock = "";

OperateDoors() {

   if(!open)
   {
       float f = 0.0;
       do
       {
           f += 0.2;
           llSetPrimitiveParams([9, 0, 0, <0.375,0.875,0.0>, 0.95, ZERO_VECTOR, <f,1.0,0.0>, ZERO_VECTOR]);
       }
       while(f < 1.0);
   }
   else
   {
       float f = 1.0;
       do
       {
           f -= 0.2;
           llSetPrimitiveParams([9, 0, 0, <0.375,0.875,0.0>, 0.95, ZERO_VECTOR, <f,1.0,0.0>, ZERO_VECTOR]);
       }
       while(f > 0.0);
   }
   llSetTimerEvent(6.0);
   open = (!open);

}

default {

   state_entry()
   {
       owner = llGetOwner();
       owner_lock = llToLower(llGetObjectDesc());
       vector pos = llGetPos();
       llSetPrimitiveParams([9, 0, 0, <0.375,0.875,0.0>, 0.95, ZERO_VECTOR, <0.0,1.0,0.0>, ZERO_VECTOR,
                             17, -1, TEXTURE_BLANK, <1.0,1.0,0.0>, ZERO_VECTOR, 0.0,
                             6, <pos.x,pos.y,(pos.z - 0.25)>,
                             18, -1, ZERO_VECTOR, 0.4,
                             8, <PI,0.0,0.0,PI>,
                             7, <3.0,5.0,0.01>]);
   }
   touch_start(integer nd)
   {
       if(owner_lock == "owner")
       {
           if(llDetectedKey(0) != owner)
           return;
       }
       OperateDoors();
   }
   timer()
   {
       llSetTimerEvent(0.0);
       if(open)
       OperateDoors();
   }

}</lsl>

Swinging Doors

This is more of a curiosity than of any use. I only made it for fun.

It will screw up if you move the doors or change the size and then operate it without first editing and resetting the script.

I might rework it one day. Honestly though you would get a better result with two prims.

<lsl>integer open;

key owner;

string owner_lock = "";

float width;

float swing;

float shift;

float shifty;

float swinger;

vector pos;

vector scale;

OperateDoors() {

   if(!open)
   {
       float f = 0.0;
       do
       {
           f += 0.05;
           swing += swinger;
           shift -= shifty;
           llSetPrimitiveParams([9, 0, 0, <0.375,0.875,0.0>, 0.95, ZERO_VECTOR, <f,1.0,0.0>, ZERO_VECTOR,
                                 7, <scale.x,scale.y,swing>,
                                 //6, <(pos.x + shift),pos.y,pos.z>]); // If Opening toward the West
                                 //6, <(pos.x - shift),pos.y,pos.z>]); // If Opening toward the East
                                 6, <pos.x,(pos.y + shift),pos.z>]); // If Opening toward the South. This is the defualt.
                                 //6, <pos.x,(pos.y - shift),pos.z>]); // If Opening toward the North.
       }
       while(f < 1.0);
   }
   else // If you want the doors to open in a different direction than the default you need to un-comment the direction you want and...
   {    // ...comment out the other directions (both above and below). Remember to rotate the prim.
       float f = 1.0;
       do
       {
           f -= 0.05;
           swing -= swinger;
           shift += shifty;
           llSetPrimitiveParams([9, 0, 0, <0.375,0.875,0.0>, 0.95, ZERO_VECTOR, <f,1.0,0.0>, ZERO_VECTOR,
                                 7, <scale.x,scale.y,swing>,
                                 //6, <(pos.x + shift),pos.y,pos.z>]); // If Opening toward the West
                                 //6, <(pos.x - shift),pos.y,pos.z>]); // If Opening toward the East
                                 6, <pos.x,(pos.y + shift),pos.z>]); // If Opening toward the South. This is the defualt.
                                 //6, <pos.x,(pos.y - shift),pos.z>]); // If Opening toward the North.
       }
       while(f > 0.0);
   }
   llSetTimerEvent(6.0);
   open = (!open);

}

default {

   state_entry()
   {
       owner = llGetOwner();
       owner_lock = llToLower(llGetObjectDesc());
       
       // The section below builds the prim and sets the correct rotation etc. Once the door is created you can comment this section out.
       // You need to comment it out if you have changed the size of the doors, moved the doors or changed the rotation of the doors.
       // Otherwise as soon as you save the changes to the direction or operate the doors it will reset its self to its default.
       
       pos = llGetPos();                                                                                // Comment out once built.
       llSetPrimitiveParams([9, 0, 0, <0.375,0.875,0.0>, 0.95, ZERO_VECTOR, <0.0,1.0,0.0>, ZERO_VECTOR, // Comment out once built.
                             17, -1, TEXTURE_BLANK, <1.0,1.0,0.0>, ZERO_VECTOR, 0.0,                    // Comment out once built.
                             6, <pos.x,pos.y,(pos.z + 2.5)>,                                            // Comment out once built.
                             18, -1, ZERO_VECTOR, 0.4,                                                  // Comment out once built.
                             8, llEuler2Rot(<90.0,0.0,180.0>*DEG_TO_RAD),                               // Comment out once built.
                             7, <6.0,6.0,0.01>]);                                                       // Comment out once built.
       
       // Only comment out the section between this commented out text.
       
       pos = llGetPos();
       scale = llGetScale();
       width = ((scale.x)/2);
       shifty = ((width/2)/20);
       swinger = (width/20);
       swing = 0.0;
   }
   touch_start(integer nd)
   {
       if(owner_lock == "owner")
       {
           if(llDetectedKey(0) != owner)
           return;
       }
       OperateDoors();
   }
   timer()
   {
       llSetTimerEvent(0.0);
       if(open)
       OperateDoors();
   }

}</lsl>

More Scripts...

Free Scripts

Even More Free Scripts