User:Tutti Anatine/scripts

From Second Life Wiki
Jump to navigation Jump to search

These are open source scripts I have written. You are free to alter and distribute these scripts, but not sell them for more than L$0. If you alter the script, make sure to add it to the comments on top of the script. Do not remove existing comments. There is no need to credit me when using these scripts, but do credit when you use part of my code in your own script.

Please make sure the scripts are distributed with full permissions.

Floating text

Inexperienced-user-friendly options include:

  • Personalized floating text;
  • Custom text color (default is white);
  • Optional text transparency;
  • Optional text disappearance after given number of seconds.
    • Note: if this is set, text will reappear on touch of the containing object.

<lsl>/* [*TA*] Floating Text script By Tutti Anatine

Feel free to edit this code but do not sell it for more than L$0. Keep permissions copy/mod/transfer at all times. Make a copy of the original script before editing the code to prevent loss. If you have been charged money for this script, please contact the seller and ask for full compensation. Please do not remove this text and other comments within this script.

Last edit: 17 August 2011 */ key CREATOR = "95eaa123-5b83-437e-9fe9-90def840da39";

// -------------------- // settings - edit these to suit your taste // --------------------

// constants float TIMEOUT = 0.0; // this is 0.0 on default, put in a higher value to make the floating text disappear after given number of seconds string FLOATING_TEXT = ""; // this is the floating text that is displayed | start new lines using '\n', without the quotes, in your text vector TEXT_COLOR = <1.0,1.0,1.0>; // color value of the floating text | ranges between <1.0, 1.0, 1.0> (white) and <0.0, 0.0, 0.0> (black) | order: red, green, blue float TEXT_ALPHA = 1.0; // the transparency of the floating text | ranges between 0.0 (full transparency) and 1.0 (no transparency)

// -------------------- // do not edit below this line unless you know what you're doing! // --------------------

// basic setup of script, used instead of llResetScript(); init() {

   llSetText(FLOATING_TEXT,TEXT_COLOR,TEXT_ALPHA);
       
   if (TIMEOUT > 0) {
       llSetTimerEvent(TIMEOUT);
   }

}

default {

   state_entry() {
       init();
   }
   
   touch_start(integer num_detected) {
       init();
   }
   
   timer() {
       llSetText("",TEXT_COLOR,TEXT_ALPHA); // remove floating text
   }
   
   changed(integer change) {
       if (change & CHANGED_OWNER) {
           init();
       }
   }
   
   on_rez(integer start_param) {
       init();
   }

}</lsl>

Pose stand (with buttons)

A single-animation pose stand which can pose one avatar at a time. It is compatible with the optional button scripts provided here as well.

Base

The base of the pose stand, where a single avatar can sit on. Inexperienced-user-friendly options include:

  • Turn automatic deletion of the object on or off;
  • Set the timeout for automatic deletion in seconds;
  • Set the amount of meters an avatar will move up or down when the height offset buttons are used;
  • Set the number of degrees an avatar will turn clockwise or anti-clockwise when the rotation buttons are used.

More experienced users may want to change the init() function to make the script more suitable for their stand. Please read the comments in this function for instructions.

<lsl>/* [*TA*] Pose Stand script - base By Tutti Anatine

Feel free to edit this code but do not sell it for more than L$0. Keep permissions copy/mod/transfer at all times. Make a copy of the original script before editing the code to prevent loss. If you have been charged money for this script, please contact the seller and ask for full compensation. Please do not remove this text and other comments within this script.

Last edit: 6 August 2011 */ key CREATOR = "95eaa123-5b83-437e-9fe9-90def840da39";

// -------------------- // settings - edit these to suit your taste // --------------------

// constants integer AUTO_DELETE = FALSE; // turns auto deletion of the object on or off | TRUE for on, FALSE is off integer TIMEOUT = 60; // the number of seconds that have to pass before the object deletes itself (when AUTO_DELETE = TRUE) float HEIGHT_OFFSET = 0.1; // the amount of meters the posing avatar moves up or down when touching the height buttons | has to be a positive number | default: 0.1 float ROTATION_OFFSET = 30.0; // the number of degrees the posing avatar turns around when touching the rotation buttons | has to be a positive number | default: 30.0

// -------------------- // do not edit below this line unless you know what you're doing! // --------------------

// variables vector currentOffset; vector currentRotInDegrees; rotation currentRotation;

// basic setup of script, used instead of llResetScript(); init() {

   currentOffset = <0.0,0.0,0.8>; // ideally, set the z-value to the height of the pose stand base
   currentRotInDegrees = <0.0,0.0,180.0>; // <0.0,0.0,180.0> when using animation 'T Pose' | <0.0,0.0,0.0> when using animaton 'turn_180'
   currentRotation = vectorToRotation(currentRotInDegrees);
   llSetSitText("Pose");
   llSitTarget(currentOffset,currentRotation);
   llSetClickAction(CLICK_ACTION_SIT);

}

changeOffsetHeight(float correction) {

   currentOffset.z += correction;
   UpdateSitTarget(currentOffset,currentRotation);

}

