Jump to content

Problems with my Intruder Log


CincinnatiBearcats
 Share

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

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

Recommended Posts

Hi,

So I have been writing an Intruder Log and I'm pretty close to being done with it. I'm just having a few problems I hope someone could help me out with. 

1. Why is the if statement if(llListFindList(accessList, [avatar]) < 0) not including me in it since I put myself on the access list?

2. I want to store the intruders position into a list. Currently, it keeps updating the owner(me) of their positions. 

3. Why is the if statement where I am testing to see if it is a returning visitor not ever true? It goes to the else and whispers when they enter the forbidden area. This is a problem because it always says the intruder is a new visitor. It was working before and I can't figure out what I did.

Thank you so much.

Here is the code:

key requestid; // just to check if we're getting the result we've asked for; all scripts in the same object get the same replies

//Declare variables
list find = []; //Stores the intruder's positions in list form
list todayVisitors = [];
list allVisitors = [];
list repeatVisitors = [];
list firstTime = [];
integer newVisitors = 0;
integer returnVisitors = 0;
string region;
integer on;
string theAvy;
integer mesLevel;
float SensorRange = 20; //Sensors range measured in meters
integer UpdateFrequency = 5; //Sweep every 5 seconds

//Current access list
list accessList = ["Craig Ashworth"];

//Show access list to owner, comma separated
AccessList()
{
    llOwnerSay("Current access list: " + llDumpList2String(accessList, ", "));
}

default
{
    state_entry()
    {
        on = 0;
        mesLevel = 1;
        llListen(0, theAvy, NULL_KEY, "");    
        llListen(-535, theAvy, NULL_KEY, "");  
        llSensorRepeat( "", "", AGENT, SensorRange, PI, 30);
        llSetTimerEvent(UpdateFrequency); //Set timer according to the updateFrequency 
        llOwnerSay("Intruder Log Started.");  
    }
    //Use sensor to find the avatars in the region
    sensor(integer found)
    {
        //Get owner UUID and avatar who entered
        key ownerKey = llGetOwner();
        key detectedKey = llDetectedKey(0);
        //Get their names
        string owner = llKey2Name(ownerKey);
        string avatar = llKey2Name(detectedKey);

        //Keep a key to find the detected avatars
        key  avKey;
        integer num;
        for(num = 0; num < found; num++)
        {
            //Test if avatar is on the access list
            if(llListFindList(accessList, [avatar]) < 0 
                && llDetectedKey(num) != llGetOwner())
            {
                llWhisper(0, "You are not on the access list. Ask " + owner 
                      + " if you are allowed here.");
                      
                avKey = llDetectedKey(num);
                string who = llDetectedName(num);

                    string avLocation = (string)llDetectedPos(num);
                    llOwnerSay(avatar + " was located at " + avLocation 
                        + " at " + (string)llGetTime());


                if (!~llListFindList(todayVisitors, [who]))
                {
                    //This avatar hasn't been seen yet today
                    todayVisitors += [who];
                    if (~llListFindList(allVisitors, [who]))
                    {
                        //This is a returning visitor
                        returnVisitors++;
                        repeatVisitors += [who];
                        llInstantMessage(llGetOwner(), llDetectedName(num) 
                            + " has not left the forbidden area.");
                    } 
                    else
                    {
                        //This is the visitors first time
                        newVisitors++;
                        allVisitors = [who] + allVisitors;
                        firstTime += [who];
                        llInstantMessage(llGetOwner(), llDetectedName(num) 
                            + " has entered the forbidden area.");
                    }
                }
            }
            else
            {
                //llInstantMessage(llGetOwner(), llDetectedName(num)
                 //   + " is granted access.");
                   
            }
        }
    }
    
    //Use a timer to keep the information on the visitors updating regularly
    timer() 
    {
        //Keep a log of all the visitors
        string visitors = "Number of Total Visitors: " 
            + (string)(newVisitors + returnVisitors)
            + "\nReturning Visitors: " + (string)returnVisitors
            + "\nNew Visitors: " + (string)newVisitors
            + "\n\nList of New Visitors:\n\t" 
            + llDumpList2String(firstTime, "\n\t")
            + "\n\nList of Returning Visitors:\n\t" 
            + llDumpList2String(repeatVisitors, "\n\t");

        if (llGetListLength(allVisitors) > 50)
        {
            allVisitors = llList2List(allVisitors, 0, 49);
        }
    } 
    
    touch_start(integer number)
    {
        //Get owner UUID and avatar who entered
        key ownerKey = llGetOwner();
        key detectedKey = llDetectedKey(0);
        on = 1;
        llSay(0, "Say something to get the visitor log sent:");
        
        //Display access list to owner
        if(detectedKey == ownerKey)
        {
            AccessList();
        }   
    }

    listen(integer channel, string name, key id, string message)
    {
        //llSensor("", NULL_KEY, AGENT, 96, PI);
        //Declare again so you can send the data
        string visitors = "Number of Total Visitors: " 
            + (string)(newVisitors + returnVisitors)
            + "\nReturning Visitors: " + (string)returnVisitors
            + "\nNew Visitors: " + (string)newVisitors 
            + "\n\nList of New Visitors:\n\t" 
            + llDumpList2String(firstTime, "\n\t")
            + "\n\nList of Returning Visitors:\n\t" 
            + llDumpList2String(repeatVisitors, "\n\t");
            
        if((on == 1) && (channel == 0))
        {
            //Use text.php to send the visitor log as a text message or email
            requestid = llHTTPRequest("http://www.wbi-icc.com/students/SL/text.php", 
            [HTTP_METHOD, "POST",
             HTTP_MIMETYPE, "application/x-www-form-urlencoded"],
            "parameter1=" + visitors);  
                on = 0; 
        }
        else
        {
            mesLevel = (integer)message;   
        }
    }
}

 

