-->

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.

llGetRegionAgentCount

default
{
    state_entry()
    {
        llSetTimerEvent(15.0);
    }
 
    timer()
    {
        llSetText("Agents in Region: " + (string)llGetRegionAgentCount(), <1.0, 1.0, 1.0>, 1.0);
    }
}

Basic Radar

//  Basic Radar
//  Created by Water Rogers for IBM/Opensource
 
//  Purpose
//  --------------------------------------------------------------
//  This is a basic example of how you can create a simple radar
//  to detect Avatars within a given distance around the object
//  that this script resides in.  Names will be viewed above the
//  object along with distance (in meters).
 
//  Requirements
//  --------------------------------------------------------------
//  A single prim is all that is necessary for this example.
 
//  GLOBAL VARIABLES
//  --------------------------------------------------------------
 
float   g_Range     = 96.0;     //  The range of the sensor in meters
float   g_Arc       = PI;       //  The arc of the sensor
float   g_Rate      = 1.0;      //  The repeat rate of the sensor in seconds
vector  g_TextColor = <1,1,1>;  //  Text color <1,1,1> = White  
 
//  EVENTS
//  --------------------------------------------------------------
 
default
{
    state_entry()
    {
        //  ------------------------------------------------------
        //  This is the entry-point of the script.  After a script
        //  has been saved or reset, this event will fire off first
        //  ------------------------------------------------------
 
        //  We call llSetText() first to "clear" the text above the object
        //  passing an empty string into the text parameter.
        llSetText("", g_TextColor, TRUE);
 
        //  We then call the llSensorRepeat() function to start detecting
        //  avatars.  This function will raise the sensor() event handle
        //  at a rate of g_Rate seconds.
        llSensorRepeat("", NULL_KEY, AGENT, g_Range, g_Arc, g_Rate);
 
        //  Since we passed an empty string and key value to the sensor,
        //  this tells the sensor that we want to look for any name with
        //  any key as long as it's an AGENT, which is a fancy name for
        //  Avatar.  If we wanted to look for a specific person only, we
        //  could simply pass their name and/or key into these arguments.
    }
 
    sensor(integer num_detected)
    {
        //  ------------------------------------------------------
        //  This event will fire off at the rate of g_Rate in seconds
        //  after being called by either llSensor() or llSensorRepeat()
        //  ------------------------------------------------------
 
        //  First we start out by declaring a local variable "output". This
        //  variable will store information we want in a string until we
        //  are ready to display it at the end.
        string output;
 
        //  The next variable sets up the for loop
        integer x;
 
        //  This next section will loop through each one of the num_detected
        //  items properly sensed (in this case, it will be AGENTS or Avatars)
        //  and store the results into the output string.
        for(x = 0 ; x < num_detected ; x++)
        {
            //  Using llVecDist(), we can quickly figure out the distance
            //  between 2 objects in 3D space.  To make it more readable, we
            //  store it as an integer so it truncates any decimal placements
            integer distance = (integer)llVecDist(llGetPos(), llDetectedPos(x));
            output += llDetectedName(x) + " (" + (string)distance + "m)\n";
 
            //  output += llDetectedName(x)...
            //      is the same as using
            //  output = output + llDetectedName(x)...
            //  The "\n" at the end is an escape sequence used for llSetText()
            //  to declare a new line.
        }
 
        //  When we have all the information collected, we can display it
        //  above the object using llSetText()
        llSetText(output, g_TextColor, TRUE);
    }
}

Display Sim Status

//  Display Sim Statistics
//  Created by Water Rogers for IBM/Opensource
 
//  Purpose
//  --------------------------------------------------------------
//  This script shows you how to use settext() and read some simple
//  sim statistics.
//  
 
//  Requirements
//  --------------------------------------------------------------
//  A single prim is all that is necessary for this example.
 
//  GLOBALS
//  --------------------------------------------------------------
float       g_Timer     = 5.0;          //  Interval to update in seconds
vector      g_TextColor = <1, 1, 1>;    //  The text color (1,1,1 = White)
 
//  FUNCTIONS
//  --------------------------------------------------------------
display()
{
    //  This function shows the SetText().  "\n" is a "NewLine" character
    //  that the compiler notices as an escape sequence.
    string output;
 
    //  Shows how to get the current name of the simulator the script is in
    output = llGetRegionName() + "\n";
 
    //  This function returns the hostname of the server (DNS)
    output += "Hostname: " + llGetSimulatorHostname() + "\n";
 
    //  This will return the current SIM FPS
    output += "FPS: " + (string)llGetRegionFPS() + "\n";
 
    //  This will return the current Sim Time Dilation
    output += "Time Dilation: " + (string)llGetRegionTimeDilation() + "\n";
    llSetText(output, g_TextColor, 1);
}
 
