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

From Second Life Wiki
Jump to navigation Jump to search
(Big time sensualitee-hee!! Added floating text alignment script. Needs work...)
Line 756: Line 756:


// Thank you to Silicon Plunkett for the following list of samples the script uses to measure the width of the strings.
// 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 with them.
// This may never have existed.


list samples = [" ", "![]{}|:;'.,ijlIJ", "\/<>`()rtf", "*#\"yszxcvETYLZ", "_?upahkbnRPAFKCV", "~$^+qeodgmDB", "w=QUOSGHXN", "%WM", "@"];
list samples = [" ", "![]{}|:;'.,ijlIJ", "\/<>`()rtf", "*#\"yszxcvETYLZ", "_?upahkbnRPAFKCV", "~$^+qeodgmDB", "w=QUOSGHXN", "%WM", "@"];
Line 767: Line 769:
     integer count = 0;
     integer count = 0;
     integer length;
     integer length;
     string line;
     string line;           // I'll be tidying this up very soon.
     integer s_length;
     integer s_length;
     integer count_a = 0;
     integer count_a = 0;
Line 806: Line 808:
                             if(count_c == 3)
                             if(count_c == 3)
                             score += 2.5;
                             score += 2.5;
                             if(count_c == 4)
                             if(count_c == 4) // Thanx to some advice from a veritable genius ( Xzaviar Qarnac ) -
                             score += 3.0;
                             score += 3.0;   // - I will be looking into adding some jumps here.
                             if(count_c == 5)
                             if(count_c == 5)
                             score += 3.5;
                             score += 3.5;
Line 834: Line 836:
             string spaces = "";
             string spaces = "";
             do
             do
             {
             {                                                         // more tidying.
                 spaces += " ";
                 spaces += " ";
             }
             }
Line 855: Line 857:
default
default
{
{
     state_entry() // The text to display must be fed to the function as a list of strings each being one line (as below).
     state_entry()
     {
     {
         float alpha = 1.0;
         float alpha = 1.0;
         vector color = <1.0,1.0,1.0>;
         vector color = <1.0,1.0,1.0>;
// The text to display must be fed to the function as a list of strings each being one line (as below).
// I may add the string to list function at some point ( cut out the "\n"'s )
         list source = ["Hello there avatar!", "My script can align your text to the left or right.", "Touch me for a copy of it."];
         list source = ["Hello there avatar!", "My script can align your text to the left or right.", "Touch me for a copy of it."];
         llSetText(SetTetAlign(TRUE, TRUE, source), color, alpha);
         llSetText(SetTetAlign(TRUE, TRUE, source), color, alpha);
    } // SetTextAlign(integer align (true/false), integer direction (true = left : false = right), list source)
 
// SetTextAlign(Align (TRUE or FALSE), Direction (TRUE = left : FALSE = right), source)
 
    }
}</lsl>
}</lsl>

Revision as of 02:26, 3 February 2010

My contributions

The legal stuff about contributing stuff here and about (worth reading).

I have simply posted some scripts I have written for FREE use. They are not meant to be the most amazing or groundbreaking scripts in all of creation but, you may find something in them useful. They are not perfect (at least I doubt it) but I have posted them here for FREE use anyway. If you want to use them go ahead. If you copy any of these scripts and compile them in-world and then restrict the perms and sell them (as scripts), be aware that I think you are scum. You are welcome to use them in products and welcome to rework them and call the results your own (and thus set the perms how you like) but, to sell these as they are when they are freely available would be disgusting.

I will be constantly updating this page, adding new scripts and tweaking the scripts already posted. Come back in a week and the scripts that are here this time may have been improved. If any give you any problems please IM me and I'll see what I can do for you. I do not want your money and I request that your respect my humanity (I may be tired, in a bad mood or even busy working on something else so, don't expect professional politeness; expect honesty).

Tuition

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

I teach in-world at The Builders Brewery. I help out in a few groups and by IM. I will be developing a course of work that will be posted here to accompany my tuition and to act as a stand-alone guide to anyone wanting to grasp the basics of scripting in LSL.

The most important first lesson is this - Don't be afraid to try. It might look like sci-fi gibberish but, in truth it is no more complex than a foreign language written in American-English. IT DOESN'T BITE!

Basic Light Switch

<lsl>// This script will cause the prim it is in to emit light. // If the prim (or object if the script is in the root of a link_set) // is touched the light will turn off if on and on if off. // The switching code can be used for many different actions.

integer on; // Global variable used to measure the condition 'on or off'.

vector color = <1.0,1.0,1.0>; // R,G,B (red, green, blue) values.