Link to comment
Share on other sites

If you look at your sensor event code carefully you would see that your condition translates to this:

for(num = 0; num < found; num++)
{
//Test if avatar is on the access list
if(llListFindList(accessList, [llDetectedKey(0)]) < 0
&& llDetectedKey(num) != llGetOwner())
{
llWhisper(0, "You are not on the access list. Ask " + owner
+ " if you are allowed here.");
....
}
else
{
//llInstantMessage(llGetOwner(), llDetectedName(num)
// + " is granted access.");

}

So your condition is always TRUE unless the owner happens to be the first agent scanned.

This is what usually happens when one declares too many unnecessary variables: one loses track of them.

 

 

 

 

Link to comment
Share on other sites

... also, somthing to consider for a "security" script,  including a test for llOverMyLand() as to not affect agents not on/over your property.    http://wiki.secondlife.com/wiki/LlOverMyLand

If you are developing a script to market, use of llOverMayLand() can can be tricky, but for a personal script for use with a personally owned parcel your neighbors will appreciate it.

 

 

 

Link to comment
Share on other sites

Well said Ela.

@ OP: I'm afraid while you may be "pretty close to being done with it" this script is quite a long way from being done.  What you have is a fairly good first attempt at a first draft.  Yes, it's fairly complete but no, it's not at all tidy and, most importantly, it doesn't work.  Give yourself a day not thinking about it at all if you can, then try to read it again.  Take out all the redundant and duplicated code you can.  Think about its organisation and structure (*Hint* does that timer() routine really do anything useful?).  With a smaller and tidier script you will find it easier to spot things such as Ela has pointed out.  Then show us your second draft.

Link to comment
Share on other sites

 

 ... like has been noted, you could change the 'and' to an 'or'  ( || instead of && )

another suggestion... instead of two tests in a single if(), like here:

if( llListFindList(accessList, [avatar]) < 0                 && llDetectedKey(num) != llGetOwner())

... use a "suito" combined list for a single test like this:

if( llListFindList(accessList + [owner], [avatar]) < 0 )

 

so long as:

string owner  is the equivalent of llKey2Name( llGetOwner() ) (assigned at rez or state_entry() with you in the region)

 

 

(not for you, but for new scripters following along ...)

Scipt flow is a learned and personal experience. I usually start by thinking how I would do it in person by hand. In the case here, having the sensor event work down from whom to ignore to whom to notice via nested if() conditions in order to efficiently deal with each agent detected.

#1. agents already noticed this period (hour, day, week, etc)

#2. anyone on a Pass or Ignore list

#3  - agents not geopraphically eligible. i.e. not on my land or a targeted parcel or bounding box

then finally #4 - doing whatever for agents detected this event who are "none of the above".

 

if you will be filtering agents within the sensor() event -

useful llDetected*() functions are at your disposal like:

llDetectedName(num_detected) in lieu of llKey2Name()

llDetectedPos(num_detected) (were they walking along the parcel boundary or in my house?)

 

GL

 

 

Link to comment
Share on other sites

I've only looked at the code briefly, but 

if(llListFindList(accessList, [avatar]) < 0)

 means, "if the avatar is in the access list, but isn't the first entry".   LSL normally starts counting at 0, not 1.

If you want to check if the avatar is on the access list in any position, including the first, you need 

 

	if(llListFindList(access_list, [avatar])!=-1){	}

 or (means the same)

	if(~llListFindList(access_list,[avatar])){	}

 

 

 

Link to comment
Share on other sites


CincinnatiBearcats wrote:

I'm sorry... Yes I am. This is my Second Life name while my Imprudence name is Craig Ashworth. 

My if statement: if(llListFindList(accessList, [avatar])) should be checking in the accessList for any "avatar" names correct? I took out the rest of the statement.

There is no "Craig Ashworth" in Second Life.  "CincinnatiBearcats" is an avatar's name, however.  I'd risk a wild guess that that's you.  I have no idea what an "imprudence name" is but the environment we're dealing with is Second Life.

No "if(llListFindList(accessList, [avatar]))" does not check in the access list for any "avatar" name.  It is true IF and ONLY IF "avatar" is not the first name in that list.

To keep it straightforward use "if(llListFindList(accessList, [avatar]) != -1)" if you want to see if a name is in the list.  Use "if(llListFindList(accessList, [avatar]) == -1)" if you want to see if a name is NOT in the list.

Link to comment
Share on other sites

Using names when filtering wasn't much of a problem until Display Names came along.

 

In fact there are now three names for each avatar:

1. Legacy Name (the traditional firstname lastname)

2. Display Name - that you can choose or change (great for greeters but not recommended for security scripts)

3. User Name (firstname.lastname format that so far isn't used for much of anything I've seen in-world)

 

If you are going to use 'Name' as a means of filtering

1. read up on Legacy Names v. DIsplay Names  http://wiki.secondlife.com/wiki/Display_Names/LSL

2. check the type of "Agent" sensor call.used  http://wiki.secondlife.com/wiki/LlSensorRepeat

 

All 1-name newer folks are actually  "avName Resident" to the llSensor() function specifying simply AGENT.

I belive this may be a contributing factor to your issue here.

 

Link to comment
Share on other sites

Edited to correct a mistake in the code

Try debugging it with this:

sensor(integer found)	{		//Get owner UUID and avatar who entered		key ownerKey = llGetOwner();		string owner = llKey2Name(ownerKey);		//(since neither the owner's uuid nor name is going to change from one sensor event to the next, //I'd store these as global variables)		integer i;		while(i<found){			key k = llDetectedKey(i);			string s = llDetectedName(i);			llOwnerSay("testing "+s+", whose uuid is "+(string)k);			if(k == ownerKey){				llOwnerSay(s+" is the owner");			}			if(llListFindList(accessList,[s])<0){				llOwnerSay(s+ " is not on the access list");			}			else{				llOwnerSay(s+" is on the access list");			}			if((llListFindList(accessList,[s])<0)&&(k!=ownerKey)){				llOwnerSay(s+ " is not on the access list and isn't the owner, either");			}			i++;		}	}

 

 

Link to comment
Share on other sites

Sorry.. try this

sensor(integer found)	{		//Get owner UUID and avatar who entered		key ownerKey = llGetOwner();		string owner = llKey2Name(ownerKey);		//(since neither the owner's uuid nor name is going to change from one sensor event to the next, //I'd store these as global variables)		integer i;		while(i<found){			key k = llDetectedKey(i);			string s = llDetectedName(i);			llOwnerSay("testing "+s+", whose uuid is "+(string)k);			if(k == ownerKey){				llOwnerSay(s+" is the owner");			}			if(llListFindList(accessList,[s])<0){				llOwnerSay(s+ " is not on the access list");			}			else{				llOwnerSay(s+" is on the access list");			}			if((llListFindList(accessList,[s])<0)&&(k!=ownerKey)){				llOwnerSay(s+ " is not on the access list and isn't the owner, either");			}			i++;		}	}

 

 

  • Like 1
Link to comment
Share on other sites

You're right, there were a couple of problems.  Try:

	sensor(integer found)	{		//Get owner UUID and avatar who entered		key ownerKey = llGetOwner();		string owner = llKey2Name(ownerKey);		integer i;		while(i<found){			key k = llDetectedKey(i);			string s = llDetectedName(i);			llOwnerSay("testing " + s + ", whose uuid is " + (string) k);			if(k == ownerKey){				llOwnerSay(s+" is the owner");			}			if(llListFindList(accessList,[s])<0){				llOwnerSay(s+ " is not on the access list");			}			else{				llOwnerSay(s+" is on the access list");			}			if((llListFindList(accessList,[s]) < 0) && (k!=ownerKey)){				llOwnerSay(s+ " is not on the access list and isn't the owner, either");			}			i++;		}	}

 

  • Like 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 4420 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...