Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

sensor to move to random avs for set time?

exifyde Bacon
Registered User
Join date: 24 Jul 2005
Posts: 27
10-20-2005 20:30
Trying to make a prim move around and look at dif avs
i can make it move and stay in the area i want.
But i need a way to make it stay with an av for 10 sec then move to somone else at random
Anyone help?
sorry about the sloppy code im learning :p
CODE

vector here = <26.72094, 159.21555, 43.81749>;
vector offset =<3,0,1>;
string name = "null";
string detected_name;
vector stop;
startup()
{

vector pos = llGetPos();
llSetStatus(STATUS_ROTATE_Z,TRUE);
llSetStatus(STATUS_PHYSICS, TRUE);
llSetStatus(STATUS_PHANTOM, TRUE);
key id = llGetOwner();
llSensorRemove();
llMoveToTarget(here+offset*llDetectedRot(0),4);
//llSensor("", NULL_KEY, AGENT, 30, PI);
llSensorRepeat("","",AGENT,30,2*PI,.30);
llSetTimerEvent(30);
}
default
{
state_entry()
{

startup();

}

touch_start(integer total_number)
{
// llOwnerSay((string)llGetPos());
// llMoveToTarget(here+offset*llDetectedRot(0),4);

}
sensor(integer total_number)
{
vector stop = llGetPos();

//if( llDetectedName(0) != detected_name )
if( stop.y <= 129)
{
llSensorRemove();
llMoveToTarget(here+offset*llDetectedRot(0),3);
llOwnerSay("stoped y1");
}
if( stop.y >= 186)
{
llSensorRemove();
llMoveToTarget(here+offset*llDetectedRot(0),3);
llOwnerSay("stoped y2");
}
if( stop.x >= 57)
{
llSensorRemove();
llMoveToTarget(here+offset*llDetectedRot(0),3);
llOwnerSay("stoped x1");
}

if( stop.x <= 10)
{
llSensorRemove();
llMoveToTarget(here+offset*llDetectedRot(0),3);
llOwnerSay("stoped x2");
}
if( stop.z <= 35)
{
llSensorRemove();
llMoveToTarget(here+offset*llDetectedRot(0),3);
llOwnerSay("stoped z1");
}
if( stop.z >= 54)
{
llSensorRemove();
llMoveToTarget(here+offset*llDetectedRot(0),3);
llOwnerSay("stoped z2");
}
vector pos = llDetectedPos(0);

llMoveToTarget(pos+offset*llDetectedRot(0),4);
llLookAt(pos, .1 , 1);
string detected_name = llDetectedName(0);
//llSetText((string)detected_name,<1,0.5,0>,1);
//llSensor("", NULL_KEY, AGENT, 30, PI);


}


timer() {

//llSensor("", NULL_KEY, AGENT, 30, PI);
if( llGetPos() == <26.72094, 159.21555, 43.81749>)
{
llSensorRepeat("","",AGENT,30,2*PI,.30);
}



}}

_____________________
-------------------------------------------------
VGI Cleary
-------------------------------------------------
Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
10-20-2005 22:28
Here's what I would do:
Use the default state to sence for your target avatar. Save the av's key to a global variable, then switch to a following state. The following state would set a timer event to occur after 10 seconds and setup a sensor that repeats every second. In the following state's sensor event, llLookAt the avatar, once the timer event is execute, llSetTimerEvent(0) and switch back to the default state.

This seemed fun, so I cooked this up:
CODE

vector OFFSET = <3, 0, 1>;
float RANGE = 30;

key target;
default {
state_entry() {
llSensor("", NULL_KEY, AGENT, RANGE, TWO_PI);
}

sensor(integer det) {
target = llDetectedKey((integer)llFrand(det));
state following;
}
}

state following {
state_entry() {
llSensorRepeat("", target, AGENT, RANGE, TWO_PI, 1.0); // Update every second.
llSetTimerEvent(10); // Change avatars in 10 seconds.
llSetStatus(STATUS_PHYSICS, TRUE);
llMoveToTarget(llGetPos(), 0.2);
}

sensor(integer det) {
// Update to point at the avatar.
vector avPos = llDetectedPos(0);
llLookAt(avPos, 1, 1);
llMoveToTarget(avPos + OFFSET * llDetectedRot(0), 1.0);
}

no_sensor() {
// Out of range
state default;
}

timer() {
// Time to choose another avatar.
state default;
}

state_exit() {
llSetTimerEvent(0);
}
}



==Chris
_____________________
October 3rd is the Day Against DRM (Digital Restrictions Management), learn more at http://www.defectivebydesign.org/what_is_drm
exifyde Bacon
Registered User
Join date: 24 Jul 2005
Posts: 27
10-21-2005 09:27
ty that was just what i needed works now :)
_____________________
-------------------------------------------------
VGI Cleary
-------------------------------------------------