Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Trying to get a prim to stay on my parcel

spinster Voom
Registered User
Join date: 14 Jun 2007
Posts: 1,069
03-18-2009 05:26
I am trying to make a prim move around randomly on the surface of the water on my land parcel. If it wanders off my parcel or if its height changes (indicating it has come out of the water and is climbing the land) it should move back to its previous position but it is not doing so - it happily wanders off into a neighbouring parcel. I don't know whether it makes a difference but the land parcel is on the edge of a sim.

Can anybody see what I am doing wrong?

vector currentPos;
float correct_zpos;
string my_parcel;

//random number function
float random(float min, float max){
return llFrand(max - min) + min;
}

default{
state_entry(){
//find out where it is
currentPos = llGetPos();
//find out the height
correct_zpos = currentPos.z;
//find out the name of the parcel
list this_parcel = llGetParcelDetails(currentPos, [PARCEL_DETAILS_NAME]);
my_parcel = (string)this_parcel;

llSetTimerEvent(0.5);

}


timer(){
//find out where it is before it moves
currentPos=llGetPos();

//change x and y positions by a small random amount
float random_x = random(-0.1,0.1);
float random_y = random(-0.1,0.1);
llSetPos(llGetPos() + <random_x, random_y, 0>;);

//find out where it is after it's moved
vector new_pos = llGetPos();

//find out its height
float new_zpos = new_pos.z;

//find out the name of the parcel it's on now
list lstParcelName=llGetParcelDetails(new_pos,[PARCEL_DETAILS_NAME]);
string this_parcel_name = (string)lstParcelName;
llSay(0, this_parcel_name);

//THIS IS WHERE IT GOES WRONG. IT SAYS this_parcel_name IS THE SAME AS THE PARCEL IT STARTED ON, EVEN WHEN IT HAS CROSSED ONTO ANOTHER PARCEL. IT NEVER RUNS THE IF BIT BELOW

//if it's on the wrong parcel or if its height has changed go back to where it was
if ((this_parcel_name != my_parcel)||(new_zpos!=correct_zpos)){
llSay(0, "oops!";);
llSetPos(currentPos);
}
}

}
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
03-18-2009 07:03
I had a similar situation once. I had to test for SIM border crossing:
if ( newpos.x < 0.0 || newpos.x >= 256.0 || newpos.y < 0.0 || newpos.y >= 256.0 )...;

Furthermore:
You should test the new position before moving to it;)
It might be no build, no entry or a full parcel
_____________________
From Studio Dora
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
03-18-2009 09:22
you might also want to check out llOverMyLand
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
spinster Voom
Registered User
Join date: 14 Jun 2007
Posts: 1,069
03-19-2009 03:30
Thanks for the tips, ladies, I'll try them out later today.
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
03-20-2009 07:51
From: Dora Gustafson
I had a similar situation once. I had to test for SIM border crossing:
if ( newpos.x < 0.0 || newpos.x >= 256.0 || newpos.y < 0.0 || newpos.y >= 256.0 )...;

Furthermore:
You should test the new position before moving to it;)
It might be no build, no entry or a full parcel


so you (or the object checking) doesn't actually have to be on the spot to test the flags? i've never worked with llGetParcelFlags. it says it's an integer, so how does it check for multiple flags? and does it check it against the perms of the avatar and/or the owner of the object checking, or just whatever flags the owner has set regardless of who's checking?
_____________________
Dark Heart Emporium

http://www.xstreetsl.com/modules.php?name=Marketplace&MerchantID=133020

want more layers for tattoos, specifically for the head? vote here
http://jira.secondlife.com/browse/VWR-1449?

llDetectedCollision* Functions similar to touch
http://jira.secondlife.com/browse/SVC-3369
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
03-20-2009 08:45
From: Ruthven Willenov
so you (or the object checking) doesn't actually have to be on the spot to test the flags?
My findings only suggest that it should be on the same SIM
_____________________
From Studio Dora
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
03-20-2009 10:03
From: Dora Gustafson
My findings only suggest that it should be on the same SIM

right, that's what i meant. i have a pet i bought somewhere else that sends out sensor orbs to make sure it's not gonna run into anything. it got too close to the parcel edge and i was getting messages about it not being allowed to enter. it was the sl debug message, not something programmed into the script. i was just wondering if the scripter could have added the parcel flag check to the sensor orb script so the owner wouldn't get bombarded with messages about it not being allowed to enter the parcel
_____________________
Dark Heart Emporium

http://www.xstreetsl.com/modules.php?name=Marketplace&MerchantID=133020

want more layers for tattoos, specifically for the head? vote here
http://jira.secondlife.com/browse/VWR-1449?

