Change font size
It is currently Thu Sep 24, 2020 5:20 pm

Forum rules


{L_IMAGE}



Post a new topicPost a reply Page 1 of 1   [ 5 posts ]
Author Message
 Post subject: restrict access to building
PostPosted: Wed Mar 04, 2020 6:52 pm 
Furious Typer

Joined: Mon Feb 13, 2017 1:53 pm
Posts: 98
Hi again!
I've got a script that is supposed to limit the access to a building to a certain number of avatars,
to for example 2 at the same time.

Should a 3rd avatar access the parcel and get close to the scripted building (here 10 m),
he / she should be teleported back to a central starting point.


The problem now is that sometimes only one of the avatars is teleported back.
Or, more often, after teleporting, the script does not repeat the process
when the same avatar enters the building a second time.

I don't understand where the problem lies.
Maybe you can help me out?

Here is the script:
Thank you very much in advance!
{L_CODE}:
string Destination = "my_region";
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//

list avatarsInRegion;
integer numOfAvatars;

key kbouncer;
list lbouncerpos;
vector vbouncerpos;

integer seconds;
key id;

list lavpos;
vector vavpos;
float fvectordistance;

default
{
    state_entry()
    {
        kbouncer = llGetKey();
        vbouncerpos = llGetPos();
        llSetTimerEvent(1.0);
    }
            timer()
            {
                ++seconds;
                if(seconds % 30 == 0)
                {
                    integer i;
                    for(i=0; i < numOfAvatars; ++i);
                    {
                        avatarsInRegion = llGetAgentList(AGENT_LIST_PARCEL, []);
                        numOfAvatars = llGetListLength(avatarsInRegion);
                        llOwnerSay((string)numOfAvatars);
                        id = llList2Key(avatarsInRegion,i);
                        lavpos = llGetObjectDetails(id,[OBJECT_POS]);
                        vavpos = llList2Vector(lavpos,0);
                        fvectordistance = llVecDist(vbouncerpos, vavpos);
                        //llOwnerSay(,(string)fvectordistance);
                        if (numOfAvatars >2)
                        {
                            if(fvectordistance < 10)
                            {
                                llRegionSayTo(id,0,"Sorry, the building is full.\n \n \nTeleporting you back ...");
                                llTeleportAgent(id,Destination,LandingPoint,LookAt);
                                avatarsInRegion = llDeleteSubList(avatarsInRegion,i,i); // Remove the person from the Visitor list
                                //llResetScript();
                            }
                        }
                    }
                }
                if(seconds % 180 == 0)
                {
                    avatarsInRegion = llDeleteSubList(avatarsInRegion,0,10); // Remove the person from the Visitor list
                    //llResetScript();
                }
            }
}


Top
 Profile  
 
 Post subject: Re: restrict access to building
PostPosted: Wed Mar 04, 2020 9:52 pm 
Furious Typer
User avatar

Joined: Fri Mar 26, 2010 12:11 pm
Posts: 298
Location: Belgium / Brussels
Hello, as usual, there are several ways to do this ...
Here is a working example using volume detection.
{L_CODE}:
// Resticted Aera v0.1 by djphil (CC_BY-NC-SA 4.0)

vector detination = <128.0, 128.0, 25.0>;
list blacklist = ["UUID", "UUID", "UUID"];

default
{
    state_entry()
    {
        llOwnerSay("initialisation ...");
        llSetAlpha(0.5, ALL_SIDES);
        llVolumeDetect(TRUE);
    }

    collision_start(integer n)
    {
        integer i;

        for (i = 0; i < n; ++i)
        {
            key user = llDetectedKey(i);

            if (~llListFindList(blacklist, [user]))
            {
                llRegionSayTo(user, PUBLIC_CHANNEL, "Sorry " + osKey2Name(user) + ", restricted area ...");
                osTeleportAgent(user, detination, ZERO_VECTOR);
            }
        }
    }

    on_rez(integer n)
    {
        llResetScript();
    }
}

