Jump to content

teleporter: teleport all avatars within range after given time


testgenord1
 Share

You are about to reply to a thread that has been inactive for 1516 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Hi again!
I have an area on my sim in which avatars are only supposed to remain for a certain limited time.

1. The avatars arriving are put on  a list.

2. Each avatar on that list is individually given the same time span to remain in that area
and then is teleported back to his / her starting point.

3. Once the avatar has been teleported,
the avatar has to be taken off that list
to make sure that should the avatar return to that area,
the same procedure will start again.

I have a script that roughly does this with one avatar, but not with multiple ones.

Do you maybe have an idea of how to adjust this script so that multiple avatars arriving in that area will be teleported after an equal time span?
Thank you very much in advance!

 

vector LandingPoint = <20,61,22>; // X,Y,Z landing point for avatar to arrive at
vector LookAt = <1,1,1>; // which way they look at when arriving//
integer seconds;
  
integer RESPONSE_CHANNEL = -100;
float   SCAN_RANGE       = 10.0;
float   SCAN_INTERVAL    = 2.0;
list    VISITOR_LIST;
key this_agent_key;
 
default
{
    state_entry()
    {
        llSensorRepeat("", NULL_KEY, AGENT_BY_LEGACY_NAME, SCAN_RANGE, PI, SCAN_INTERVAL);
    }
    sensor(integer number_detected)
    {
        integer agent_number;
  
//iterate through all detected agents
        for (; agent_number < number_detected; agent_number++)
        {
            string  this_agent_name = llDetectedName(agent_number);
            this_agent_key  = llDetectedKey(agent_number);
 
//if the agent is not found on the list
            if (llListFindList(VISITOR_LIST, [this_agent_name]) == -1)
            {
//add her/him and make the list hold the last 200 visitors
                VISITOR_LIST = [this_agent_name] + llList2List(VISITOR_LIST, 0, 198);
                llOwnerSay(this_agent_name);
                llSetTimerEvent(1.0);
            }
        }
    }
            timer()
            {
                ++seconds;
                if(seconds == 15)
                {
                    llInstantMessage(this_agent_key, "Your time is up.\n \n \nTeleporting you to ... ");
                    llTeleportAgent(this_agent_key, "", LandingPoint, LookAt);
                }
            }
}

 

 

Edited by testgenord1
Link to comment
Share on other sites

All you have to do is save the Unix time when you save the person's name, so you have a strided list:

VISITOR_LIST = [name, time, name, time, name, time, name, time, .... ]

Obviously, the ones at the start if the list are the oldest, so look at the first person on VISITOR_LIST.  If that person isn't in the area any more, delete him and his time from the list and go on to the next person...

When you finally get the first person who is still in the area, just have your timer compare llGetUnixTime with llList2Integer( VISITOR_LIST,1) + 15.  If llGetUnixTime() > llList2Integer( VISITOR_LIST,1) + 15, eject the person and remove him and his time from the list.  Move on till you get to the first non-ejectable person.  Then stop.  All the rest have been there for less than 15 seconds.

  • Like 1
Link to comment
Share on other sites

Thank you very much for your quick reply.
I tried to implement your suggestions and ended up using an older script of yours as a help, which I found here:

So it seems to be going in the right direction.
The teleporter starts after the given time, and it works on multiple avatars.
There is probably still a lot of room for improvements, so feel free to comment further.
I might come back for more detailed questions on this later.

For now, thank you very much, again!

float   SCAN_RANGE       = 20.0;
float   SCAN_INTERVAL    = 90.0;

string  dest = "you_region";
vector  land = <20.0,61.0,22.0>;
vector  look = <1.0, 1.0, 1.0>;
key id;
list gVisitors;  // Save Visitor UUIDs
list gVtime;  // Save visit times
integer seconds;

default
{
    state_entry()
    {
        llSetTimerEvent(180.0); // Start a 180 seconds garbage collector
        llSensorRepeat("", NULL_KEY, AGENT_BY_LEGACY_NAME, SCAN_RANGE, PI, SCAN_INTERVAL);
    }
        sensor(integer number_detected)
        {
            id = llDetectedKey(0);
            integer temp = llListFindList(gVisitors,[id]);
            if(~temp)  //Has the Av visited before?
            {
                //Subtract saved Unix time from current Unix time. Was it it > 90 seconds ago?
                if((llGetUnixTime() - llList2Integer(gVtime,temp)) > 90)
                {   // If yes .....
                    gVisitors = llDeleteSubList(gVisitors,temp,temp); //Remove Av from visitor list
                    gVtime = llDeleteSubList(gVtime,temp,temp);  // Remove Av's visit time too
                    llInstantMessage(id, "Teleporting you to : "+ dest);
                    osTeleportAgent(id, dest, land, look);
                }
            }
            else  //No previous visit
            {
                llRegionSayTo(id,0,"You will be teleported back in  90 seconds.");
                gVisitors += [id]; // Add to the Visitor list
                gVtime += [llGetUnixTime()];  // Add current Unix time to the time list
            }             
        }
        
        timer() //Every 180 seconds ...
        {
                integer i;
                for (i=((gVisitors !=[])-1);i>=0;--i) //Look through all the saved visitor times
                {  // For each one ...
                    if((llGetUnixTime() - llList2Integer(gVtime,i))> 180) // If it was more than 270 seconds ago ...
                    {
                        gVisitors = llDeleteSubList(gVisitors,i,i); // Remove the person from the Visitor list
                        gVtime = llDeleteSubList(gVtime,i,i); //Remove the visit time from the list
                    }
                }
         }
                        
}

 

Edited by testgenord1
adjusted the garbage collector.
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1516 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...