-->

FoxSan's 3D Tools and LSL Script Repository

Tons of LSL scripts, examples and 3D tools, free for all. There are currently 207 scripts and articles in this database.

Animation Script Example

////////////////////////////////////////////
// Animation Script v1.2.1
//
// Written by Xylor Baysklef
////////////////////////////////////////////
 
/////////////// CONSTANTS ///////////////////
list ANIMATIONS  = [ "aim_L_bow", "aim_R_bazooka", "aim_R_handgun", "aim_R_rifle", "angry_fingerwag",
"angry_tantrum", "away", "backflip", "blowkiss", "bow", "brush", "clap",
"courtbow", "cross_arms", "crouch", "crouchwalk", "curtsy",
"dance1", "dance2", "dance3", "dance4", "dance5", "dance6", "dance7", "dance8",
"dead", "drink", "express_afraid", "express_anger", "express_bored",
"express_cry", "express_embarrased", "express_laugh", "express_repulsed",
"express_sad", "express_shrug", "express_surprise", "express_wink",
"express_worry", "falldown", "female_walk", "fist_pump", "fly", "flyslow",
"hello", "hold_R_bow", "hold_R_bazooka", "hold_R_handgun", "hold_R_rifle",
"hold_throw_R", "hover", "hover_down", "hover_up", "impatient",
"jump", "jumpforjoy", "kick_roundhouse_R", "kissmybutt", "kneel_left",
"kneel_right", "land", "laugh_short", "motorcycle_sit", "musclebeach", "no_head", "no_unhappy",
"nyanya", "peace", "point_me", "point_you" ];
 
list ANIMATIONS2 = [ "prejump", "punch_L", "punch_onetwo", "punch_R",
"RPS_countdown", "RPS_paper", "RPS_rock",
"RPS_scissors", "run", "salute", "shoot_L_bow", "shout", "sit", "sit_female", "sit_ground",
"sit_to_stand", "sleep", "slowwalk", "smoke_idle", "smoke_inhale", "smoke_throw_down",
"snapshot", "soft_land", "stand", "standup", "stand_1", "stand_2",
"stand_3", "stand_4", "stretch", "stride", "surf", "sword_strike_R",
"talk", "throw_R", "tryon_shirt", "turnback_180", "turnleft", "turnright",
"turn_180", "type", "uphillwalk", "walk", "whisper", "whistle", "wink_hollywood", "yell",
"yes_happy", "yes_head", "yoga_float" ];
///////////// END CONSTANTS /////////////////
 
///////////// GLOBAL VARIABLES ///////////////
//integer gToggle = 0;
integer gAnimNumber;
integer gTotalAnims;
 
string gAnimName = "type";
/////////// END GLOBAL VARIABLES /////////////
 
default {
    state_entry() {
        //llSay(0, "Init...");
        llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
 
        ANIMATIONS += ANIMATIONS2;
        ANIMATIONS2 = [];
 
        gTotalAnims = llGetListLength(ANIMATIONS);
        gAnimNumber = -1;
        llListen(0, "", llGetOwner(), "");
    }
 
    on_rez(integer param) {
        //llGiveInventory(llGetOwner(), "Animation Names");
        llResetScript();
    }
 
    listen(integer channel, string name, key id, string mesg) {
        string preamble = llGetSubString(mesg, 0, 3);
        if (preamble != "anim" && preamble != "stop")
            return;
 
        integer perm = llGetPermissions();
 
        if ( !(perm & PERMISSION_TRIGGER_ANIMATION)) {
            llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
            return;
        }
 
        list parsed = llParseString2List(mesg, [ " " ], []);
        //llSay(0, (string)parsed);
 
        string anim = llList2String(parsed, 1);
 
        if (preamble == "stop") {
            //llSay(0, "Stopping: " + llGetAnimation(llGetOwner()));
            //llStopAnimation(llGetAnimation(llGetOwner()));
            if (anim == "")
                anim = gAnimName;
 
            if (anim == "all") {
                integer i;
                llSay(0, "Stopping all animations... please wait.");
                for (i=0; i<gTotalAnims; i++)
                    llStopAnimation(llList2String(ANIMATIONS, i));
 
                llSay(0, "Done.");
 
                return;
            }
 
            //llSay(0, "Stopping: " + anim);
            llStopAnimation(anim);
            return;
        }
 
        gAnimName = anim;
        //llSay(0, "Animation: " + gAnimName);
        llStartAnimation(gAnimName);
    }
 
    run_time_permissions(integer perm) {
        //llStopAnimation(gAnimName);
        //gToggle = 0;
    }
 
    attach(key id) {
        integer perm = llGetPermissions();
 
        if (id != NULL_KEY) {        
 
            if (! (perm & PERMISSION_TRIGGER_ANIMATION)) {
                llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
            }
        }
        else {
 
            if (perm & PERMISSION_TRIGGER_ANIMATION) {
                llStopAnimation(gAnimName);
            }
        }
    }
 
    touch_start(integer total_number) {
        if (llDetectedKey(0) != llGetOwner())
            return;
 
        integer perm = llGetPermissions();
 
        if (perm & PERMISSION_TRIGGER_ANIMATION) {
            if (gAnimNumber != -1) {
                llStopAnimation( llList2String(ANIMATIONS, gAnimNumber) );
            }
 
            gAnimNumber++;
            if (gAnimNumber == gTotalAnims)
                gAnimNumber = 0;
 
            gAnimName = llList2String(ANIMATIONS, gAnimNumber);
 
            llStartAnimation( gAnimName );
            llSay(0, "Animation: " + gAnimName);
        }
        else {
            llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
        }
    }
}

