Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

How Do I Tweak This Sensor Script Please

Mako Davidson
Registered User
Join date: 27 Jun 2006
Posts: 56
06-26-2007 03:43
Here is an example of a sensor script I found that returns the sensed avatars names as a Dialog menu. What I'm wanting to do is say a message in open chat or another channel containing the name of the selected avatar. eg if the sensor returnes the names Jack and Jill in the Dialog menu and i press Jack, a message is said using that name. ie Goodmorning (Jack) in open chat or on another channel. Does anyone know how to do this please???

CODE

integer channel = -10;
string menuText = "Select your target:";
list avatarsDetected = [ ];
list keysDetected = [ ];

useKey(key targetKey)
{
// This is where you "do something" with that key. I dunno whatYOU plan to do with it
// in my demo in world, I passed it to a particle beam. There's some issues with that
// since the particle target range seems to be the client's draw distance.
// but if you wanted to rez a follower, or whatever, you'd do that here.
}

default
{
state_entry()
{
llListen(channel, "", llGetOwner(), "");
}

listen(integer channel, string name, key id, string message)
{
integer listPos = llListFindList(avatarsDetected, (list)message);
useKey(llList2Key(keysDetected, listPos));
}

touch_start(integer duration)
{
llSensor("", NULL_KEY, AGENT, 100, PI);
}

sensor(integer numDetected)
{
if (numDetected > 12) numDetected = 12;
integer nextStep;
string nextAvatarName;
string nextAvatarKey;
avatarsDetected = [ ];
keysDetected = [ ];
for (nextStep = 0; nextStep < numDetected; nextStep++)
{
nextAvatarName = llDetectedName(nextStep);
nextAvatarKey = llDetectedKey(nextStep);
if (llStringLength(nextAvatarName) > 24) nextAvatarName = llGetSubString(nextAvatarName, 0, 23);
avatarsDetected = (avatarsDetected=[]) + avatarsDetected + nextAvatarName;
keysDetected = (keysDetected=[]) + keysDetected + nextAvatarKey;
}
llDialog(llGetOwner(), menuText, avatarsDetected, channel);
}
}
Simnelia Petrichor
Registered User
Join date: 10 Feb 2006
Posts: 35
06-26-2007 04:34
Add a line to the listen event so it reads like this:

listen(integer channel, string name, key id, string message)
{
integer listPos = llListFindList(avatarsDetected, (list)message);
useKey(llList2Key(keysDetected, listPos));
llSay(0, "Good morning " + message);
}
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
06-26-2007 07:48
From: Simnelia Petrichor
llSay(0, "Good morning " + message);
I suspect, rather, "... + name...". ;)

One might also get fancy and extract the first name, using llSubStringIndex(name, " ";) to find the space character, and llGetSubString() from 0 to that index.
Milambus Oh
Registered User
Join date: 6 Apr 2007
Posts: 224
06-26-2007 08:14
No, you want message.

In the listen event, name refers to the name of the person the script is listening to... which is the person to used the Dialog. message is the text from the button on the llDialog, which is the names of the people in the area.
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
06-26-2007 08:21
From: Milambus Oh
No, you want message.
Oh, quite right. I actually looked for an llDialog() or anything else that might make that listen() event be something other than somebody talking, but didn't see it in our forum's current "blank verse" formatting. Sorry for the bum steer.
Mako Davidson
Registered User
Join date: 27 Jun 2006
Posts: 56
thanks guys
06-26-2007 08:43
thanks guys, anyone ever tell you that you rock??? Well ya do and if anyone has anything different to say, send them my way :)
Markus Lewsey
Registered User
Join date: 14 Aug 2007
Posts: 4
Could it say the UUID?
09-21-2007 16:32
I'm fairly new to scripting and doing what a lot of folks do to learn I think by tweaking existing scripts.

I've found to repurpose this script to have it say the Agent Key instead of the name.
Can this be done?

Thanks for the help, Oh Gurus of LSL.
Markus Lewsey
Registered User
Join date: 14 Aug 2007
Posts: 4
Well that was quick..
09-21-2007 20:50
Thanks folks, I answered my own question...
I adjusted this portion of the script:

listen(integer channel, string name, key id, string message)
{
integer listPos = llListFindList(avatarsDetected, (list)message);
useKey(llList2Key(keysDetected, listPos));
llSay(0,"The uuid for "+message+" is:";);
llSay(0, (string)llList2Key(keysDetected,listPos));
}

Teach a man to fish and he eats forever. :)