//  EVENTS
//  --------------------------------------------------------------
default
{
    state_entry()
    {
        //  First we clear any text that the object may already have,
        //  then call the display() function and set the event timer.
        llSetText("", g_TextColor, 1);
        display();
        llSetTimerEvent(g_Timer);
    }
 
    timer()
    {
        display();
    }
}

Online Status Indicator v1.6

integer glow = TRUE;
integer bounce = FALSE;
integer interpColor = TRUE;
integer interpSize = TRUE;
integer wind = FALSE;
integer followSource = FALSE;
integer followVel = FALSE;
 
// Choose a pattern from the following:
// PSYS_SRC_PATTERN_EXPLODE
// PSYS_SRC_PATTERN_DROP
// PSYS_SRC_PATTERN_ANGLE_CONE_EMPTY
// PSYS_SRC_PATTERN_ANGLE_CONE
// PSYS_SRC_PATTERN_ANGLE
integer pattern = PSYS_SRC_PATTERN_ANGLE_CONE;
 
key target =        ""; 
 
float age =         4;
float minSpeed =    0;
float maxSpeed =    0;
string texture =    "";
float startAlpha =  1;
float endAlpha =    1;
vector startColor = <1,1,1>;
vector endColor =   <1,1,1>;
vector startSize =  <.1,.1,.02>;
vector endSize =    <.1,.1,.6>;
vector push =       <0,0,0>;
 
float rate =        .01;
float radius =      .2;
integer count =     50;
float outerAngle =  0;
float innerAngle =  PI;
vector omega =      <5,5,5>;
 
integer flags;
 
updateParticles()
{
    if (target == "owner")  target = llGetOwner();
    if (target == "self")   target = llGetKey();
    if (glow)               flags = flags | PSYS_PART_EMISSIVE_MASK;
    if (bounce)             flags = flags | PSYS_PART_BOUNCE_MASK;
    if (interpColor)        flags = flags | PSYS_PART_INTERP_COLOR_MASK;
    if (interpSize)         flags = flags | PSYS_PART_INTERP_SCALE_MASK;
    if (wind)               flags = flags | PSYS_PART_WIND_MASK;
    if (followSource)       flags = flags | PSYS_PART_FOLLOW_SRC_MASK;
    if (followVel)          flags = flags | PSYS_PART_FOLLOW_VELOCITY_MASK;
    if (target != "")       flags = flags | PSYS_PART_TARGET_POS_MASK;
 
    llParticleSystem([  PSYS_PART_MAX_AGE,          age,
                        PSYS_PART_FLAGS,            flags,
                        PSYS_PART_START_COLOR,      startColor,
                        PSYS_PART_END_COLOR,        endColor,
                        PSYS_PART_START_SCALE,      startSize,
                        PSYS_PART_END_SCALE,        endSize,
                        PSYS_SRC_PATTERN,           pattern,
                        PSYS_SRC_BURST_RATE,        rate,
                        PSYS_SRC_ACCEL,             push,
                        PSYS_SRC_BURST_PART_COUNT,  count,
                        PSYS_SRC_BURST_RADIUS,      radius,
                        PSYS_SRC_BURST_SPEED_MIN,   minSpeed,
                        PSYS_SRC_BURST_SPEED_MAX,   maxSpeed,
                        PSYS_SRC_TARGET_KEY,        target,
                        PSYS_SRC_INNERANGLE,        innerAngle,
                        PSYS_SRC_OUTERANGLE,        outerAngle,
                        PSYS_SRC_OMEGA,             omega,
                        PSYS_SRC_TEXTURE,           texture,
                        PSYS_PART_START_ALPHA,      startAlpha,
                        PSYS_PART_END_ALPHA,        endAlpha
                            ]);
}
 
integer gIsOnline = FALSE;
integer gLandOwner = FALSE;
key gKey = NULL_KEY;
string gName = "";
float UPDATE_INTERVAL = 5.0; 
 
updateStatus(string s){
    key k = llGetLandOwnerAt(llGetPos());
    if(s=="1"){
        gIsOnline = TRUE;
    }else{
        gIsOnline = FALSE;
    }
}
 
key getWhom(){
    if(gKey == NULL_KEY){
        if(gLandOwner){
            return llGetLandOwnerAt(llGetPos());
        }else{
            return llGetOwner();
        }
    }else{
        return gKey;
    }
}
 
doUpdate(){
    llRequestAgentData(getWhom(),DATA_ONLINE);
}
 
updateName(){
    llRequestAgentData(getWhom(),DATA_NAME);
}
 
enable(){
    updateName();
    doUpdate();
    llSetTimerEvent(1);
    llWhisper(0,"Online status display enabled.");
 
}
disable(){
    llSetTimerEvent(0);
    llSetText("Display Disabled",<1,1,1>,1);
    llSetColor(<0,0,1>,ALL_SIDES);
    startColor = <0,0,1>;
    endColor = <0,0,1>;
    updateParticles();
    llWhisper(0,"Online status display disabled.");
}
 
