Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Scan, then rez an object to follow an avatar

PhoenixRene Ashbourne
Script Novice
Join date: 19 Feb 2008
Posts: 9
08-07-2008 15:37
I have a question about altering a script so that instead of "poking" a person in chat after completing a scan the script will rezz an object that will go to the Scanned avatar and follow them. If you can give me any help, I would really appreciate it.


Here is the Scanning Script I was looking at:

integer dlgHandle = -1;
integer dlgChannel = -9999;
list avatarList = [];
reset()
{
llSetTimerEvent(0.0);
llListenRemove(dlgHandle);
dlgHandle = -1;
}
default
{
touch_start(integer total_number)
{
llOwnerSay("Scanning...";);
avatarList = [];
// Look for any avatars within 10m.
llSensor("", NULL_KEY, AGENT, 96.0, PI);
}
sensor(integer num_detected)
{
integer i;
while((i < num_detected) && (i < 9))
{
if (llDetectedKey(i) != llGetOwner())
{
avatarList += [llDetectedName(i)];
}
++i;
}
if (llGetListLength(avatarList) > 0)
{
state dialog;
}
}
}
state dialog
{
state_entry()
{
// Set up a listener to detect button clicks.
dlgHandle = llListen(dlgChannel, "", llGetOwner(), "";);

// Start a new timer.
llSetTimerEvent(30.0);

// Add a 'Cancel' button.
avatarList += ["Cancel"];

// Display the dialog.
llDialog(llGetOwner(), "Please select an avatar.", avatarList, dlgChannel);
}
listen(integer channel, string name, key id, string message)
{
// The message parameter holds the caption of the
// button that was clicked. Search the menu options
// list for it.
if ((channel == dlgChannel) && (llListFindList(avatarList, [message]) != -1))
{
if (message != "Cancel";)
{
llSay(0, llKey2Name(llGetOwner()) + " pokes " + message);
}
reset();
state default;
}
}
timer()
{
reset();
state default;
}
}
Kaluura Boa
Polygon Project
Join date: 27 Mar 2007
Posts: 194
08-07-2008 23:36
I think nobody answered because it has the potential to turn into a griefing tool. I will just provide some (exhaustive) advices.

First, your current script is looking for troubles. Collecting avatars' names and putting them directly on buttons is bad, very bad. Your script will scream to the ears of every serious scripter that hasn't the debug channel switch off if there are more than 11 avies or if any name is longer than 24 letters. So...

avatarList += [llGetSubString(llDetectedName(i), 0, 23)];

And later...

if (llGetListLength(avatarList) > 11)
{
avatarList = llList2List(avatarList, 0, 10);
}
avatarList += ["Cancel"];

Now your little problem...

Since the script may cut some avatar's name, let's consider they are lost and collect keys too.

avatarList += [llGetSubString(llDetectedName(i), 0, 23)];
avatarKeyList += [llDetectedKey(i)];

Then in your listen() event:

if (message != "Cancel";)
{
Index = llListFindList(avatarList, [message]); // Index must be GLOBAL
llRezObject("follower", llGetRootPosition(), ZERO_VECTOR, ZERO_ROTATION, 42);
}

And create a new event:

object_rez(key id)
{
llSleep(0.4); // To give time to the follower to rez.
llWhisper(-123456, llList2String(avatarKeyList, Index));
reset();
state default;
}

Everything is said... Your follower just need to listen to the right channel on rez and it will receive a key usable with llGetObjectDetails(). No need to start a sensor, use a timer.

One little detail: Disable the listen() event once the follower got the key or each already rezzed follower will follow the last selected AV.

Do not forget to check in the listen() event of your follower that the message comes from an object with the same owner... in case somebody else also uses the same channel.

if (llGetOwnerKey(id) == llGetOwner())
{
// Action!
}

Use only a temporary and phantom follower so that, in case of problem, it ultimately dies and it won't bump into yourself or anybody else. Besides, even if ppl find your follower annoying, they shouldn't call you a griefer if it dies quickly enough.

Now, you're on your own... The Abuse Reports will mention your name, not mine. :-D
PhoenixRene Ashbourne
Script Novice
Join date: 19 Feb 2008
Posts: 9
08-07-2008 23:54
Thanks, I appreciate your help. I was actually wanting to use it like the Vector Interceptor from Outy Banjo. Just to make sure though, I intend to make all the prims temporary, and the particles in that prim are not going to be excessive either. I know that there are many targeting particles and such that you can use chat to type in the target, and I could use those, but I wanted everything to be done by the HUD. Thanks again.