changeRotation(float correction) {

   currentRotInDegrees.z += correction;
   currentRotation = vectorToRotation(currentRotInDegrees);
   UpdateSitTarget(currentOffset,currentRotation);

}

rotation vectorToRotation(vector rotInDegrees) {

   vector rotInRadians = rotInDegrees * DEG_TO_RAD;
   return llEuler2Rot(rotInRadians);

}

//Sets / Updates the sit target moving the avatar on it if necessary. UpdateSitTarget(vector pos, rotation rot) {//Using this while the object is moving may give unpredictable results.

   llSitTarget(pos, rot);//Set the sit target
   key user = llAvatarOnSitTarget();
   if(user)//true if there is a user seated on the sittarget, if so update their position
   {
       vector size = llGetAgentSize(user);
       if(size)//This tests to make sure the user really exists.
       {
           //We need to make the position and rotation local to the current prim
           rotation localrot = ZERO_ROTATION;
           vector localpos = ZERO_VECTOR;
           if(llGetLinkNumber() > 1)//only need the local rot if it's not the root.
           {
               localrot = llGetLocalRot();
               localpos = llGetLocalPos();
           }
           pos.z += 0.4;
           integer linkNum = llGetNumberOfPrims();
           do{
               if(user == llGetLinkKey( linkNum ))//just checking to make sure the index is valid.
               {
                   llSetLinkPrimitiveParams(linkNum,
                                           [PRIM_POSITION, ((pos - (llRot2Up(rot) * size.z * 0.02638)) * localrot) + localpos,
                                            PRIM_ROTATION, rot * localrot / llGetRootRotation()]);
                   jump end;//cheaper but a tad slower then return
               }
           }while( --linkNum );
       }
       else
       {//It is rare that the sit target will bork but it does happen, this can help to fix it.
           llUnSit(user);
       }
   }
   @end;

}//Written by Strife Onizuka, size adjustment provided by Escort DeFarge

pose() {

   llStopAnimation("sit");
   llStartAnimation("T Pose"); // you can change this to the built-in animation 'turn_180', the (should be) provided 'T Pose' or a custom animation from the pose stand base's contents

}

// this will only be activated when AUTO_DELETE = TRUE setTimer() {

   llOwnerSay("I will delete myself in 60 seconds unless you stand on me before then.");
   llSetTimerEvent(TIMEOUT);

}

default {

   state_entry() {
       init();
   }
   
   link_message(integer sender_num, integer num, string str, key id) {
       // matching button script(s) should've come with this base script
       if (str == "up") {
           changeOffsetHeight(HEIGHT_OFFSET);
       } else if (str == "down") {
           changeOffsetHeight(-HEIGHT_OFFSET);
       } else if (str == "clockwise") {
           changeRotation(-ROTATION_OFFSET);
       } else if (str == "anticlockwise") {
           changeRotation(ROTATION_OFFSET);
       }
   }
   
   changed(integer change) {
       // this occurs when an avatars sits on the object, or stands up from it
       if (change & CHANGED_LINK) {
           key avatar = llAvatarOnSitTarget();
           
           if (avatar != NULL_KEY) {
               llSetTimerEvent(0.0);
               llRequestPermissions(avatar,PERMISSION_TRIGGER_ANIMATION);
           } else {
               if (AUTO_DELETE == TRUE) {
                   setTimer();
               }
           }
       }
   }
   
   run_time_permissions(integer perm) {
       if (perm & PERMISSION_TRIGGER_ANIMATION){
           pose();
       }
   }
   
   on_rez(integer start_param) {
       if (AUTO_DELETE == TRUE) {
           setTimer();
       }
   }
   
   timer() {
       llSetTimerEvent(0.0);
       llDie(); // this deletes the entire object
   }

}</lsl>

Button

An optional button script. This can either be a height offset or rotation button, depending on the value of DIRECTION.

<lsl>/* [*TA*] Pose Stand script - button By Tutti Anatine

Feel free to edit this code but do not sell it for more than L$0. Keep permissions copy/mod/transfer at all times. Make a copy of the original script before editing the code to prevent loss. If you have been charged money for this script, please contact the seller and ask for full compensation. Please do not remove this text and other comments within this script.

Last edit: 6 August 2011 */ key CREATOR = "95eaa123-5b83-437e-9fe9-90def840da39";

// -------------------- // settings - edit these to suit your taste // --------------------

// constants string DIRECTION = ""; // 'up' or 'down' for height offset | 'clockwise' or 'anticlockwise' for rotation

// -------------------- // do not edit below this line unless you know what you're doing! // --------------------

default {

   touch_start(integer num_detected) {
       llMessageLinked(LINK_ROOT,0,DIRECTION,"");
   }

}</lsl>

Notes

  • The function UpdateSitTarget() is written by Strife Onizuka and Escort DeFarge and was taken from LlSitTarget.
  • The in-world original uses a pose called 'T Pose' by Adenoraque Qin. It's also possible to change the script to use Linden Labs' default animation, turn_180. Instructions to do this are inside the base script, function init().

Tip jar

