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

From Second Life Wiki
Jump to navigation Jump to search
(→‎Basic Light Switch: Added notes.)
(Added notes to scripts.)
Line 7: Line 7:
== Basic Light Switch ==
== 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)
<lsl>// This script will cause the prim it is in to emit light.
// is touched the light will turn off if on and on if off. The switching code can be used for many different actions.
// 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'.
integer on; // Global variable used to measure the condition 'on or off'.
Line 42: Line 44:
'''IF TOO MANY AGENTS USE IT THE MEMORY WILL RUN OUT AND IT WILL FAIL'''
'''IF TOO MANY AGENTS USE IT THE MEMORY WILL RUN OUT AND IT WILL FAIL'''


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


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


integer count;
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.
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 set running and drop in your prim.
integer ammount = 1; // Change this figure to the required ammount to give away (e.g. 5). Then drop in your object.


default
default
Line 56: Line 58:
     on_rez(integer param)
     on_rez(integer param)
     {
     {
         llResetScript();
         llResetScript(); // Clear all lists and reset all variables. This action will also clear the permissions.
     }
     }
     changed(integer change)
     changed(integer change)
     {
     {
         if(change & CHANGED_OWNER)
         if(change & CHANGED_OWNER) // If the script or object changes ownership the script will not be able
         llResetScript();
         llResetScript();           // to deduct cash from the previous owners account.
     }
     }
     state_entry()
     state_entry()
     {
     {
         owner = llGetOwner();
         owner = llGetOwner(); // Store the owners key.
         llRequestPermissions(owner, PERMISSION_DEBIT); // THIS MEANS IT WILL TAKE YOUR MONEY.
         llRequestPermissions(owner, PERMISSION_DEBIT); // !! THIS MEANS IT WILL TAKE YOUR MONEY !!
     }
     }
     run_time_permissions(integer perm)
     run_time_permissions(integer perm)
     {
     {
         if(perm & PERMISSION_DEBIT)
         if(perm & PERMISSION_DEBIT) // Have we got the permissions we requested?
         perms = TRUE;
         perms = TRUE; // Store the result of success.
         else
         else
         llRequestPermissions(owner, PERMISSION_DEBIT);
         llRequestPermissions(owner, PERMISSION_DEBIT); // If not we ask for them again.
     }
     }
     touch_end(integer nd)
     touch_end(integer nd)
     {
     {
         do
         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);
             key toucher = llDetectedKey(count);
             if(llListFindList(visitors, [toucher]) == -1)
             if(llListFindList(visitors, [toucher]) == -1) // Check if the agent has touched us before by searching the list for a match.
             {
             {
                 if(perms)
                 if(perms) // Check if we have permissions.
                 {
                 {
                     llGiveMoney(toucher, ammount);
                     llGiveMoney(toucher, ammount); // Ker-ching!!
                     visitors += toucher;
                     visitors += toucher; // That's all buster! NEXT!!
                 }
                 }
             }
             }
         }
         }
         while((++count) < nd);
         while((++count) < nd); // Increment the counter and loop while it is less than the number of touchers detected.
         count = 0;
         count = 0; // Reset the counter.
     }
     }
}</lsl>
}</lsl>
Line 100: Line 102:
default
default
{
{
    on_rez(integer param)
    {
        llResetScript();
    }
     state_entry()
     state_entry()
     {
     {
Line 111: Line 109:
     run_time_permissions(integer perm)
     run_time_permissions(integer perm)
     {
     {
         if(perm & PERMISSION_TAKE_CONTROLS)
         if(perm & PERMISSION_TAKE_CONTROLS) // Do we have the perms we asked for?
         llTakeControls(CONTROL_ML_LBUTTON, TRUE, FALSE);
         llTakeControls(CONTROL_ML_LBUTTON, TRUE, FALSE); // This creates a button at the bottom of the screen
         else
         else                   // that if pressed automatically zooms the camera of the owner into mouselook.
         llRequestPermissions(owner, PERMISSION_TAKE_CONTROLS);
         llRequestPermissions(owner, PERMISSION_TAKE_CONTROLS);
     }
     }
     control(key id, integer this, integer that)
     control(key id, integer this, integer that)
     {
     {                       // Adding various conditions here can change the script behavior in many ways.
         // Do stuff when clicking the left mouse button while in mouselook. Like for guns etc.
         llOwnerSay("Click"); // Do stuff when clicking the left mouse button while in mouselook. Like for guns etc.
     }
     }
}</lsl>
}</lsl>
Line 124: Line 122:
== Script that makes the object it is in float on water ==
== Script that makes the object it is in float on water ==


<lsl>// Floating on water script
<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.
float offset = 0.0; // add the offset here
default // The offset is a measure of meters and/or parts thereof.
 
default
{
{
     on_rez(integer param)
     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);
         float float_height = (llWater(ZERO_VECTOR) + offset);  
         vector pos = llGetPos();
         vector pos = llGetPos();
         llSetStatus(STATUS_PHYSICS, TRUE);
         llSetStatus(STATUS_PHYSICS, TRUE); // Make the object physical.
         llMoveToTarget(<pos.x, pos.y, float_height>, 0.5);
         llMoveToTarget(<pos.x, pos.y, float_height>, 0.5); // Have it maintain it's position.
     }
     }
}</lsl>
}</lsl>
Line 143: Line 139:
<lsl>integer on;
<lsl>integer on;


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


string command = "switch"; // place command here to say. Same command will switch on and off.
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)
integer channel = 1; // Place channel to use here (must be a positive if an avatar is chatting on it).


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


Line 159: Line 155:
     {
     {
         owner = llGetOwner();
         owner = llGetOwner();
         llListen(channel, "", owner, command);
         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)
     touch_end(integer nd)
     {
     {
         on = (!on);
         on = (!on);
         Switch(on);
         Switch(on); // Blah
     }
     }
     listen(integer chan, string name, key id, string msg)
     listen(integer chan, string name, key id, string msg)
     {
     {
         on = (!on);
         on = (!on);
         Switch(on);
         Switch(on); // Blah
     }
     }
}</lsl>
}</lsl>

Revision as of 10:33, 25 January 2010

All the below scripts are basic and to be cleaned up and annotetated later (next few days prolly)


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

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

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