User:Aryn Gellner

From Second Life Wiki
Jump to: navigation, search

Free LSL Scripts and snippets

Optimized Hovertext Adder

Note: Script deletes itself after setting. This is preferred, since hovertext is considered a property of the prim itself and is immune to copying/taking.

default
{
    state_entry()
    {
        llListen(20, "", llGetOwner(), "");
        llTextBox(llGetOwner(), "Set Hovertext", 20);
        llRegionSayTo(llGetOwner(), 0, "Enter set hovertext in the resultant text box, or on channel 20");
    }
    listen(integer chan, string name, key id, string msg)
    {
        llSetText(msg, <1, 1, 1>, 1.0);
        llRemoveInventory(llGetScriptName());
    }
}



Optimized Rotation Slow

Note: Script deletes itself after setting. This is preferred, since llTargetOmega() is considered a property of the prim itself and is immune to copying/taking.

default
{
    state_entry()
    {
       llTargetOmega(<0,0,1>*llGetLocalRot(),PI/4,1.0);
       llRemoveInventory(llGetScriptName());
    }
}



Give Inventory as a folder

string folder = ""; // Defaults to object name. Change this to a different value to set the folder name for the recipient.
 
default
{
    touch_start(integer total_number)
    {
        list inv = [];
 
        integer i = llGetInventoryNumber(INVENTORY_ALL);
 
        while(--i >= 0)
        {
            inv += llGetInventoryName(INVENTORY_ALL, i);
        }
        integer removeThis = llListFindList(inv, [llGetScriptName()]);
 
        inv = llDeleteSubList(inv, removeThis, removeThis);
 
        if(folder == "")
        {
            llGiveInventoryList(llDetectedKey(0), llGetObjectName(), inv);
        }
        else
        {
            llGiveInventoryList(llDetectedKey(0), folder, inv);
        }
    }
}



Basic Keyframed Follower/Bot

Notes:

  • Linkset/object must be a Prim Equivalency linkset see llSetKeyframedMotion for details
  • Object will auto-delete under the following circumstances:
    • Avatar/target is too far away ( > 62m)
    • Avatar teleports away or target ceases to exist
  • Owner can be an object as well as an avatar. By default it's set to the avatar owner
vector offset = <-1.3,-0.5,1.1>;
key owner;
 
rotation llRotNorm(rotation Q)
{
    float MagQ = llSqrt(Q.x*Q.x + Q.y*Q.y +Q.z*Q.z + Q.s*Q.s);
 
    return
        <Q.x/MagQ, Q.y/MagQ, Q.z/MagQ, Q.s/MagQ>;
}
 
default
{
    state_entry()
    {
        llSetTimerEvent(0.25);
        owner = llGetOwner();
    }
 
    on_rez(integer param)
    {
        owner = llGetOwner();
    }
 
    timer()
    {
        list temp = llGetObjectDetails(owner, [OBJECT_POS, OBJECT_ROT]);
        vector myPos = llGetPos();
        vector avPos = llList2Vector(temp, 0);
        rotation avRot = llList2Rot(temp, 1);
 
        vector fwd = llVecNorm(avPos - myPos);
        vector left = <0, 1, 0>*avRot;
 
        rotation targetRot = llAxes2Rot(left % fwd, left, fwd);
 
        vector target = avPos + offset*avRot;
 
        if(llVecDist(avPos, myPos) < 62 && avPos != ZERO_VECTOR)
        {
            llSetKeyframedMotion([target - myPos, llRotNorm(targetRot)/llGetRot(), 22.5/llGetRegionFPS()], []);
        }
        else
        {
            llDie();
        }
    }
}