Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Get optimal parcel pos for sensor

Ezian Ecksol
Unregistered User
Join date: 25 Dec 2007
Posts: 82
06-24-2008 06:03
// Get optimal parcel position for sensor at ground.
// (c) Ezian Ecksol. Use, modify, steal or sale as you like. Keep credits.

float detect_range = 96.;

string getparcelname(vector p) {
return llList2String(llGetParcelDetails(p, [PARCEL_DETAILS_NAME]),0);
}

string Float2String(float num) {
list s = llParseString2List((string)(llRound(num*10.)/10.), ["."], []);
return llList2String(s, 0)+"."+llGetSubString(llList2String(s, 1), 0, 0);
}

string Vector2String(vector v) {
return "<"+Float2String(v.x)+", "+Float2String(v.y)+", "+Float2String(v.z)+">";
}

getparcelbounds() {
vector pos = llGetPos();
vector rpos;
pos = <llRound(pos.x), llRound(pos.y), 0.>;
string name = getparcelname(pos);
vector parcel0; vector parcel1;
vector parcel_center; vector parcel_size;

rpos = pos;
do { rpos.x -= 1.; } while (getparcelname(rpos) == name);
parcel0.x = rpos.x + 1.;

rpos = pos;
do { rpos.y -= 1.; } while (getparcelname(rpos) == name);
parcel0.y = rpos.y + 1.;

rpos = pos;
do { rpos.x += 1.; } while (getparcelname(rpos) == name);
parcel1.x = rpos.x;

rpos = pos;
do { rpos.y += 1.; } while (getparcelname(rpos) == name);
parcel1.y = rpos.y;

parcel_center = (parcel1 + parcel0) / 2.;
parcel_size = parcel1 - parcel0;
float c = llPow(parcel_size.x/2.,2.)+llPow(parcel_size.y/2.,2.);
float d = detect_range*detect_range;
if (c > d)
llOwnerSay("Your parcel is to large to be covered by a "+Float2String(detect_range)+"-m-scanner. Place the detector in the middle of the parcel at ground, but the corners are not covered.";);
else {
vector dest = <parcel_center.x, parcel_center.y, llGround(parcel_center-llGetPos())+llSqrt(d-c)>;
llOwnerSay("For optimal scanning range at ground, set position of sensor object to: "+Vector2String(dest));
}
}


default {
state_entry() {
getparcelbounds();
}
}
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
06-24-2008 08:31
This looks good!
I will grab a copy and try it out later.
Thank you so much
_____________________
From Studio Dora
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
06-24-2008 08:49
Cool script!

Couple comments..

Land has a 4m resolution - you can't make a parcel smaller than 4m x 4m. You can get a big speed boost on this script by using -= 4.0 and += 4.0 as it walks through the region.

Using llGetLandOwnerAt might be a little more efficient - it just returns a key and you won't have to muck around with doing list operations every time. Downside is that multiple parcels with the same owner will appear to be the 'same' parcel but you also get some of that with your version if different parcels have the same name. Actually, you should probably call llGetLandOwnerAt either way, just in case a neighbor parcel has the same name but a different owner.
_____________________
Tired of shouting clubs and lucky chairs? Vote for llParcelSay!!!
- Go here: http://jira.secondlife.com/browse/SVC-1224
- If you see "if you were logged in.." on the left, click it and log in
- Click the "Vote for it" link on the left
Mallory Triellis
Registered User
Join date: 23 Jun 2008
Posts: 1
06-24-2008 09:31
Parcel names do not need to be unique.

Had this come up in a Estate management tool I have, one tenant had several parcels in the same sim, with the same name.
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
06-24-2008 10:15
Yeah. Ideally they'd implement a function that returns some kind of UUID for a parcel or something. Actually just returning the upper-left coordinates of the most upper-left 4m square in the whole parcel would be enough to test whether two positions are in the same one. Hopefully LL will implement something like that eventually. Might be worth fussing around in JIRA to find/suggest that, but maybe someone with more optimism than I have can give it a shot. LOL.
Krista Chaffe
Registered User
Join date: 16 Jun 2007
Posts: 96
06-24-2008 21:07
lol, yeah we could hope