I recently had to split the script into two parts, because one single script cannot store all of the information for all approximately 185 public sims with the limited memory we have.
These scripts work by receiving a Linked Message from some other script in the form of a World Coordinate vector or a string representing the name of a sim. It will then return back the sim name or World Coordinate, respectively.
Script #1
============
CODE
//Region Database Script
//by Hank Ramos
//June 22, 2004
list Regions;
integer RegionLineCount;
integer NotifyCount;
key RegionReadKey;
disp(string m)
{
//Send Message to Display on Overhead Text display
llMessageLinked(LINK_SET, 411, m, NULL_KEY);
}
getRegionName(vector RegionCorner)
{
string ResultString;
vector sim_corner = (RegionCorner / 256) - <1000,1000,0>;
integer XValue = (integer)sim_corner.x;
integer YValue = (integer)sim_corner.y;
//Send coordinates to Coord Script for processing
llMessageLinked(llGetLinkNumber(), 649500, (string)XValue + "," + (string)YValue, NULL_KEY);
}
getRegionVector(string name)
{
integer ListIndex = llListFindList(Regions, [name]);
if (ListIndex >= 0)
{
//Send position of region name in list to other script
llMessageLinked(llGetLinkNumber(), 649000, (string)ListIndex, NULL_KEY);
}
else
{
disp("Region " + name + " not found in database.");
}
}
default
{
state_entry()
{
disp("Loading Regions...");
Regions = [];
RegionLineCount = 0;
llResetOtherScript("Region Coords Script");
RegionReadKey = llGetNotecardLine("Regions", 0);
}
link_message(integer sn, integer n, string m, key id)
{
string tempString;
vector tempVector;
list tempList;
m = llToLower(m);
if (n == 100)
{
//Convert Name to Vector
getRegionVector(m);
return;
}
if (n == 101)
{
//Convert Vector to Name
getRegionName((vector)m);
return;
}
if (n == 102)
{
//Retrieve region name of current sim.
getRegionName(llGetRegionCorner());
return;
}
if (n == 649001)
{
//Coordinates coming back
tempList = llCSV2List(m);
tempVector = <llList2Float(tempList,0),llList2Float(tempList,1),0>;
tempVector = (tempVector + <1000,1000,0>)* 256;
//Send region coordinates back to requestor
llMessageLinked(llGetLinkNumber(), 200, (string)tempVector, NULL_KEY);
}
if (n == 649501)
{
//Index of Region Name in list coming back
tempString = llList2String(Regions, (integer)m);
//Send region name back to requestor
llMessageLinked(llGetLinkNumber(), 201, tempString, NULL_KEY);
}
if (n == 999)
{
llResetScript();
}
if (n == 95562)
{
if ((m == "reset regions")||(m == "reset notecards"))
{
llResetScript();
}
}
}
dataserver(key requested, string data)
{
//Process Regions
if (requested == RegionReadKey)
{
list L = llCSV2List(data);
if (data != EOF)
{
if ((llSubStringIndex(data, "#") != 0) && (llGetListLength(L) == 3))
{
Regions += [llToLower(llList2String(L, 0))];
//Send Region Coordinates to other script (due to memory limitations with so many sims)
llMessageLinked(llGetLinkNumber(), 648000, llList2String(L, 1) + "," + llList2String(L, 2), NULL_KEY);
}
RegionLineCount += 1;
NotifyCount += 1;
if (NotifyCount > 10)
{
disp((string)llGetListLength(Regions) + " Regions Loaded");
NotifyCount = 0;
}
RegionReadKey = llGetNotecardLine("Regions", RegionLineCount);
}
else
{
llMessageLinked(0, 102, "", NULL_KEY);
disp("Region Load Complete. Total " + (string)llGetListLength(Regions) + " Regions Loaded");
llMessageLinked(LINK_SET, 203, (string)llGetListLength(Regions), NULL_KEY);
}
L = [];
}
}
}
============
Script #2
This script was added to provide more storage space in
memory. It only keeps a parallel script with the world coordinates
of each simulator.
============
CODE
//Region Database Coords Script
//by Hank Ramos
//June 22, 2004
list RegionCoords;
disp(string m)
{
llMessageLinked(LINK_SET, 411, m, NULL_KEY);
}
default
{
state_entry()
{
RegionCoords = [];
}
link_message(integer sn, integer n, string m, key id)
{
if (n == 648000)
{
//Add region coords to list
RegionCoords += m;
return;
}
if (n == 649000)
{
//Send back region coordinates for requested list index.
llMessageLinked(llGetLinkNumber(), 649001, llList2String(RegionCoords, (integer)m), NULL_KEY);
return;
}
if (n == 649500)
{
//Find region coordinates in list, and pass back list index
integer ListIndex = llListFindList(RegionCoords,[m]);
if (ListIndex >= 0)
{
llMessageLinked(llGetLinkNumber(), 649501, (string)ListIndex, NULL_KEY);
};
}
}
}
============
The notecard with the sim locations is an attachment to the next message.