Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Follower Script Question

Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
04-10-2008 20:00
I am, for my own amusement, creating something that rezzes a ghost when people visit part of my sim, and the ghost then follows them about for a minute.

Everything is working reasonably as I want it to, except that the ghost, when rezzed, is remarkably fickle. That is, if the avi it's haunting comes too close to another avi, it is very likely to start following the second avi. How, please, do I change the code so it sticks to the first avi it finds?




default {
on_rez(integer start_param) {
llResetScript();

llSensor("", NULL_KEY, AGENT, 10, PI);






}
state_entry()
{
vector pos = llGetPos();
llSetStatus(STATUS_ROTATE_X | STATUS_ROTATE_Y, FALSE);
llSetStatus(STATUS_PHYSICS, TRUE);
llSleep(0.1);
llMoveToTarget(pos,0.1);
llSetTimerEvent(60.0);



llSensorRepeat("",NULL_KEY,AGENT,10, PI,1);





}

sensor(integer detected)
{
vector pos = llDetectedPos(0);

vector offset =<-1,0,0>;
pos+=offset;
llMoveToTarget(pos,.3);


}
timer() {
llDie();
}
}
Soen Eber
Registered User
Join date: 3 Aug 2006
Posts: 428
04-10-2008 20:59
Declare a key variable at the top of the script (before the state declaration - it gives it global scope). You then have to have some "if" logic - if the variable is null grab the first detected key like you already are, otherwise loop through the detected keys until you find the one that matches your key variable. If its not found, the guy has teleported away is otherwise out of range, so you can then either latch onto anyone else in range, or else have the script die.
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
04-10-2008 21:42
I'd actually stop the sensor once an avatar is decided upon and start using llGetObjectDetails() with a timer instead. If you know the key you are looking for, it's both more convenient and likely much less costly in terms of sim resources (read: less laggy).
Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
04-11-2008 09:32
i kind of like the idea of the ghost haunting other people, too. Who knows what makes sense to a ghost.
_____________________
So many monkeys, so little Shakespeare.