Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Radar controller

Huns Valen
Don't PM me here.
Join date: 3 May 2003
Posts: 2,749
08-19-2003 03:35
Want a radar dish that can report avatars in the area? I did, so I built a radar and scripted it. This isn't exactly the most awesome source code I've ever written (it was the first thing I'd done that was more complex than a lightbulb) but it works. Feel free to mess around with it, use it in your projects, etc., but if you make any improvements I would ask that you post them here.

There are two types of controls, 'radarctl' and 'scanctl'. radarctl controls spin rate, and scanctl controls reporting. See the notecard (below) for full info.


CODE

// Radar controller by Huns Valen
// Please give me credit if you use this. Thanks!

float scanWeather = 0.1;
float scanAirTraffic = 1;
float scanTactical = 5;
integer notify = 1;
integer interval = 60;
integer range = 96;
string radarID="";
key id;
float rotSpeed;

default
{
state_entry()
{
// Figure out who owns me and listen to them
llListen(0,"",llGetOwner(),"");

// Set up initial rotation
rotSpeed = scanAirTraffic;
llTargetOmega(<0,0,1>, rotSpeed, 2);

// Turn on sensor
if(notify==1)
llSensorRepeat("","",AGENT,range,PI,interval);
}

// Give instructions note card
touch_start(integer total_number)
{
llGiveInventory(llDetectedKey(0), "Radar Dish Controls");
}

// Handle sensor events (if turned on)
sensor(integer n) {
integer i;
string preamble;
vector pos;
vector me = llGetPos();
integer dist;
integer t = (integer)llGetTimeOfDay();
string dt =
(string)((t/3600)%24)
+":"
+(string)((t%3600)/60)
+":"
+(string)(t%60);
string iSee = " ";
for(i=0; i<n; i++) {
pos = llDetectedPos(i);
dist = (integer)llVecDist(me, pos);
iSee += " ["+llDetectedName(i)+" @ "+(string)dist+"M] ";
}
if(radarID!="")
preamble="["+radarID+"] : ";
else
preamble = "";
llInstantMessage(llGetOwner(), preamble+iSee);
}

// Listen for instructions
listen(integer channel, string name, key id, string message) {
float magnitude = 2;
rotSpeed = -1;
list cmd = llParseString2List(message, [" "], []);
string auth = llList2String(cmd, 0);

if (id != llGetOwner()) {
string op = llToUpper(llList2String(cmd, 0));
llSay(0, op+" NAK: Control by non-owners is forbidden.");
return;
}

// Handle 'factory'
if(auth=="factory") {
llSay(0, "FACTORY ACK: Resetting.");
llResetScript();
// notify = 1;
// interval = 60;
// range = 96;
// radarID="";
// rotSpeed = scanAirTraffic;
// llTargetOmega(<0,0,1>, rotSpeed, 2);
// llSensorRemove();
// llSensorRepeat("","",AGENT,range,PI,interval);
}

// Handle 'scanctl x y'
if(auth=="scanctl") {
integer scanset=0;
string scan = llList2String(cmd, 1);
if(scan=="on") {
llSensorRemove();
llSensorRepeat("","",AGENT,range,PI,interval);
scan="Enable scanner";
scanset=1;
}
if(scan=="off") {
llSensorRemove();
scan="Disable scanner";
scanset=1;
}
if(scan=="interval") {
interval = llList2Integer(cmd, 2);
scan="Set interval "+(string)interval+" and enable scanner";
llSensorRemove();
llSensorRepeat("","",AGENT,range,PI,interval);
scanset=1;
}
if(scan=="range") {
range = llList2Integer(cmd, 2);
scan="Set range "+(string)range+" and enable scanner";
llSensorRemove();
llSensorRepeat("","",AGENT,range,PI,interval);
scanset=1;
}
if(scan=="name") {
radarID = llList2String(cmd, 2);
scan="Set name '"+radarID+"'";
scanset=1;
}
if(scanset!=1) {
llSay(0, "SCANCTL: Try 'on', 'off', 'name xyz', 'interval x' (seconds), or 'range x' (0-96).");
} else {
llSay(0, "SCANCTL ACK: ["+scan+"]");
}
}

// Handle 'radarctl x y z'
if(auth=="radarctl") {
string speed = llList2String(cmd, 1);
if(speed=="Weather")
rotSpeed = scanWeather;
if(speed=="AirTraffic")
rotSpeed = scanAirTraffic;
if(speed=="Tactical")
rotSpeed = scanTactical;
if(speed=="stop")
rotSpeed = 0;
if(speed=="speed") {
rotSpeed = llList2Float(cmd, 2);
speed = "Set speed "+(string)rotSpeed;
}
if(rotSpeed == -1) {
llSay(0, "RADARCTL: Try 'Weather', 'AirTraffic', 'Tactical', 'stop', or 'speed n.nn'.");
}
if(rotSpeed >= 0) {
llSay(0, "RADARCTL ACK: ["+speed+"]");
if(rotSpeed==0)
magnitude = 0;
llTargetOmega(<0,0,1>, rotSpeed, magnitude);
}
}
}
}


Notecard:
CODE
/*
Huns Valen's Radar Dish
--------------------------
This radar dish responds to owner voice commands. Non-
owners will get a NAK (negative acknowledgement) if they
attempt any of these commands.

Its two primary features are that it rotates (like a real
scanning radar) and that it can report the names and
distances of any avatar within 96 meters, even across
simulator boundaries. Rotation speed can be adjusted or
turned off, and scanning can be set to any range (0-96M) or
turned off.

After you have installed your dish for the first time, be sure
to use the 'factory' command. This will clear out any settings
that may have carried over from the display unit you bought
your dish from.


Usage
--------------------------
factory
Resets the radar to default factory settings.
(Notify on, range 96, interval 60, radarctl AirTraffic)


radarctl [preset | speed x.xx]
Sets rotational speed of the unit.
preset Weather
AirTraffic
Tactical
stop

speed A decimal number from 0 to about 7
(higher speeds tend to get choppy)

scanctl [on | off | interval x]
Controls avatar reporting feature.
on
off
name A name to identify the radar.
Useful for when you have more than one!
interval An integer number of seconds.
range An integer number of meters to scan,
up to 96.


Examples
--------------------------
radarctl Weather
radarctl Tactical
radarctl stop
radarctl speed 4.7
scanctl name Rooftop (must be 1 word)
scanctl off
scanctl interval 60 (report back once per minute)
scanctl range 32
scanctl on



***NOTE***
--------------------------
Due to a bug that presently exists in the SecondLife
implementation, you may not see the dish change speeds, or
even start to begin with, without clicking it. This is because
the client is not seeing that llTargetOmega() was called.

Fortunately, this is fixed when your client re-rezzes the object
(i.e. you go a couple simulators over and then return). For
some reason, stopping always seems to work. (I did try
stopping the dish every time a 'radarctl' is caught, but it
never seems to pick up the bit where I tell it to start rotating
again.)
*/
Sydney Alexander
Registered User
Join date: 19 Feb 2005
Posts: 69
12-17-2005 00:59
I am looking for a radar that will allow me to have it llOwnerSay or llInstantMessage this info but also offer a llSetText above the radar... I have seenthem before and I can get one to set, but can't parse the string properly... early morning. Aslo would be nice to the the 3D Dynamically rezzed prims...

SO three options, all or any combo: chat|2D text|3D text & object If I can find a script that does the 2D I think I can cobble it together.

thanks,

sydney
Sydney Alexander
Registered User
Join date: 19 Feb 2005
Posts: 69
12-17-2005 01:16
I am looking for a radar that will allow me to have it llOwnerSay or llInstantMessage this info but also offer a llSetText above the radar... I have seenthem before and I can get one to set, but can't parse the string properly... early morning. Aslo would be nice to the the 3D Dynamically rezzed prims...

SO three options, all or any combo: chat|2D text|3D text & object If I can find a script that does the 2D I think I can cobble it together.

thanks,

sydney
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Discussion Thread
12-19-2005 20:21
/54/20/78431/1.html
_____________________
i've got nothing. ;)