Usage : Place the prim where you want to limit access.
Resize the prim if necessary to encompass the area you want to limit.
If an avatar in the "blacklist" collides with the prim or if it is inside the prim, it will then be teleported to "destination".

Enjoy! :)

_________________
Webmaster @ digitalconcepts.free.fr & digigrids.free.fr


Top
 Profile  
 
 Post subject: Re: restrict access to building
PostPosted: Thu Mar 05, 2020 2:06 pm 
Furious Typer

Joined: Mon Feb 13, 2017 1:53 pm
Posts: 98
Hi!
Thank you so much for your quick reply and your script.
It gave me a new idea for my own.
It was not exactly what I meant.
I was looking for a script that allows entry only when a certain maximum number of people is not inside the house yet.
Has the maximum number been reached inside the house, new visitors should be teleported.

However, your script using the collision_start gave me a new idea and eventually I may have been successful.
I'm posting the script below.
There might still be lots of opportunities for improvement so feel free to comment.

Thank you very much again!
{L_CODE}:
string Destination = "your_region";
vector LandingPoint = <77,154,22>; // X,Y,Z landing point for avatar to arrive at
vector LookAt = <1,1,1>; // which way they look at when arriving//

list avatarsInRegion;
integer numOfAvatars;

key id;
string name;

list newkeys;
integer listpos;
integer arrivaltime;

integer seconds;
integer time = 180;

default
{
    state_entry()
    {
        avatarsInRegion = llGetAgentList(AGENT_LIST_PARCEL, []);
        numOfAvatars = llGetListLength(avatarsInRegion);
        llVolumeDetect(TRUE);
    }
    collision_start(integer n)
    {
        llSetTimerEvent(1.0);
        id = llDetectedKey(0);
        name = llKey2Name(id);
        llRegionSayTo(id,0, "Welcome " + name + "!\n \nYou have 3 minutest time.\n \nThen you will be teleported back.");
        if(llListFindList(newkeys,id) == -1)
        {
            arrivaltime = llGetUnixTime();
            integer i;
            for(i=0; i < numOfAvatars; ++i);
            {
                //llShout(0,"key: " + (string)id);
                newkeys += [arrivaltime,id]; // add Unix Time and key to the list; Unix Time first position, key second position
                newkeys = llListSort(newkeys, 2, TRUE);     //  sort strided list by ascending arrivaltime (arrivaltime used because it comes before key [arrivaltime,id]); TRUE means ascending order
                listpos = llListFindList(newkeys,id); // search for key in list
                if(listpos > 7) // if the key is in the 8th onwards position, its agent will be teleported; this means user 5 onwards, because position 8 is in stride 5 (= user 5) (0,1; 2,3; 4,5; 6,7; 8,9 ...)
                {
                    llRegionSayTo(id,0,"Sorry, the task is full.\n \n \nYou are teleported back.");
                    osTeleportAgent(id,Destination,LandingPoint,LookAt);
                    newkeys = llDeleteSubList(newkeys,4,5); // ... the 3rd avatar arriving (3rd stride) is teleported and removed from the Visitor list
                }
            }
        }
    }
    timer()
    {
        ++seconds;
        if(seconds > time)
        {
        integer k;
        for (k=((newkeys !=[])-1);k>=0;--k) //Look through all the saved visitor times
                {  // For each one ...
                    if((llGetUnixTime() - llList2Integer(newkeys, k)) > time) // If it was more than 180 seconds ago ...
                    {
                        llRegionSayTo(id,0, "Sorry, but your time is up.\n \n You will be teleported back in 3 seconds.\n \nBye!");
                        if(seconds = 3)
                        {
                            llInstantMessage(id, "Teleporting you to : "+ Destination);
                            osTeleportAgent(id, Destination, LandingPoint, LookAt);
                           
                            //llSay(0,"current keys on list: "+llList2String(newkeys, k+1)); //Check AV key
                            //llSay(0,"current arrivaltimes on list: "+llList2String(newkeys, k)); //Check AV arrivaltime
                           
                            newkeys = llDeleteSubList(newkeys, k+1, k+1); // Remove Av from visitor list
                            newkeys = llDeleteSubList(newkeys, k, k); // Remove Av's arrivaltime, too
                           
                            //llSay(0,"reset keys on list: "+llList2String(newkeys, k+1)); //Check if Av was removed (no key returned)
                            //llSay(0,"reset arrivaltimes on list: "+llList2String(newkeys, k)); //Check if arrivaltime was removed (no integer returned)
                        }
                    }
                }
            }
    }
   
     touch_start(integer num_detected)
    {
       id=llDetectedKey(0);
       integer j;
       for(j = 0; j < numOfAvatars; ++j);
       {
           j = llListFindList(newkeys,id);
           llInstantMessage(id, "Teleporting you to : "+ Destination);
           osTeleportAgent(id, Destination, LandingPoint, LookAt);
           
           //llSay(0,"keys: "+llList2String(newkeys,j)); // Say key of agent touching
           //llSay(0,"times: "+llList2String(newkeys,j-1)); // Say integer arrivaltime of agent touching
           
           newkeys = llDeleteSubList(newkeys,j,j); // Remove Av from visitor list
           newkeys = llDeleteSubList(newkeys,j-1,j-1); // Remove Av's arrivaltime, too
           
           //llSay(0,"neue keys: "+llList2String(newkeys,j)); //Check if Av was removed (no key returned)
           //llSay(0,"neue times: "+llList2String(newkeys,j-1)); //Check if arrivaltime was removed (no integer returned)
        }
    }
}