float intensity = 1.0; // 0.0 to 1.0 (1.0 = full brightness)

float radius = 20.0; // 0.1 to 20.0 (20.0 = full sphere)

float falloff = 0.01; // 0.01 to 2.0 (2.0 = least spread)

Switch() // The switching function. I made the switch function to facilitate easier editing. {

   on = (!on); // Flip the boolean value of the integer 'on'.
   llSetPrimitiveParams([PRIM_POINT_LIGHT, on, color, intensity, radius, falloff]);

}

default {

   touch_end(integer nd)
   {
       Switch(); // Unconditionally call the switch to operate.
   }

}</lsl>

Script that gives a set amount of L$ to whoever touches the object this script is in

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>

Script to make the Mouselook button show at the bottom of your screen

<lsl>key owner;

default {

   state_entry()
   {
       owner = llGetOwner();
       llRequestPermissions(owner, PERMISSION_TAKE_CONTROLS);
   }
   run_time_permissions(integer perm)
   {
       if(perm & PERMISSION_TAKE_CONTROLS) // Do we have the perms we asked for?
       llTakeControls(CONTROL_ML_LBUTTON, TRUE, FALSE); // This creates a button at the bottom of the screen
       else                    // that if pressed automatically zooms the camera of the owner into mouselook.
       llRequestPermissions(owner, PERMISSION_TAKE_CONTROLS);
   }
   control(key id, integer this, integer that)
   {                        // Adding various conditions here can change the script behavior in many ways.
       llOwnerSay("Click"); // Do stuff when clicking the left mouse button while in mouselook. Like for guns etc.
   }

}</lsl>

Script that makes the object it is in float on water (like a marker buoy)

<lsl>float offset = 0.0; // Use this float to offset the height of the object in relation to the water surface. // The object will (when the offset is zero) float with its geometric center at the level of the water surface. default // The offset is a measure of meters and/or parts thereof. {

   state_entry() // Best to set the object in place with your edit tools and then add the script.
   {             // As the code runs it will lock the objects position and attempt to remain there.
       float float_height = (llWater(ZERO_VECTOR) + offset); 
       vector pos = llGetPos();
       llSetStatus(STATUS_PHYSICS, TRUE); // Make the object physical.
       llMoveToTarget(<pos.x, pos.y, float_height>, 0.5); // Have it maintain it's position.
       // Things get more complex if you wanna make a boat. But this is a place to start.
   }

}</lsl>

Very Basic Alpha (transparency) ON/OFF script

<lsl>integer on;

key owner; // Store the owners UUID (key)

string command = "switch"; // Place the command to chat here. The same command will switch on and off.

integer channel = 1; // Place channel to use here (must be a positive if an avatar is chatting on it).

Switch(integer i) {

   llSetLinkAlpha(LINK_SET, ((float)i), ALL_SIDES); // This setting will turn a whole link_set transparent or solid.

}

default {

   state_entry()
   {
       owner = llGetOwner();
       llListen(channel, "", owner, command); // This script is listening all the time.
   }   // Switching the listen off at times would be better to reduce lag. But when??
   touch_end(integer nd)
   {
       on = (!on);
       Switch(on); // Blah
   }
   listen(integer chan, string name, key id, string msg)
   {
       on = (!on);
       Switch(on); // Blah
   }

}</lsl>

Scripts for multi prim drawers (2 scripts)

Could also be used for doors etc.

<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><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><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\nSet all the prims so that all the drawers are closed.
       \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>

Group Joiner that sets it's self to whatever group you are wearing as it is rezzed or created

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

Tip Jar with ability to pay a percentage to the founder of the group the object is set to

Might be a bit buggy because I wrote it while 1/2 asleep. I'll check later.

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>

Region Stats as floating text

<lsl>string bar = "||";

string RFPS = "Region Frames per Second ";

string RTD = "Region Time Dilation ";

string GetCondition(integer d, integer f) {

   string s = "";
   if(d >= 15 && f >= 15)
   s = "GOOD";
   else if(d >= 10 && f >= 10)
   s = "POOR";
   else if(d >= 5 && f >= 5)
   s = "DIABOLICAL";
   else
   s = "CRASHED?";
   return s;

}