default
{
    state_entry()
    {
        llListen(0, "", llGetOwner(), "");
        enable();
        llWhisper(0,"Type /ol help for a list of commands");
    }
    on_rez(integer n){
        llResetScript();
    }
    dataserver(key req, string data){
        if(data == "1" || data == "0"){
            updateStatus(data);
        }else{
            gName = data;
            llSetText("Getting online status for " + gName,<1,1,1>,1);
            llSetColor(<0,0,1>,ALL_SIDES);
            startColor = <0,0,1>;
            endColor = <0,0,1>;
            updateParticles();
            llSetTimerEvent(UPDATE_INTERVAL);
        }
    }
    timer(){
        doUpdate();
        if(gIsOnline){
            llSetText(gName + " is Online",<1,1,1>,1);
            llSetColor(<0,1,0>,ALL_SIDES);
            startColor = <0,1,0>;
            endColor = <0,1,0>;
            updateParticles();
        }else{
            llSetText(gName + " is Offline",<1,1,1>,1);
            llSetColor(<1,0,0>,ALL_SIDES);
            startColor = <1,0,0>;
            endColor = <1,0,0>;
            updateParticles();
        }
    }
    listen(integer number, string name, key id, string msg){
        if (llGetSubString(msg, 0,0) != "/"){
            return;
        }
        list argv = llParseString2List(msg, [" "], []);
        integer argc = llGetListLength(argv);
        string cmd = llToLower(llList2String(argv, 0));
        if(cmd == "/ol"){
            string arg =  llToLower(llList2String(argv, 1));
            if(arg=="on"){
                enable();
            }else if(arg=="off"){
                disable();
            }else if(arg=="land"){
                gLandOwner = TRUE;
                gKey = NULL_KEY;
                updateName();
            }else if(arg=="key"){
                gKey = llList2Key(argv,2);
                updateName();
            }else if(arg=="me"){
                gLandOwner = FALSE;
                gKey = NULL_KEY;
                updateName();
            }else if(arg=="help"){
                llWhisper(0,"/ol on - activate online status display");
                llWhisper(0,"/ol off - disable online status display");
                llWhisper(0,"/ol land - display online status for owner of this land");
                llWhisper(0,"/ol me - display your online status");
            }
        }
    }
 
}

Object Detector

//
//    SHOP ZERO Tips24 ObjectDetector v1.0
//
//                   Created by Zero2000 Kid     2008/03/21
// 
 
integer input_ch = 33;
integer range=96;
integer handle;
string target;
string simname;
 
output_info (vector v , string name) {
    string pos=(string)v.x + "/" + (string)v.y + "/" + (string)v.z;
    llInstantMessage(llGetOwner(),name+"--> secondlife://"+simname+"/"+pos);
}
 
default {
    state_entry(){
        handle = llListen(input_ch,"",llGetOwner(),"");
    }
 
    on_rez(integer param){
        llResetScript();
    }
 
    listen(integer ch, string name, key id, string message) {
        target=message;
        simname=llGetRegionName();
        llInstantMessage(llGetOwner(),"Searching " + target + " ....");
        state active_target;
    }
 
}
 
state active_target {
 
    state_entry(){
        llInstantMessage(llGetOwner(),"< active_target >");
        llSensor(target, NULL_KEY, ACTIVE, range, PI);
    }
 
    sensor(integer total_number) {
        integer i;
        for (i = 0; i < total_number; i++) {
            output_info(llDetectedPos(i),llDetectedName(i));
        }
        state passive_target;
    }
 
    no_sensor() {
        llInstantMessage(llGetOwner(),"active_target --> Not found.");
        state passive_target;
    }
 
}
 
state passive_target {
 
    state_entry(){
        llInstantMessage(llGetOwner(),"< passive_target >");
        llSensor(target, NULL_KEY, PASSIVE, range, PI);
    }
 
    sensor(integer total_number) {
        integer i;
        for (i = 0; i < total_number; i++) {
            output_info(llDetectedPos(i),llDetectedName(i));
        }
        state scripted_target;
    }
 
    no_sensor() {
        llInstantMessage(llGetOwner(),"passive_target --> Not found.");
        state scripted_target;
    }
 
}
 
state scripted_target {
 
    state_entry(){
        llInstantMessage(llGetOwner(),"< scripted_target >");
        llSensor(target, NULL_KEY, SCRIPTED, range, PI);
    }
 
    sensor(integer total_number) {
        integer i;
        for (i = 0; i < total_number; i++) {
            output_info(llDetectedPos(i),llDetectedName(i));
        }
        llInstantMessage(llGetOwner(),"Searching complete.");
        state default;
    }
 
    no_sensor() {
        llInstantMessage(llGetOwner(),"scripted_target --> Not found.");
        llInstantMessage(llGetOwner(),"Searching complete.");
        state default;
    }
 
}