Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Security Orb Script Help

Johnny Sleestak
Registered User
Join date: 17 Mar 2006
Posts: 2
05-15-2007 23:22
I have this open source Security Script and I'm trying to modify it slightly. It works good except it will still kick people from the land even if they move out of the pre- set range. I'd like to modify it so it won't kick the person if they back away from it. I've tried but can't seem to figure it out.

CODE

key second = NULL_KEY; // fill in a second key if you want
string active = "deactive";
float range = 25.0;

key nrofnamesoncard;
integer nrofnames;
list names;
list keynameoncard;
string nameoncard;
string storedname;

integer listener;

default
{
state_entry()
{
llOwnerSay("Startup state reading whitelist notecard");
nrofnamesoncard = llGetNumberOfNotecardLines("whitelist"); // reads a notecard with names. called whitelist
}

dataserver (key queryid, string data){

if (queryid == nrofnamesoncard)
{

nrofnames = (integer) data;
llOwnerSay("Found "+(string)nrofnames+ " names in whitelist.");

integer i;
for (i=0;i < nrofnames;i++){
keynameoncard += llGetNotecardLine("whitelist", i);
}
} else
{
integer listlength;
listlength = llGetListLength(keynameoncard);
integer j;
for(j=0;j<listlength;j++) {
if (queryid == (key) llList2String(keynameoncard,j))
{
llOwnerSay("Name added to whitelist: "+data);
names += data;
}
}
}

if (llGetListLength(names) == nrofnames)
{
llOwnerSay ("Done with reading notecard. Starting script now");
state start;
}



}


}
state start
{
state_entry ()
{
llListen(9, "", llGetOwner(), "");
llListen(9, "", second, "");
llSensorRepeat("", NULL_KEY, AGENT, range, PI, 5.0);
}

listen(integer channel, string name, key id, string message)
{
if (message == "activate")
{
active = "active";
llOwnerSay("Activated");
}
if (message == "deactivate")
{
active = "deactive";
llOwnerSay("Deactivated");
}
if (message == "reset")
{
llResetScript();
}
if (llGetSubString(message,0,4) == "range"){
range = (float) llGetSubString(message,6,-1);
llSensorRemove();
llSensorRepeat("", NULL_KEY, AGENT, range, PI, 5.0);
llOwnerSay("Changed range to: "+(string) range);
}
}

sensor(integer nr)
{

if (active == "active")
{
integer i;
for (i = 0; i < nr; i++)
{
string found = "no";

string nametotest = llDetectedName(i);
integer j;
for (j = 0; j < llGetListLength(names); j++)
{
if (llList2String(names, j) == nametotest){
found = "yes";
}
}
if (found == "no")
{
llSay(0, "You will be ejected from this land in 10 seconds. You are on ground you should not be on.");
llSleep(10);
llSay(0, "BYE!");
llInstantMessage(llGetOwner(), "Ejecting from our home: "+llDetectedName(i));
if (second != NULL_KEY)
{
llInstantMessage(second , "Ejecting from our home: "+llDetectedName(i));
}
llEjectFromLand(llDetectedKey(i));
}
}
}
}

}
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
05-16-2007 00:13
You will need to start a single sensor sweep for the specific AV just prior to ejection. If they are still in range (i.e. detected) then eject them. The best way would be to hand over handling to a subscript. If you expect high useage then you could use multiple ejectors.

I'd also suggest making it touch / dialog based rather than always on but thats a personal choice.

Oh and please get rid of all the unnecessary string compares!!!
_____________________
I'm back......
Shadow Subagja
Registered User
Join date: 29 Apr 2007
Posts: 354
05-22-2007 15:01
Some comments on this script:

Definitely get rid of all the strings used for comparison, integers are MUCH faster to compare.

Also, where you are looping to find something in a list. There is a library function for that called llListFindList. For example:

CODE

string found;
for (j = 0; j < llGetListLength(names); j++)
{
if (llList2String(names, j) == nametotest){
found = "yes";
}

Can become:
CODE

integer found;
if(llListFindList(names, [nametotest]) != -1)
{
found = TRUE;
}


Which I think you will find will operate muuch faster (not to mention de-clutter your code of all the loops).

Also the script seemed very linear and only capable of dealing with 1 person intruding.. the sleep function is a no-no. Basically if somebody enters the property, the script will sleep (hang) then try to act 10 seconds later. What about other people entering in that time, or as you pointed out what about if they leave, or what if you try to reset it or disable it to prevent the boot while it is counting. The script will be very unresponsive and just not as flexible as you might want.

Cheers,
Shadow