Jump to content
Sign in to follow this  
Kennethh Yamdev

llSetRegionPos()

Recommended Posts

Greetings.  I am having a hard time figuring out how to use llSetRegionPos() in my script. Maybe there is a better way to go about this. But I have it where you click the object and llDialog() menu shows up with names of avatars with in range. I want to set it up so that when the name is clicked the object goes to that persons position. But I cannot figure out what I am doing wrong. The script below I had some help writing and im not pro. I am learning and would say I am a moderate scripter. 

Any tips of help would be great. :)

 

 

//menu listener
integer listener;
integer sensorChannel;
// range and arc for the sensor
float range = 40.0;
float arc = PI;

integer i;
list avatarsKeys;
list avatarsNames;
menu(key user,integer channel,string title,list buttons)
{
listener = llListen(channel,"","","");
llDialog(user,title,buttons,channel);
//remove listener if there's no activity in menu
llSetTimerEvent(20.0);
}
integer randomNumber()
{
return (integer)(llFrand(99999.0) * -1);
}
default
{
on_rez(integer somettgh)
{
llSensor("","",AGENT,range,arc);
}
touch_start(integer total_number)
{
//only owner can access the menu
if (llDetectedKey(0) == llGetOwner())
{
llSensor("","",AGENT,range,arc);
}
}
sensor(integer total_number)
{
integer i;
key tempId;
avatarsKeys = [];
avatarsNames = [];
i = 0;
while ((i < total_number) && (i < 12))
{
tempId = llDetectedKey(i);
avatarsKeys = avatarsKeys + tempId;
avatarsNames = avatarsNames + llKey2Name(tempId);
i = i+1;
}
sensorChannel = randomNumber();
menu(llGetOwner(),sensorChannel,"Select an avatar ",avatarsNames);
}
listen(integer channel,string name,key id,string message)
{
if (channel == sensorChannel)
{
integer pos = llListFindList(avatarsNames,[message]);
if (pos > -1)
{
//When person choice is made. Move object to choice
llOwnerSay((string) message + " is youre choice.");
//  llSetRegionPos(); //Need to find out who/where
}
}
}
}

Share this post


Link to post
Share on other sites

you need to set the position by getting the key of the avatar chosen,

and getting their object details... and define llSetRgionPos as an integer?

kinda like so?....

 

//menu listenerinteger listener;integer sensorChannel;// range and arc for the sensorfloat range = 40.0;float arc = PI;integer i;list avatarsKeys;list avatarsNames;menu(key user,integer channel,string title,list buttons){    listener = llListen(channel,"","","");    llDialog(user,title,buttons,channel);    //remove listener if there's no activity in menu    llSetTimerEvent(20.0);}integer randomNumber(){    return (integer)(llFrand(99999.0) * -1);}integer moved;    // llSetRegionPos is an integer.default{    on_rez(integer somettgh)    {    llSensor("","",AGENT,range,arc);    }        touch_start(integer total_number)    {         //only owner can access the menu        if (llDetectedKey(0) == llGetOwner())        {        llSensor("","",AGENT,range,arc);        }    }        sensor(integer total_number)    {    integer i;    key tempId;    avatarsKeys = [];    avatarsNames = [];    i = 0;        while ((i < total_number) && (i < 12))        {        tempId = llDetectedKey(i);        avatarsKeys = avatarsKeys + tempId;        avatarsNames = avatarsNames + llKey2Name(tempId);        i = i+1;        }    sensorChannel = randomNumber();    menu(llGetOwner(),sensorChannel,"Select an avatar ",avatarsNames);    }            listen(integer channel,string name,key id,string message)    {        if (channel == sensorChannel)        {           integer index = llListFindList(avatarsNames,[message]);           if (index > -1)           {            //When person choice is made. Move object to choice           // the names & keys should share the same index since they are added simultaneously
key chosenKey = llList2Key(avatarsKeys,index); list details = llGetObjectDetails(chosenKey, ([ OBJECT_POS]) ); vector movePos = llList2Vector(details,0); llOwnerSay((string) message + " is youre choice."); moved = llSetRegionPos(movePos); //you can OwnerSay an error if moved == 0 } } }}

  you can also use MoveToTarget for this ... http://wiki.secondlife.com/wiki/LlMoveToTarget

  • Like 1

Share this post


Link to post
Share on other sites

Ah that works perfect. I had thought that the same key and name I got for llDialog would have worked but I did not think to set another integer.
and I see you mentioned llMoveToTarget - That could work too, Ill slide that in there and see what I think. Probably get the same results but hey, it helps practice.

Share this post


Link to post
Share on other sites

Kennethh Yamdev wrote:

Ah that works perfect. I had thought that the same key and name I got for llDialog would have worked but I did not think to set another integer.

 Just to clarify, llSetRegionPos() requires a vector as an argument and returns an integer -- either TRUE (1) or FALSE (0)  -- depending on whether the function succedes in moving the object to the target position.  

You can, if you wish, say something like

		if(llSetRegionPos(movePos){ //if I have successfully moved to movePos.			//do something		}		else {//Oops! movePos is not an accessible destination for some reason.			//do some error handling		}

 but  it's not compulsory.   

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...