A simple tip jar script, all donations go to the owner. Inexperienced-user-friendly options include:

  • Change quick pay button values;
  • Set the color of the floating text;
  • Personalized thank you message.

<lsl>/* [*TA*] Tip Jar script By Tutti Anatine

Feel free to edit this code but do not sell it for more than L$0. Keep permissions copy/mod/transfer at all times. Make a copy of the original script before editing the code to prevent loss. If you have been charged money for this script, please contact the seller and ask for full compensation. Please do not remove this text and other comments within this script.

Last edit: 31 July 2011 */ key CREATOR = "95eaa123-5b83-437e-9fe9-90def840da39";

// -------------------- // settings - edit these to suit your taste // --------------------

// constants list QUICK_PAY_BUTTONS = [5,10,20,40]; // the values of the quick page buttons, set value to PAY_HIDE to hide a button | order: top left, top right, bottom left, bottom right vector FLOATING_TEXT_COLOR = <1.0 , 1.0, 1.0>; // color value of floating text | ranges between <1.0 , 1.0, 1.0> (white) and <0.0 , 0.0, 0.0> (black) | order: red, green, blue string THANK_MESSAGE = "Thank you for your donation, I really appreciate it!"; // the private message sent to a donator after donation

// -------------------- // do not edit below this line unless you know what you're doing! // --------------------

// variables key owner; integer donatedThisSession; integer lastDonation; string lastDonator;

// basic setup of script, used instead of llResetScript(); init() {

   owner = llGetOwner();
   donatedThisSession = 0;
   llSetPayPrice(0, QUICK_PAY_BUTTONS);
   updateFloatingText();
   llSetClickAction(CLICK_ACTION_PAY);

}

updateFloatingText() {

   if (donatedThisSession > 0) {
       llSetText(llKey2Name(owner)+"'s Tip Jar\nClick me to donate\nL$"+(string)donatedThisSession+" donated this session\nLast donation: L$"+(string)lastDonation+" by "+lastDonator, FLOATING_TEXT_COLOR, 1.0);
   } else {
       llSetText(llKey2Name(owner)+"'s Tip Jar\nClick me to donate", FLOATING_TEXT_COLOR, 1.0);
   }

}

default {

   state_entry() {
       init();
   }
   
   money(key id, integer amount) {
       donatedThisSession += amount;
       lastDonation = amount;
       lastDonator = llKey2Name(id);
       updateFloatingText();
       llInstantMessage(id, THANK_MESSAGE);
       llInstantMessage(owner,lastDonator+" just donated L$"+(string)lastDonation);
   }
   
   changed(integer change) {
       if (change & CHANGED_OWNER) {
           init();
       }
   }
   
   on_rez(integer start_param) {
       init();
   }

}</lsl>

Unpacker

Unpacker for owner of containing object. Users can change the color of the floating text.

<lsl>/* [*TA*] Unpacker script By Tutti Anatine

Feel free to edit this code but do not sell it for more than L$0. Keep permissions copy/mod/transfer at all times. Make a copy of the original script before editing the code to prevent loss. If you have been charged money for this script, please contact the seller and ask for full compensation. Please do not remove this text and other comments within this script.

Last edit: 17 August 2011 */ key CREATOR = "95eaa123-5b83-437e-9fe9-90def840da39";

// -------------------- // settings - edit these to suit your taste // --------------------

// constants vector FLOATING_TEXT_COLOR = <1.0 , 1.0, 1.0>; // color value of floating text | ranges between <1.0 , 1.0, 1.0> (white) and <0.0 , 0.0, 0.0> (black) | order: red, green, blue

// -------------------- // do not edit below this line unless you know what you're doing! // --------------------

// variables key owner; list inventoryList;

// basic setup of script, used instead of llResetScript(); init() { owner = llGetOwner(); updateInventoryList();

if (llGetListLength(inventoryList) == 0) { llSetText("This package is empty.",FLOATING_TEXT_COLOR,1.0); } else { llSetText("Please touch to unpack me.",FLOATING_TEXT_COLOR,1.0); } }

updateInventoryList() { llSetText("Reloading inventory, please be patient while waiting.",FLOATING_TEXT_COLOR,1.0);

   integer count = llGetInventoryNumber(INVENTORY_ALL);
   inventoryList = [];

integer i; for (i = 0; i < count; i++) { string name = llGetInventoryName(INVENTORY_ALL,i); if (name != llGetScriptName()) { inventoryList += [name]; } } }

default {

   state_entry() {
   	init();
   }
   touch_start(integer num_detected) {
   	if (!llGetListLength(inventoryList) == 0) {

key avatar = llDetectedKey(0); if (avatar == owner) { llGiveInventoryList(owner,llGetObjectName(),inventoryList); llSetText("This package is now unpacked and can be safely deleted.",FLOATING_TEXT_COLOR,1.0); } else { llInstantMessage(avatar,"I can not give you the contents of this package, because you are not the owner."); }

   	}
   }
   changed(integer change) {
   	if (change & CHANGED_INVENTORY) {
   		init();
       } else if (change & CHANGED_OWNER) {
           init();
       }
   }
   
   on_rez(integer start_param) {
       init();
   }

}</lsl>