default {

   on_rez(integer param)
   {
       llResetScript();
   }
   state_entry()
   {
       llSetTimerEvent(5.0);
   }
   timer()
   {
       integer count = 0;
       vector color;
       string d = "";
       string f = "";
       string text = "";
       float dilation = (llGetRegionTimeDilation() * 10);
       float FPS = llGetRegionFPS();
       integer mathed_fps = (llRound(FPS*2)/10);
       integer mathed_dilation = llRound(dilation);
       do
       d += bar;
       while((++count) < mathed_dilation);
       count = 0;
       do
       f += bar;
       while((++count) < mathed_fps);
       color = <1.0, (dilation/10), 0.0>;
       text = ("All is  -  " + GetCondition((mathed_dilation * 2), (mathed_fps * 2)) + "\n" + RFPS + f + "\n" + RTD + d);
       llSetText(text, color, 1.0);
   }

}</lsl>

Configurable Unpacker

Honestly I haven't tested this at all. IM Fred Gandt if it gives you problems.

<lsl>key owner;

string me;

integer open = FALSE;

list folder_contents = [];

string folder_name; // The folder name will establish from the description of the object this script is in.

// CHANGE ONLY THE SETTINGS BELOW //

integer give_this_script = TRUE; // Give this FREE script away with the other contents? Think about it....

integer allow_only_owner = FALSE; // Owner only or open to all?

integer self_delete = FALSE; // Self delete?

integer timed_deletion = FALSE; // Delete immediately after giving contents or hang around a bit?

float deletion_delay = 10.0; // Length of time to hang around in seconds (if timed_deletion is set TRUE)

string display_rez_text = ""; // Floating text on rez?

string localchat_rez_text = ""; // Chatted message on rez?

string ownerchat_rez_text = ""; // Chatted message only to owner on rez?

string display_deletion_text = ""; // Floating text before deletion?

string localchat_deletion_text = ""; // Chatted message before deletion?

string ownerchat_deletion_text = ""; // Chatted message only to owner before deletion?

vector rez_text_color = <1.0,1.0,1.0>; // Color of floating text if set to show on rez.

vector deletion_text_color = <1.0,1.0,1.0>; // Color of floating text if set to show before deletion.

float rez_text_alpha = 1.0; // Transparency of floating text if set to show on rez.

float deletion_text_alpha = 1.0; // Transparency of floating text if set to show before deletion.

// CHANGE ONLY THE SETTINGS ABOVE //

OnRezTextOptionsFunctionThingy(integer o) {

   if(display_rez_text != "")
   llSetText(display_rez_text, rez_text_color, rez_text_alpha);
   if(localchat_rez_text != "")
   llSay(0, localchat_rez_text);
   if(ownerchat_rez_text != "")
   llOwnerSay(ownerchat_rez_text);
   if(!o)
   {
       integer count = 0;
       integer NOI = llGetInventoryNumber(INVENTORY_ALL);
       if(NOI)
       {
           do
           {
               string name = llGetInventoryName(INVENTORY_ALL, count);
               if(name == me)
               {
                   if(give_this_script)
                   folder_contents += [name];
               }
               else
               folder_contents += [name];
           }
           while((++count) < NOI);
       }
       folder_name = llGetObjectDesc();
   }

}

default {

   on_rez(integer param)
   {
       owner = llGetOwner();
       me = llGetScriptName();
       OnRezTextOptionsFunctionThingy(FALSE);
   }
   touch_start(integer nd)
   {
       if(!open)
       {
           integer give = FALSE;
           key toucher = llDetectedKey(0);
           if(allow_only_owner)
           {
               if(toucher == owner)
               give = TRUE;
           }
           else
           {
               give = TRUE;
           }
           if(give)
           {
               open = TRUE;
               llGiveInventoryList(toucher, folder_name, folder_contents);
           }
           if(open)
           {
               if(display_deletion_text != "")
               llSetText(display_deletion_text, deletion_text_color, deletion_text_alpha);
               if(localchat_deletion_text != "")
               llSay(0, localchat_deletion_text);
               if(ownerchat_deletion_text != "")
               llOwnerSay(ownerchat_deletion_text);
               if(self_delete)
               {
                   if(timed_deletion)
                   llSetTimerEvent(deletion_delay);
                   else
                   llDie();
               }
               else
               {
                   open = FALSE;
                   OnRezTextOptionsFunctionThingy(TRUE);
               }
           }
       }
   }
   timer()
   {
       llDie();
   }

}</lsl>

Give dialog offering a push button to visit the URL of your choice

If you have a website you can direct people there with something like this

<lsl>string URL_Loader_Message = "\nCopy FREE scripts from an SL wiki page"; // Message to show on dialog.

string URL_To_Visit = "https://wiki.secondlife.com/wiki/User:Fred_Gandt/Scripts"; // URL to visit.

vector Omega_Axis = <0.0,0.0,1.0>; // If you don't want spinning set this to <0.0,0.0,0.0>;

