Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

LLDialog, sensor and LLDetectedPos

Aime Takaaki
Registered User
Join date: 23 Feb 2008
Posts: 3
06-25-2009 14:24
Hi! Please be kind with me, since my english is not too good, but ill do my best :)
im new in script, but i want to learn..
i want to make a script that detected the avs within range and gets their positions.
so far, collecting some scripts posted here. i made this.. but all i can do is to get my own position and say it in channel 0, but i would like to be able to choose any avs that the dialog shows.. and says HIS/HER position.
can anyone help me to figure it out?

so here is the script:


integer chan=-6547;//channel that we listen for the object touching on
key toucher;
integer targetID;
integer target_id;





//llDialog Stuff
integer menuchannel;//The channel needed for dropdown boxes
//Random number stuff for menu channel
integer lower=-90000;// we use minus channels so only objects can "hear"
integer higher=-10000;//Also we use a range so to prevent cross-talk
integer RandInt;//Our Random number placeholder
integer listener;//Place holder for the listen function

string menuText = "Select your target:";
list avatarsDetected = [ ];
list keysDetected = [ ];

list av_positions = [];
integer i;
useKey(key targetKey)
{


}



default
{
state_entry()
{
llListen(chan,"",NULL_KEY,"";);
}

listen(integer channel, string name, key id, string msg)
{
if (channel==chan)
{
toucher = (key)msg;
state dialog;
}
}
}

state dialog
{
state_entry()
{
//Random number stuff
integer range = higher - lower;
integer result = llFloor(llFrand(range - 0)) + lower;
RandInt= result;
//Prevents cross talk if you have multiple items
menuchannel=RandInt;


listener=llListen(menuchannel,"",NULL_KEY,"";);
llSensor("", NULL_KEY, AGENT, 100, PI);

}

listen(integer channel, string name, key id, string msg)
{
llListenRemove(listener);//remove listener
integer listPos = llListFindList(avatarsDetected, (list)msg);
useKey(llList2Key(keysDetected, listPos));




vector av_pos = llList2Vector(av_positions,i);
llSay(0, msg + "is located at " + (string)av_pos );


state default;
}
sensor(integer numDetected)


{


if (numDetected > 12) numDetected = 12;
integer nextStep;
string nextAvatarName;
string nextAvatarKey;
av_positions = [ ];
avatarsDetected = [ ];
keysDetected = [ ];

for (nextStep = 0; nextStep < numDetected; nextStep++)
{
nextAvatarName = llDetectedName(nextStep);
av_positions += llDetectedPos(i);
nextAvatarKey = llDetectedKey(nextStep);
nextAvatarName = llGetSubString(nextAvatarName, 0, 23);
avatarsDetected = avatarsDetected + nextAvatarName;
keysDetected = keysDetected + nextAvatarKey;

}
llDialog(toucher,menuText,avatarsDetected, menuchannel);}
}



****i call the dialog menu through another prim :)
Ron Khondji
Entirely unlike.
Join date: 6 Jan 2007
Posts: 224
06-25-2009 22:20
Change this:
av_positions += llDetectedPos(i);

to:
av_positions += llDetectedPos(nextStep);


'nextStep' is the counter in the for/next loop, not 'i'.
Aime Takaaki
Registered User
Join date: 23 Feb 2008
Posts: 3
06-26-2009 11:58
thank u ron.. i changed that bit, but still, no other position but mine detected :(
Ron Khondji
Entirely unlike.
Join date: 6 Jan 2007
Posts: 224
06-27-2009 06:55
Another little mistake you made is:

integer listPos = llListFindList(avatarsDetected, (list)msg);

to find the 'name you clicked' position in the avatarsDetected list. So far so good.
But then you want to find the av's position in the sim with:

vector av_pos = llList2Vector(av_positions, i);

This i should be the earlier found list position listPos.

You do not need integer i at all as far as I can tell.
Aime Takaaki
Registered User
Join date: 23 Feb 2008
Posts: 3
06-28-2009 12:01
thank you ron! it works now :) !!!!