Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

notecard script?

Michelle Culcomp
Registered User
Join date: 26 Aug 2005
Posts: 6
12-03-2005 14:20
hi -- i have a working script to have a notecard handed to someone when they touch an object but i'm looking for one that will give a notecard to a visitor who approaches (not touches) the object. any ideas? i can't figure out the sensor command. thanks to anyone who can help!!
Rickard Roentgen
Renaissance Punk
Join date: 4 Apr 2004
Posts: 1,869
12-03-2005 14:56
This is the code I recommend.

CODE

// Change this to set how far away the sensor detects avatars (in meters).
float range = 20.0;

// This is the name of the notecard in the object's contents to give avatars (capitol letters count).
string notecard_name = "mynote";

// This is how many of the most recent avatars will be remembered when they're given a notecard. It is set to 75 to begin with, which means that if 76 avatars pass through, and the very first one comes back... they will get another notecard, but if the 2nd one to show up comes back, they will not.
// Setting this number too high may cause your script to break. you have about 12000 bytes to use, and in theory this list will use about (36 * avatar_history_size * 2) bytes, plus an unknown small amount. 75 is a safe bet to use about half of your 12000.
integer avatar_history_size = 75

list recipients = [];

default
{
state_entry()
{
llSensorRepeat("", NULL_KEY, AGENT, range, PI, 3.3);
}

sensor(integer n)
{
integer i;
for (i = 0; i < n; i += 1) {
if (llListFindList(recipients, [llDetectedKey(i)]) < 0) {
integer avatar_seen_index = llListFindList(recipients, [llDetectedKey(i)]);

if (avatar_seen_index >= 0) {
recipients = llDeleteSubList(recipients, avatar_seen_index, avatar_seen_index);
} else if (llGetListLength(recipients) >= avatar_history_size) {
recipients = llDeleteSubList(recipients, 0, 0);
}

recipients += llDetectedKey(i);
llGiveInventory(llDetectedKey(i), notecard_name);
}
}
}
}


The above script stores a total number of avatars it has seen and forgets the ones it has seen longest ago if it sees more than the number of avatars it's allowed. There should be less spam with this one, but here's another if the above isn't what you want.

CODE

// Change this to set how far away the sensor detects avatars (in meters).
float range = 20.0;

// This is the name of the notecard in the object's contents to give avatars (capitol letters count).
string notecard_name = "mynote";

list recipients0 = [];
list recipients1 = [];
list recipients2 = [];

default
{
state_entry()
{
llSensorRepeat("", NULL_KEY, AGENT, range, PI, 3.3);
}

sensor(integer n)
{
list new_detected = [];
integer i;
for (i = 0; i < n; i += 1) {
new_detected += llDetectedKey(i);
if (llListFindList(recipients0, [llDetectedKey(i)]) < 0) {
if (llListFindList(recipients1, [llDetectedKey(i)]) < 0) {
if (llListFindList(recipients2, [llDetectedKey(i)]) < 0) {

llGiveInventory(llDetectedKey(i), notecard_name);

}}}
}

recipients2 = recipients1;
recipients1 = recipients0;
recipients0 = new_detected;
}

no_sensor()
{
recipients2 = recipients1;
recipients1 = recipients0;
recipients0 = [];
}
}


The above code will give people a notecard if they come within 20 meters of the object. It will not give them another one until they leave the 20 meter radius area for at least 10 seconds and then come back.
_____________________