Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Converting spoken name to key / targeting

Archaegeo Platini
Ancient Earth University
Join date: 12 Aug 2004
Posts: 152
08-17-2004 09:34
Ive looked lots of places now, but I must be missing it....

Targeting..

Could someone post an example of how to target another AV via spoken command and via one AV targeting another, I must be missing it.

I know the sensor function will get folks around an object, but say i want to have the player say "Hug Fred", how do i convert that into fred's av so i can make the player walk over and hug fred, etc.

Or what if i wanted to have the av just click on the target av and the object do something...

Any links/help?
Siobhan Taylor
Nemesis
Join date: 13 Aug 2003
Posts: 5,476
08-17-2004 10:28
Something like this...

CODE


string targetname; // the name you're targetting

sensor(integer total_number) {
integer i;
for (i=0;i<=total_number;i++) {
if (llDetectedName(i) == targetname) {
key targetKey = llDetectedKey(i);
// do target stuff
}
}
}

_____________________
http://siobhantaylor.wordpress.com/
Archaegeo Platini
Ancient Earth University
Join date: 12 Aug 2004
Posts: 152
08-17-2004 10:35
So with sensor, its a 10m limit.

Anyone to click on your target to make it in the code?
Siobhan Taylor
Nemesis
Join date: 13 Aug 2003
Posts: 5,476
08-17-2004 10:39
sensor range is up to 96m
_____________________
http://siobhantaylor.wordpress.com/
Jeffrey Gomez
Cubed™
Join date: 11 Jun 2004
Posts: 3,522
08-17-2004 17:18
From: someone
Originally posted by Archaegeo Platini
Any way to click on your target and make it in the code? (Jeff edit: Grammar Nazi)

I've already requested a command for that - something like llTouchTarget, etc - in another thread or two. It'd be nice, but t'ain't happening just yet.

Just for giggles, I'm going to make this into a multiple missile script - while I don't normally do guns, I just find the prospect of this amusing. Bear with me. :D

CODE

list targetList = [];
string sayIt;

detault
{
state_entry()
{
llListen(0,"",llGetOwner(),"");
}
listen(integer chan, string name, key id, string msg)
{
if(llSubStringIndex(msg,"target") != -1)
{
llSensor("","",AGENT.96.0,TWO_PI);
string takeNames = "";
integer j;
if(llGetListLength(targetList) == 1)
takeNames = llKey2Name(llList2Key(targetList, 0);
for(j=0;j<llGetListLength(targetList);j++)
{
if(j != llGetListLength(targetList))
takeNames += llKey2Name(llList2Key(targetList, i) + ", ";
else takeNames += "and " + llKey2Name(llList2Key(targetList, i);
}
if(takeNames == "") llSay(0,"No targets selected.");
else llSay(0,"Avatars " + takeNames + " selected. Commencing program.");
//<<< Do stuff here.
}
}
sensor(integer total_number)
{
integer i;
targetList = [];
for(i=0;i<total_number;i++)
{
if(llSubStringIndex(sayIt,llDetectedName(i)) != -1)
targetList += llDetectedKey(i);
}
}


So what was all that gibberish? When you say "target" followed by one or many avatar names, the script will target all valid avatar names you said and return their keys in a list by seeing if they're nearby and match the names you said. A little much? It's basically just a start to a "smart" target script - but will I code you a gun too?

Not a chance. :D
Bosozoku Kato
insurrectionist midget
Join date: 16 Jun 2003
Posts: 452
08-18-2004 07:28
Don't forget "total_number" is NOT zero index based, but llSensor() IS zero index based.

I always convert the num to a zero index..
CODE

default
{
state_entry()
{
llSensor(....);
}

sensor(integer num)
{
num -= 1; // convert num to zero index based so you
// don't miss ZERO, or go over the max num in your checks.
// sensor returns up to 16 "hits", 0 to 15.
}


Boso

p.s.
Jeff's for statement is correct, but the original for (forget who wrote it) is incorrect (checks "i <= total_number" .. which would check "16" when "15" is the actual max).