If Else Example

// Bromley College
// Linden Script Exhibition
 
// Code for poster 16;
 
// You will notice that this program contains two states default and new. It was necessary to introduce states in this example in order to prevent the poster listening continuously and responding to all events on channel 0. Before introducing states the else condition was even "replying" to the chat messages produced when posters 17 and 18 were touched! ;
 
default
{
    touch_start(integer total_number)
    {
        llSay(0, "What is the number of this              poster? Please reply using chat.");
        state new;
    }
}
 
state new
{
    state_entry()
    {
       llListen(0,"",NULL_KEY, "");
    }
 
    listen(integer channel, string name, key id, string message)
    {
        if(message=="16")
        {
            llSay(0,"Well done your answer is correct");
        }
        else
        {
        llWhisper(0,"Sorry wrong answer, please click on this poster to try again");
        }
        state default;
    }
}
 
// End of code;

List Example

// Bromley College
// Linden Script Exhibition
 
// Code for poster 38
 
list SCAN = []; // define an empty list
integer ItemNumber; // reference number of selected item
integer ItemTotal; // total number of items
string Item; // the selected item
 
default
{
    state_entry()
    {
        llSetTimerEvent( 0 ); //disable timer
    }
 
    touch_start(integer total_number) // wait for touch and scan for agents
    {
        llSensor("", NULL_KEY, AGENT, 96, PI);
    }
 
    sensor(integer total_number)
    // write scan results into a list one by one
    {
        integer i;
        for (i = 0; i < total_number; i++)
        {
            SCAN = SCAN + [llDetectedName(i)];
        }
        llSay(0, "Scanning complete " + (string)i + " avatar(s) detected and stored in list. Touch poster again to view list. ");
        if(i==total_number) // if scan complete
        {
             state playback;
        }
    }
}
 
state playback
{
    touch_start(integer total_number) // on touch display list contents one by one with a half second delay between each item
    {
        ItemTotal = llGetListLength(SCAN);
        llSetTimerEvent( 0.5 );
    }    
 
    timer ()
    {
        Item = llList2String(SCAN, ItemNumber); // Get Item from list
        llSay(0, "List Item " + (string)ItemNumber + ": " + (string)Item);
        // Output Item
        ItemNumber++;
        // Point to next Item in list
 
        if (ItemNumber == ItemTotal)
        // if all items displayed reset
        {
            ItemNumber = 0;
            llResetScript();
        }
    }
}
 
// End of code;

Count In llGetObjectDesc Example

default
{
    touch_start(integer total_number)
    {
        integer count;
        // Retrieves the count
        count = (integer)llGetObjectDesc();
        // Increment it
        count++;
        // Save it
        llSetObjectDesc((string)count);
    }
}

Look At Example

string person;
integer found;
 
default
{
    state_entry()
    {
        llSetColor(<1,1,1>, ALL_SIDES);
        llListen(0, "", llGetOwner(), "");
    }
    listen(integer channel, string name, key id, string message)
    {
        string lowerMessage = llToLower(message);
 
        if (lowerMessage == "reset look")
        {
            //Remove the sensor
            llSay(0, "Removing Look");
            llSensorRemove();
        }
        if(llSubStringIndex(lowerMessage, "look at") >= 0)
        {
            //Remove the Previous Sensor
            llSensorRemove();
 
            //Get the name of the person
            person = llGetSubString(message, 8, llStringLength(message));
 
            //Setup a repeating sensor
            found = FALSE;
            llSetColor(<0,0,1>, ALL_SIDES);
            llSay(0, "Scanning for " + person);
            llSensorRepeat(person, NULL_KEY, AGENT, 96, TWO_PI, 0.5);
        }
    }
    no_sensor()
    {
        //Remove Sensor if Avatar not found
        llSay(0, person + " not found. Removing Look.");
        llSetColor(<1,0,0>, ALL_SIDES);
        llSensorRemove();
        llSleep(2);
        llSetColor(<1,1,1>, ALL_SIDES);
    }
    sensor(integer num_detected)
    {
        if (!found)
        {
            llSetColor(<0,1,0>, ALL_SIDES);
            llSay(0, (string)num_detected);
            llSay(0, "Found " + person + ".");
        }
        found = TRUE;
        //Get postion of detected Agent
        vector pos = llDetectedPos(0);
 
        //Point our prim to look at them
        llLookAt(pos, 1.0, 1.0);
    }
}