llDetectedCollision* Functions similar to touch
http://jira.secondlife.com/browse/SVC-3369
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
03-20-2009 10:15
From: Ruthven Willenov
i was just wondering if the scripter could have added the parcel flag check to the sensor orb script so the owner wouldn't get bombarded with messages about it not being allowed to enter the parcel
That was what I did, But the position has to be checked before the object takes it! If it is not on the parcel the animal must go somewhere else. And the Sim borders must be checked separately as I mentioned: if ( newpos.x < 0.0 || newpos.x >= 256.0 || newpos.y < 0.0 || newpos.y >= 256.0 ) "point is not on SIM";
_____________________
From Studio Dora
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
03-20-2009 10:34
Note that if you cross into a new sim, the old position recorded will now be relative to the NEW region's origin. For example (I know you move shorter distances than this, but for simplicity...) let's say you start at <250.0, 128.0, 20.0> on YourRegion and move 10m East into OtherRegion. Your new position would be <4.0, 128.0, 20.0> in OtherRegion, and your logic would correctly deduce that you are on another parcel (assuming the two parcels don't have the same name). So you would try to move back to <250.0, 128.0, 20.0>. But this would be close to the Eastern border of OtherRegion, not YourRegion! So to truly move back to your starting point, you would really have to detect the change in sim and use <-6.0, 128.0, 20.0> instead to move back to YourRegion. All in all it is better to test the new potential position before moving, as Dora suggested.
spinster Voom
Registered User
Join date: 14 Jun 2007
Posts: 1,069
03-21-2009 05:08
From: Hewee Zetkin
Note that if you cross into a new sim, the old position recorded will now be relative to the NEW region's origin. For example (I know you move shorter distances than this, but for simplicity...) let's say you start at <250.0, 128.0, 20.0> on YourRegion and move 10m East into OtherRegion. Your new position would be <4.0, 128.0, 20.0> in OtherRegion, and your logic would correctly deduce that you are on another parcel (assuming the two parcels don't have the same name). So you would try to move back to <250.0, 128.0, 20.0>. But this would be close to the Eastern border of OtherRegion, not YourRegion! So to truly move back to your starting point, you would really have to detect the change in sim and use <-6.0, 128.0, 20.0> instead to move back to YourRegion. All in all it is better to test the new potential position before moving, as Dora suggested.


Well, that would make sense, wouldn't it? What happened when my prim went over the sim border was that it registered the y coordinate as a minus number and said it was still on the same parcel. It didn't try to move to the previous coordinates on OtherRegion as it didn't try to move back where it was at all.

Oh well, Dora's method works fine, I have just used that for all four parcel boundaries and not bothered with llGetParcelDetails at all. It's just annoying that if I wanted to use it on another parcel I'd have to find and code in the coordinates of the parcel boundaries again. I haven't tried OverMyLand yet - that might work fine for what I want (although it's group land so I don't know), but it would be no good for somebody who wanted to keep it on one parcel of sub-divided land.
Jim Gustafson
Registered User
Join date: 6 Feb 2007
Posts: 84
03-21-2009 05:16
check out llGetRegionCorner() that should help in finding out if it's still on the same sim.

Jim
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
03-21-2009 06:04
From: spinster Voom
Oh well, Dora's method works fine, I have just used that for all four parcel boundaries and not bothered with llGetParcelDetails at all. It's just annoying that if I wanted to use it on another parcel I'd have to find and code in the coordinates of the parcel boundaries again.
llGetParcelDetails works fine together with the condition I submitted earlier in this thread.
There is no need to make conditions for each and every single parcel;) Here are some snippets from a working script:
CODE
list playland; // a list with parcel owner and and parcel group keys at the parcel where the object is rezzed

mover( vector newpos )
{
if ( newpos.x < 0.0 || newpos.x >= 256.0 || newpos.y < 0.0 || newpos.y >= 256.0 ) return;
if ( 0==(llListFindList( playland, llGetParcelDetails( newpos, [PARCEL_DETAILS_OWNER, PARCEL_DETAILS_GROUP]))) )
llSetPos( newpos);
}

default
{
state_entry()
{
playland = llGetParcelDetails( llGetPos(), [PARCEL_DETAILS_OWNER, PARCEL_DETAILS_GROUP]);
}
...
// call mover with the vector position you want to move to
...
on_rez(integer param)
{
llResetScript();
}
}

From: spinster Voom
I haven't tried OverMyLand yet - that might work fine for what I want (although it's group land so I don't know), but it would be no good for somebody who wanted to keep it on one parcel of sub-divided land.
llOverMyLand is no good! when it reports you are NOT over your land the object has already crossed the parcel border:(
_____________________
From Studio Dora