Simple Ship's Radar

From Lucinda Bullock via the scripting forum:

this is script to display above a prim your ships heading and any rocks or ships around you

it uses most of the llDetect functions that freak people

study it and see that they arnt as scary as they look

this is a ships compass that detects the closest thing and gives its relative position,heading and speed

the things you need for sailing:

 

list range = ; // list of radar ranges
list angle = ;//list of radar angles
list times = ;//list of radar times
list cp =;//list of headings and positions
integer rate = 0;
integer heading = -10;
integer target = -10;
integer targethead = -10;
key targetkey = NULL_KEY;
float targetvel;
integer targetdis;
integer targettype;
string sonarsound = "";//a radar ping sound to make it more real
string captian = "";

default
{
    state_entry()
    {
     list temp = llParseStringKeepNulls(llKey2Name(llGetOwner()),,);
     captian = "Captian "+llList2String(temp,1);//this just makes the captians name
     llSetTimerEvent(2);// short timer to do the first dispaly
    }

    timer()
    {
     llSetTimerEvent(0);//stop timer
     vector dir = <0.0, 1.0, 0.0> / llGetRot();//convert your rotation to a position vector
     string knots = llGetSubString((string)(llVecMag(llGetVel())*1.943846),0,3);//find your speed in knots
     heading = llRound(llAtan2(dir.x, dir.y) *llGetListLength(cp) / TWO_PI);//find you direction as far as compass points - it can be more
     string result = captian+"\nHeading:- "+llList2String(cp,heading)+"\nSpeed:- "+knots+" kts\n";//start making text string
     if(target != -10)// is there somthing near
      {
       string tknots = llGetSubString((string)(targetvel*1.943846),0,3);//yes get its speed
       result += llKey2Name(targetkey)+" "+(string)targetdis+"m to the "+llList2String(cp,target)+"\n";//print name and distance
       if((targettype == ACTIVE) && (targetvel >0.0)) result += "Ship heading:- "+llList2String(cp,targethead)+"\nSpeed:- "+tknots+" kts\n";//if a ship print its data
      }
     llSetText(result,<1 ,1,1>,1); //print the info above prim
     llSensor("","",ACTIVE|PASSIVE,llList2Float(range,rate),PI_BY_TWO*llList2Float(angle,rate));//start a new radar ping
    }
   sensor(integer tnum)
    {
    
     if(sonarsound != "")llPlaySound(sonarsound,1.0);//something in range sound ping
     vector pos = llGetPos();//get your position
     vector dpos = llDetectedPos(0);//get the targets pos
     vector tdir = <0.0, 1.0, 0.0> / llDetectedRot(0);//turn its rotation into a direction
     float diff = llVecDist(pos,dpos);//get the distance between you and the target
     target = llRound(llAtan2((dpos.y-pos.y)/diff,(dpos.x-pos.x)/diff) * llGetListLength(cp)/ TWO_PI);//work out the compass direction relative to you
     targetkey = llDetectedKey(0);//store the tagets key
     targetvel = llVecMag(llDetectedVel(0));//store the targets speed
     targetdis = llRound(diff);//store the targets distance
     targettype = llDetectedType(0);//get the target type rocks or ship
     targethead = llRound(llAtan2(tdir.x, tdir.y) * llGetListLength(cp)/ TWO_PI);// get the targets heading
     do{rate++;}//decrease range
     while((diff

 

Showing near avatars in a menu

//Touch and get near avatars in a dialog menu.
//By Kahiro Watanabe
//GPL share it!

//menu listener
integer listener;
integer sensorChannel;

// range and arc for the sensor
float range = 15.0;
float arc = PI;

list avatarsKeys;
list avatarsNames;

menu(key user,integer channel,string title,list buttons)
{
    listener = llListen(channel,"","","");
    llDialog(user,title,buttons,channel);
    //remove listener if there's no activity in menu
    llSetTimerEvent(20.0);
}

integer randomNumber()
{
    return (integer)(llFrand(99999.0) * -1);
}

default
{
    touch_start(integer total_number)
    {
        //only owner can access the menu
        if (llDetectedKey(0) == llGetOwner())
        {
            llSensor("","",AGENT,range,arc);
        }
    }
    sensor(integer total_number)
    {
        integer i;
        key tempId;
        avatarsKeys = [];
        avatarsNames = [];
        i = 0;
        while ((i  -1)
            {
                llSay(0,message + "'s key is " + llList2String(avatarsKeys,pos));
            }
        }
    }
    timer()
    {
        llListenRemove(listener);
        llSetTimerEvent(0.0);
    }
}

 

This simple script can be controlled only by owner, it will generate a list of near avatars and put it in a menu, when the user selects one it will show its key. You can do useful stuff like give an object or animate it, etc etc etc.

 

Aim Detection

This script detects who's aiming at you.

 

//This script was designed by Han Shuffle AKA MichaelRyan Allen AKA Dugley Reanimator
//Cleaned up a bit by another resident.
//Cleaned up some more by another resident.
 
default
{
    state_entry()
    {
        // black and transparent floattext
        llSetText("", ZERO_VECTOR, (float)FALSE);
 
        llSensorRepeat("", "", AGENT_BY_LEGACY_NAME, 90, PI, 0.1);
    }
 
    sensor(integer num_detected)
    {
        list output;
 
        integer i;
        do
        {
            key agentKey = llDetectedKey(i);
            string agentName = llDetectedName(i);
            vector agentPosition = llDetectedPos(i);
            rotation agentRotation = llDetectedRot(i);
            vector ownPosition = llGetPos();
 
            if (llGetAgentInfo(agentKey) & AGENT_MOUSELOOK)
            {
                if (llVecDist(ownPosition, agentPosition+llRot2Fwd(agentRotation)*llVecDist(ownPosition,agentPosition)) <1.5)
                    output += [agentName];
            }
        }
        while (++i < num_detected);
 
        llSetText(llDumpList2String(output, "\n"), <1.0, 1.0, 1.0>, (float)TRUE);
    }
}

 

Avatar Radar (NewAge)

NewAge Avatar Radar Project Version 1.2 No longer need to spend time making a hud, just copy and past script into a prim and click yes to allow script permission to attach to your UI, Set on Center 2.

 

/////////////////////////////////
// NewAge Radar Project Script
// By Asia Snowfall
// Version 1.2
/////////////////////////////////
// v1.2;
// ------
// (Added) HUD Maker Feature, When you save script, click Yes
// (Added) Power Feature, Turn Radar on and Off
// (Added) HUD Menu, Allowing you to control Power Feature, Change from Avatar Radar to Land Information and back again
// Easier to now Modify script varibles
/////////////////////////////////
// v1.1;
// ------
// (Added) - Agent Count in Region when no agents in sensor range
// (Added) - Lag Status when no agents in sensor range
/////////////////////////////////
// v1.0
// ------
// (Initial Release)
/////////////////////////////////
 
// Configure;
float scan_range = 100;
float speed = 2;
 
integer channel = 1;
integer menu_channel = 666;
integer show_total_agents_in_chat_range = TRUE;
integer show_total_agents_in_region = TRUE;
integer show_lag_status = TRUE;
integer max_people = 7;
integer parcel_description_max_characters = 50;
 
string menu_text = "***\nAvatar Radar Project\n***\nby Asia Snowfall";
string hud_texture = "ec122289-1239-74fd-708f-ab4b949b7cdb";
 
vector hud_size = <0.1,0.1,0.1>;
 
// Core Varibles;
 
// Integer Varibles
integer setting = FALSE;
integer handler;
integer radar_power = TRUE;
integer positioning;
integer positioning_handler;
integer scan_type = TRUE;
 
// String Varibles
string people;
string lag_status;
 
// List Varibles
list people_in_sensor_range;
list people_in_sensor_vectors;
list chat_range;
list hud_position;
list main_menu;
 
// Float Varibles
float position_by = 0.01;
 
// Vector Varibles
vector text_color;
 
// Premade Functions
 
asSetPosMenu() //Might wonder why i make the script empty the hud position and fill it again with same options, but it optimizes script memory! every little helps
{
    setting = TRUE;
    hud_position = [];
    llListenRemove(positioning_handler);
    @retry;
    positioning = llRound(llFrand(999999));
    if(positioning <= 2000)
    {
        jump retry;
    }
    positioning_handler = llListen(positioning, "", "", "");
    hud_position = ["-", "Down", "+", "Left", "===", "Right", "===", "Up", "Done"];
    llSetText("Setup the hud using position control\nClick Done when your finished", <1.0, 1.0, 1.0>, 1.0);
    llSetTimerEvent(30);
}
 
asSetMainMenu()
{
    main_menu = ["Avatars", "Land Info"];
    if(radar_power == FALSE)
    {
        main_menu += "Power On";
    }
    else
    {
        main_menu += "Power Off";
    }
}
 
llLagStatus()
{
    float time_dilation = llGetRegionTimeDilation();
    if(time_dilation <= 0.3)
    {
        lag_status = "Laggy";
        text_color = <1.0,0.0,0.0>;
    }
    else if(time_dilation > 0.3 && time_dilation <= 0.5)
    {
        lag_status = "Not Bad";
        text_color = <1.0,1.0,0.0>;
    }
    else if(time_dilation > 0.5 && time_dilation <= 0.8)
    {
        lag_status = "Good";
        text_color = <0.0,1.0,0.0>;
    }
    else if(time_dilation > 0.8 && time_dilation <= 1.0)
    {
        lag_status = "Excellent";
        text_color = <0.0,1.0,1.0>;
    }
}
 
all_status()
{
    if(show_total_agents_in_region == TRUE)
    {
        people += "Region Agent Count = "+(string)llGetRegionAgentCount()+"\n";
    }
    if(show_total_agents_in_chat_range == TRUE)
    {
        people += "Agents in Range = "+(string)llGetListLength(chat_range)+"\n";
    }
    if(show_lag_status == TRUE)
    {
        people += "Lag Status = "+lag_status;
    }
}
 
finish()
{
    llOwnerSay("Starting radar system\nClick HUD for Menu");
    setting = FALSE;
    llSetTimerEvent(speed);
    llListenRemove(positioning_handler);
}
 
 
default
{
    state_entry()
    {
        llListen(menu_channel, "", "", "");
        if(llGetAttached() != 0)
        {
            llSetScale(hud_size);
            llSetTexture(hud_texture, ALL_SIDES);
            handler = llListen(channel, "", "", "");
            llOwnerSay("Find location of avatar within sensor range by typing either their full or partial name on channel "+(string)channel + ", example; /"+(string)channel+" Mark");
            asSetPosMenu();
            llDialog(llGetOwner(), menu_text, hud_position, positioning);
        }
        else if(llGetAttached() == 0)
        {
            llSensor("", "", AGENT, scan_range, PI);
            setting = FALSE;
            llListenRemove(handler);
            llRequestPermissions(llGetOwner(), PERMISSION_ATTACH);
        }
    }
    touch_start(integer x)
    {
        if(llDetectedKey(0) == llGetOwner())
        {
            if(setting == FALSE)
            {
                if(llGetAttached() != 0)
                {
                    asSetMainMenu();
                    llDialog(llGetOwner(), menu_text, main_menu, menu_channel);
                }
                else
                {
                    llRequestPermissions(llGetOwner(), PERMISSION_ATTACH);
                }
            }
            else
            {
                llDialog(llGetOwner(), menu_text, hud_position, positioning);
            }
        }
    }
    run_time_permissions(integer perm)
    {
        if(perm & PERMISSION_ATTACH)
        {
            llAttachToAvatar(ATTACH_HUD_CENTER_2);
        }
        else
        {
            llOwnerSay("Some features disabled when not attached");
            llSetTimerEvent(speed);
        }
    }
    attach(key id)
    {
        llResetScript();
    }
    listen(integer chan, string name, key id, string str)
    {
        if(id == llGetOwner())
        {
            str = llToLower(str);
            if(chan == channel)
            {
                integer index = llListFindList(people_in_sensor_range, [str]);
                if(index != -1)
                {
                    llOwnerSay(llList2String(people_in_sensor_range, index)+" is located at "+llList2String(people_in_sensor_vectors, index));
                }
                else if(index == -1)
                {
                    integer i = 0;
                    integer length = llGetListLength(people_in_sensor_range);
                    integer ind;
                    do
                    {
                        if(llStringLength(llList2String(people_in_sensor_range, i)) > 0)
                        {
                            ind = llSubStringIndex(llList2String(people_in_sensor_range, i), str);
                            if(ind != -1)
                            {
                                llOwnerSay(llList2String(people_in_sensor_range, i) + " is located at "+llList2String(people_in_sensor_vectors, i));
                                return;
                            }
                        }
                    }while(i++, 1.0);
                }
            }
            else if(chan == positioning)
            {
                if(str == "+")
                {
                    if(position_by <0.1)
                    {
                        position_by += 0.01;
                    }
                    llOwnerSay("Positioning will move by "+(string)position_by+" meters");
                }
                else if(str == "-")
                {
                    if(position_by > 0.01)
                    {
                        position_by -= 0.01;
                    }
                    llOwnerSay("Positioning will move by "+(string)position_by+" meters");
                }
                else if(str == "down")
                {
                    llSetPos(llGetLocalPos()+<0.0,0.0,-position_by>*llGetRot());
                }
                else if(str == "left")
                {
                    llSetPos(llGetLocalPos()+<0.0,position_by,0.0>*llGetRot());
                }
                else if(str == "right")
                {
                    llSetPos(llGetLocalPos()+<0.0,-position_by,0.0>*llGetRot());
                }
                else if(str == "up")
                {
                    llSetPos(llGetLocalPos()+<0.0,0.0,position_by>*llGetRot());
                }
                else if(str == "done")
                {
                    finish();
                }
                if(setting == TRUE)
                {
                    llSetTimerEvent(30);
                    llDialog(llGetOwner(), menu_text, hud_position, positioning);
                }
            }
        }
    }
    on_rez(integer g)
    {
        if(g & CHANGED_OWNER)
        {
            llResetScript();
        }
    }
    changed(integer h)
    {
        if(h & CHANGED_OWNER)
        {
            llResetScript();
        }
    }
    sensor(integer x)
    {
        people_in_sensor_range = [];
        people_in_sensor_vectors = [];
        integer i = 0;
        integer index;
        --x;
        if(x > max_people)
        {
            x = max_people-1;
        }
        do
        {
            index = llListFindList(chat_range, [llDetectedName(i)]);
            if(llStringLength(llDetectedName(i)) >! 0)
            {
                if(llVecDist(llDetectedPos(i), llGetPos()) <= 20)
                {
                    if(index == -1)
                    {
                        chat_range += llDetectedName(i);
                        llOwnerSay(llDetectedName(i) + " has entered chat range");
                    }
                }
                else
                {
                    if(index != -1)
                    {
                        llOwnerSay(llDetectedName(i) + " has left chat range");
                        chat_range = llDeleteSubList(chat_range, index, index);
                    }
                }
                people_in_sensor_range += llToLower(llDetectedName(i));
                people_in_sensor_vectors += llDetectedPos(i);
                people += llDetectedName(i) + " - " + llGetSubString((string)llVecDist(llDetectedPos(i), llGetPos()), 0, 4)+"m\n";
            }
        }while(i++ 0)
            {
                people += "\nParcel Owner = "+llKey2Name((key)llList2String(details, 2));
            }
            else
            {
                people += "\nParcel Owner = Group Owned";
            }
            people += "\nParcel Area = "+llList2String(details, 3);
            people += "\nRegion FPS = "+(string)llGetRegionFPS();
            people += "\nRegion Time Dilation = "+(string)llGetRegionTimeDilation();
        }
        llSetText(people, text_color, 1.0);
        people = "";
    }
    no_sensor()
    {
        if(llGetListLength(chat_range) > 0)
        {
            chat_range = [];
        }
        people += "Region Agent Count = "+(string)llGetRegionAgentCount()+"\nAgents in Range = "+(string)llGetListLength(chat_range)+"\n";
        people = "No People In Range\n";
        llLagStatus();
        all_status();
        llSetText(people, text_color, 1.0);
        people = "";
    }
    timer()
    {
        if(setting == FALSE)
        {
            llSensor("", "", AGENT, scan_range, PI);
        }
        else
        {
            finish();
        }
    }
}

 

3D Radar

Rezzes a ball for each avatar in range. Each ball tracks it's on AV and displays distance.

 

Scanner/Rezzer Script

 

Place this script in a prim along with the scan ball. When touched it will scan the surrounding area and rezz a ball for each avatar.

 

Suggestion: Create a sphere with a diameter of 2 meters. Set transparency about 60. Create another sphere about 0.05 diameter, color a dark color and put it in the center of the large prim. Select small prim 1st and then large prim and link them. This will give you a center point to reference. The scan ball script is set to scan for it's avatar to a range of 96 meters.

 

This formula: vector avDivPos = (avPos - rPos) * 0.010417; Takes the (avatars position - position of scanner) & multiplies by (radius of the distance you want the balls to go(2 meter sphere = 1 meter radius)/scan range(96meters)):

 

1/96 = approximately 0.010417

 

//////////////////////////////////////////////////////////////////////////////////////////////////////
//				3D Radar 2.5
// 				"Oct 15 2008", "18:43:28"
// 				Creator: Jesse Barnett
//				Released into the Public Domain
//////////////////////////////////////////////////////////////////////////////////////////////////////
 
integer Scan = TRUE;
string avKey;
integer list_pos;
list key_list;
integer key_chan;	//Key channel is generated randomly and passed to the scan ball
integer die_chan = -9423753;	//Hey pick your own channels and be sure to paste them into
						//the scan balls too!
integer key_rem_chan = -49222879;
default {
	state_entry() {
		llSetObjectName("3D Radar");
	}
	touch_start(integer total_number) {
		if (Scan) {
			llSensorRepeat("", "", AGENT, 96, PI, 1);
			key_list =[];
			llListen(key_rem_chan, "", "", "");
			llOwnerSay("on");
			Scan = FALSE;
		}
		else {
			llSensorRemove();
			llRegionSay(die_chan, "die");
			llOwnerSay("off");
			Scan = TRUE;
		}
	}
	sensor(integer iNum) {
		integer p = 0;
		for (p = 0; p 

 

 

Scan Ball Script

 

Place this script in a prim and then place the prim into the inventory of the Scanner/Rezzer. It will automatically name itself.

 

Suggestion; Create a sphere prim of 0.05 diameter with glow set about .80.

 

//////////////////////////////////////////////////////////////////////////////////////////////////////
//				3D Radar 2.5
// 				"Oct 15 2008", "18:44:36"
// 				Creator: Jesse Barnett
//				Released into the Public Domain
//////////////////////////////////////////////////////////////////////////////////////////////////////
 
string avName;
integer avDistance;
key avKey;
integer avListen;
integer key_chan;
integer die_chan = -9423753;
integer key_rem_chan = -49222879;
vector avPos;
vector rPos;
default {
	state_entry() {
		llSetObjectName("scan ball");
	}
	on_rez(integer start_param) {
		rPos = llGetPos();
		key_chan = start_param;
		llListen(die_chan, "", "", "");
		avListen = llListen(key_chan, "", "", "");
	}
	listen(integer c, string n, key id, string msg) {
		if (c == die_chan)
			llDie();
		else {
			avKey = (key) msg;
			avName = llKey2Name(avKey);
			llSensorRepeat("", avKey, AGENT, 96, PI, 1.0);
			llListenRemove(avListen);
		}
	}
	sensor(integer n) {
		avPos = llDetectedPos(0);
		vector avDivPos = (avPos - rPos) / (96 / 1);	//Scan range/Radius of large sphere
		avDistance = (integer) llVecDist(rPos, llDetectedPos(0));
		llSetPos(rPos + avDivPos);
		llSetText(avName + "[" + (string) avDistance + "]", <1 , 1, 1 >, 1);
	}
	no_sensor() {
		llRegionSay(key_rem_chan, avKey);
		llDie();
	}
}