Simple Ship's Radar

Written by Kitsune

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