The following script shows the use of a rotation scan. I'm not really sure if everything goes right with the rotation. I think there is still a bug in it, so that not the full area is scanned. This have to verified first.
------------------------------------------------------------------------------------------------------------------------------------------------
//Script (c)2007 by Thomas
//do whatever you want with this script but leave a greeting to my person ;o)
integer scanMode = 0;
integer scanWhatGlobal;
integer scanRangeGlobal;
string searchedName = "";
float lastRadius = PI;
key searchedID = NULL_KEY;
integer scanCount = 0;
integer searchedCount = 0;
list listKeys;
list listPos;
list listTypes;
RotateObject(integer rotX, integer rotY, integer rotZ)
{
vector euler = <rotX, rotY, rotZ>;
euler *= DEG_TO_RAD;
euler += llRot2Euler(llGetRot());
llSetRot(llEuler2Rot(euler));
}
StartScan(key id, string name, integer scanWhat, integer scanRange, float scanRadius)
{
integer whatToScan;
if (scanWhat == 1)
{
whatToScan = (AGENT);
}
else if (scanWhat == 2)
{
whatToScan = (ACTIVE);
}
else
{
whatToScan = (AGENT | ACTIVE);
}
llSensor(name, id, whatToScan, scanRange, scanRadius);
}
Init_State()
{
listKeys = [];
listPos = [];
listTypes = [];
scanCount = 0;
searchedCount = 0;
}
integer SearchNameInList(string name)
{
integer i;
integer index = -1;
for(i = 0; i < searchedCount; i++)
{
if (llSubStringIndex(llToUpper(llKey2Name(llList2Key(listKeys, i))), llToUpper(name)) == 0)
{
if (index > -1)
{
llMessageLinked(LINK_THIS, 0, "Found more than one name for your search!", NULL_KEY);
llMessageLinked(LINK_THIS, 0, "Name: " + llKey2Name(llList2Key(listKeys, index)) + " (" + (string)llList2Key(listKeys, index) + ")", NULL_KEY);
llMessageLinked(LINK_THIS, 0, "Name: " + llKey2Name(llList2Key(listKeys, i)) + " (" + (string)llList2Key(listKeys, i) + ")", NULL_KEY);
index = -2;
}
else if (index == -2)
{
llMessageLinked(LINK_THIS, 0, "Name: " + llKey2Name(llList2Key(listKeys, i)) + " (" + (string)llList2Key(listKeys, i) + ")", NULL_KEY);
}
else
{
index = i;
}
}
}
return index;
}
ResetThisScript()
{
llResetScript();
}
DoWork()
{
//Add the work code with the userlists here
ResetThisScript();
}
DoScanRotation()
{
if (lastRadius == PI_BY_TWO)
{
if (scanCount == 0)
{
RotateObject(0, 180, 0);
scanCount += 1;
StartScan(searchedID, "", scanWhatGlobal, scanRangeGlobal, lastRadius);
}
else if (scanCount == 1)
{
RotateObject(0, 180, 0);
scanCount += 1;
DoWork();
}
}
else if (lastRadius == (PI_BY_TWO / 2))
{
if (scanCount < 3)
{
RotateObject(0, 90, 0);
scanCount += 1;
StartScan(searchedID, "", scanWhatGlobal, scanRangeGlobal, lastRadius);
}
else if (scanCount == 3)
{
RotateObject(90, 0, 0);
scanCount += 1;
StartScan(searchedID, "", scanWhatGlobal, scanRangeGlobal, lastRadius);
}
else if (scanCount == 4)
{
RotateObject(180, 0, 0);
scanCount += 1;
StartScan(searchedID, "", scanWhatGlobal, scanRangeGlobal, lastRadius);
}
else if (scanCount == 5)
{
RotateObject(0, 0, 90);
scanCount += 1;
DoWork();
}
}
else if (lastRadius == PI)
{
DoWork();
}
}
default
{
state_entry()
{
Init_State();
}
link_message(integer senderNumber , integer number, string message, key id)
{
//this script is controlled by linked messages
//the number have to be 4 to start scan
//the message string have to contain some stuff and looks like "2;0;96;Thomas"
//means 2 = scanmode in my case ... used this in my DoWork function
//means 0 = what to scan ... look in the StartScan function to understand the values
//means 96 = scanrange of 96 metres
//means Thomas = name or part of the name to search for
//if id is not NULL_KEY then it ignore the name part (last paramter in the message string) and search directly for this ID
//sample call llMessageLinked(LINK_THIS, 4, "2;" + scanWhat + ";" + scanRange + ";" + llGetSubString(message, 6 + llStringLength(botName), -1), NULL_KEY);
if (number == 4)
{
Init_State();
integer c = llSubStringIndex(message, ";");
scanMode = (integer)llGetSubString(message, 0, c - 1);
message = llGetSubString(message, c + 1, -1);
c = llSubStringIndex(message, ";");
scanWhatGlobal = (integer)llGetSubString(message, 0, c - 1);
message = llGetSubString(message, c + 1, -1);
c = llSubStringIndex(message, ";");
scanRangeGlobal = (integer)llGetSubString(message, 0, c - 1);
searchedName = llGetSubString(message, c + 1, -1);
lastRadius = PI;
searchedID = id;
if (scanRangeGlobal == 0) scanRangeGlobal = 96;
StartScan(searchedID, "", scanWhatGlobal, scanRangeGlobal, lastRadius);
}
else if (number == 99)
{
llResetScript();
}
}
on_rez(integer reset)
{
llResetScript();
}
sensor(integer totalNumber)
{
//if 16 results are found then it could be that there are more than 16 but SL only give 16 back
//so lower the scan radius to catch more. the lowering of the radius will go only down to PI / 4
if ((totalNumber == 16) && (lastRadius > (PI_BY_TWO / 2)))
{
if (lastRadius > PI_BY_TWO)
{
lastRadius = PI_BY_TWO;
}
else if (lastRadius > (PI_BY_TWO / 2))
{
lastRadius = PI_BY_TWO / 2;
}
Init_State();
StartScan(searchedID, "", scanWhatGlobal, scanRangeGlobal, lastRadius);
}
else
{
//the scanradius cant be lowered more and/or there are less than 16 results
//start collecting the results in lists
key foundKey;
list searchForList;
integer i;
for(i = 0; i < totalNumber; i++)
{
foundKey = llDetectedKey(i);
searchForList = [foundKey];
if (llListFindList(listKeys, searchForList) == -1)
{
listKeys = (listKeys = []) + listKeys + foundKey;
listTypes = (listTypes = []) + listTypes + llDetectedType(i);
listPos = (listPos = []) + listPos + llDetectedPos(i);
searchedCount += 1;
}
}
//does the needed rotation when the scanradius is lower than PI
DoScanRotation();
}
}
no_sensor()
{
DoScanRotation();
}
}
-------------------------------------------------------------------------------------------------------------------------------------
Page Information
|
Wiki Information |
Recent PBwiki Blog Posts |