Last edited by marshall genord on Fri Mar 06, 2020 7:17 am, edited 4 times in total.

Top
 Profile  
 
 Post subject: Re: restrict access to building
PostPosted: Thu Mar 05, 2020 2:57 pm 

Joined: Mon Jul 19, 2010 3:30 am
Posts: 18
Heres another method using llSensor()

{L_CODE}:
//Limit access by number of avatars
//Total Sorbet March 2020

integer allowed=3;      //number of avatars allowed inside restricted zone
float radius=5.0;       //radius of restricted zone from this prim
float time=2.0;         //interval between checks
vector tp=<100,117,20>; //teleport destination
vector la=<1,0,0>;      //lookat direction

list resident;          //buffer holds keys of avatars allowed into restricted zone

default
    {
    state_entry()
        {
        llSay(0,"OK");
        llSensorRepeat("","",AGENT,radius,PI,time);
        }
       
    no_sensor()
        {
        //noone home so clear list
        resident=[];
        }
       
    sensor(integer i)
        {
        //build list of whos in restricted zone
        list inzone;
        while(i--) inzone+=llDetectedKey(i);
       
        //check if avatar left restricted zone and remove from list 'resident'
        i=llGetListLength(resident);
        while(i--)
            {
            if(!~llListFindList(inzone,llList2Key(resident,i))) resident=llDeleteSubList(resident,i,i);
            }
           
        //append 'inzone' avatars to 'resident' whilst avoiding duplicates
        i=llGetListLength(inzone);
        while(i--)
            {
            key k=llList2Key(inzone,i);
            if(!~llListFindList(resident,k)) resident+=k;
            }
           
        //'resident' now contains pre-existing avatars in zone plus any new ones (in that order) so lets remove those over the limit
        i=llGetListLength(resident);
        while(i>allowed)
            {
            key k=llList2Key(resident,--i);
            osTeleportAgent(k,tp,la);
            llRegionSayTo(k,0,"Sorry the limit for this area is "+(string)allowed+" avatars");
            resident=llDeleteSubList(resident,i,i);
            }
        }
    }


Top
 Profile  
 
 Post subject: Re: restrict access to building
PostPosted: Thu Mar 05, 2020 3:50 pm 
Furious Typer

Joined: Mon Feb 13, 2017 1:53 pm
Posts: 98
Thank you very much! :-)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 1   [ 5 posts ]


Who is online

Users browsing this forum: legacy_google [bot] and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
610nm Style by Daniel St. Jules of Gamexe.net