float Omega_Speed = 0.5; // Speed of spin.

float Omega_Gain = 1.0; // Strength of spin.

string Floating_Text = "FREE SCRIPTS!!\n \nTouch to visit web site.\n \n(Official SL wiki)\n \n "; // Floating text.

vector Float_Text_Color = <1.0,1.0,1.0>; // Color of floating text.

float Float_Text_Alpha = 1.0; // Transparency of floating text (1.0 is solid).

// FROM THIS POINT IT IS SCARY!! ARRGGGHHHH...!!! //

default {

   state_entry()
   {
       llTargetOmega(Omega_Axis, Omega_Speed, Omega_Gain);
       llSetText(Floating_Text, Float_Text_Color, Float_Text_Alpha);
   }
   touch_start(integer nd)
   {
       integer count = 0;
       do
       {
           key toucher = llDetectedKey(count);
           llLoadURL(toucher, URL_Loader_Message, URL_To_Visit);
       }
       while((++count) < nd);
   }

}</lsl>

Alarm Clock (simple)

Good for reminding you about sandbox returns etc.

<lsl>string sound = "5e1d5f52-e7ae-0194-a412-93a96f39ff6f"; // Name of the sound in the object inventory.

                                                      // Or the UUID of any sound.

float time;

integer on;

default {

   touch_end(integer nd)
   {
       if(on)
       {
           llStopSound();
           llResetScript();
       }
       else
       {
           time = ((float)llGetObjectDesc()); // You need to write the time for the script to run
                                              // before alarming you into the object description.
           if(time < 0.1)
           {
               llOwnerSay("The time is not set.\nPlease write the time into the object description and try again");
               return;
           }
           llSetTimerEvent(time);
           on = TRUE;
       }
   }
   timer()
   {
       llSetTimerEvent(0.0);
       llLoopSound(sound, 1.0);
   }

}</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>// The script below will make a display that looks kinda like this -

Hello there avatar! My script can align your text to the left or right. Touch me for a copy of it.

// Without it the floating text would look kinda like this -

             Hello there avatar!

My script can align your text to the left or right.

          Touch me for a copy of it.

// Text alignment! Whoot!</lsl><lsl>// SetTextAlign //

// 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 with them. // This may never have existed.

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

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

   list result = [];
   string separate = "";
   float score = 0.0;
   list scores = [];
   integer count = 0;
   integer length;
   string line;           // I'll be tidying this up very soon.
   integer s_length;
   integer count_a = 0;
   string letter;
   integer count_b = 0;
   integer count_c = 0;
   string sample;
   integer ssi;
   if(A)
   {
       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;
                           if(count_c == 1)
                           score += 1.5;
                           if(count_c == 2)
                           score += 2.0;
                           if(count_c == 3)
                           score += 2.5;
                           if(count_c == 4) // Thanx to some advice from a veritable genius ( Xzaviar Qarnac ) -
                           score += 3.0;    // - I will be looking into adding some jumps here.
                           if(count_c == 5)
                           score += 3.5;
                           if(count_c == 6)
                           score += 4.0;
                           if(count_c == 7)
                           score += 4.5;
                           if(count_c == 8)
                           score += 5.0;
                       }
                   }
                   while((++count_c) < 9);
               }
               while((++count_b) < 1);
           }
           while((++count_a) < s_length);
           scores += [score];
       }
       while((++count) < length);
       list scores_max = llListSort(scores, 1, FALSE);
       integer bulkem = 0;
       float max_score = llList2Float(scores_max, bulkem);
       do
       {
           float next = llList2Float(scores, bulkem);
           string spaces = "";
           do
           {                                                         // more tidying.
               spaces += " ";
           }
           while(((integer)((((float)llStringLength(spaces))) + next)) < max_score);
           string to_bulk = llList2String(S, bulkem);
           if(D)
           result += [(to_bulk + spaces)];
           else
           result += [(spaces + to_bulk)];
       }
       while((++bulkem) < length);
   }
   else
   result = S;
   return llDumpList2String(result, separate);

}

// SetTetAlign //

default {

   state_entry()
   {
       float alpha = 1.0;
       vector color = <1.0,1.0,1.0>;

// The text to display must be fed to the function as a list of strings each being one line (as below). // I may add the string to list function at some point ( cut out the "\n"'s )

       list source = ["Hello there avatar!", "My script can align your text to the left or right.", "Touch me for a copy of it."];
       llSetText(SetTetAlign(TRUE, TRUE, source), color, alpha);

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

   }

}</lsl>