Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Notecard and lists

Viny Bailey
Registered User
Join date: 13 Dec 2008
Posts: 5
02-15-2009 07:28
Hello,

I'm very new to scripting and i would like some help on something i cant seem
to solve. i searched the forums, but no clear answer could be found. I tried a few things with list and strings but i cant get what i want. Unfortunately i'm not skilled enough to do that.

What i wanna do is putting a notecard named "Groups"in a prim that could be placed at a house door or something. When we update the notecard by for example add one group and avatars, a script reads that notecard. The notecard is written something like this:

////////////////////example notecard begin
Group001:Officer

Group001Avis: Viny Bailey, Some Guy, John Doe


Group002:Builder

Group002Avis:Viny Something, That Guy, Ned Flanders
////////////////////example notecard end

Owner of the notecard can add and remove groups and avatars.

What I would need is a script (put in a phantom prim that holds the "Groups" notecard) that can detect who cross it, and then say (chat or im) the group of the avatar that crossed this prim.

For example,
If Viny Bailey cross that prim, the prim says: "Please welcome Viny Bailey that belongs to Officers Group".
If Ned Flanders cross the prim, the prim says "Please welcome Ned Flanders that belongs to Builder Group".
If someone who is not placed in the notecard cross the prim, the prim could say something like "Here comes " + (string)llDetectedName(0) + ", not a current member of any group".

Any help will be welcomed. Thank you all so much for ur time, have a good day.
Haravikk Mistral
Registered User
Join date: 8 Oct 2005
Posts: 2,482
02-15-2009 10:32
I've hacked up a script of mine which does pretty much what you're asking (unless I've misread the request):

CODE
float   REFRESH_TIME        = 7200.0; // How frequently to clear recent collisions

list groupNames = [];
list groupMemberKeys = [];
list groupMemberKeysMap = [];
list groupMemberNames = [];
list groupMemberNamesMap = [];

list recentCollisions = [];

key dataKey = NULL_KEY;
key notecardKey = NULL_KEY;
integer notecardLine = 0;

default {
state_entry() {
llSetStatus(STATUS_PHANTOM, FALSE);
llVolumeDetect(TRUE);

string name = llGetInventoryName(INVENTORY_NOTECARD, 0);
if (name == "") llOwnerSay("No notecard found!");
else {
llOwnerSay("Loading " + name + "…");
notecardKey = llGetInventoryKey(name);
dataKey = llGetNotecardLine(notecardKey, (notecardLine = 0));
}
} changed(integer x) { if (x & CHANGED_INVENTORY) llResetScript(); }

dataserver(key id, string data) {
if (id != dataKey) dataKey = llGetNotecardLine(notecardKey, notecardLine);

if (data != EOF) {
list parts = llParseString2List((data = "") + data, [":", ","], []);
string groupName = llStringTrim(llList2String(parts, 0), STRING_TRIM);

integer names = 0; integer x = parts != []; list indices = [];
integer index = llListFindList(groupNames, [groupName]);
if (index < 0) {
index = groupNames != [];
if (index >= 32) {
llOwnerSay("Can't add " + groupName + ", group-limit reached");
jump skip;
}
}

while ((--x) >= 1) {
string name = llToLower(
llStringTrim(llList2String(parts, x), STRING_TRIM)
);

integer i = llListFindList(groupMemberNames, [name]);
integer groups = 0;
if (i >= 0) groups = llList2Integer(groupMemberNamesMap, i);

groups = groups | (1 << index);

if (i >= 0)
groupMemberNamesMap = llListReplaceList(
groupMemberNamesMap, [groups], i, i
);
else {
groupMemberNames += [name];
groupMemberNamesMap += [groups];
}

++names;
}

if (names > 0) {
if (index == (groupNames != []))
groupNames += (list)groupName;
} else llOwnerSay("Group " + groupName + " has no members!");

@skip;
dataKey = llGetNotecardLine(notecardKey, ++notecardLine);
} else {
llOwnerSay((string)(groupNames != []) + " groups loaded.");
state ready;
}
}
}

state ready {
state_entry() { llSetTimerEvent(REFRESH_TIME); }
timer() { recentCollisions = []; }
changed(integer x) { if (x & CHANGED_INVENTORY) llResetScript(); }

collision_start(integer x) {
// Check every collider
while ((--x) >= 0) {
// Check only agents
if (llDetectedType(x) & AGENT) {
key id = llDetectedKey(x);
list l = (list)id;

// Ignore recent-colliders
if (llListFindList(recentCollisions, l) < 0) {
string name = llDetectedName(x);

integer i = llListFindList(groupMemberKeys, l);
if (i >= 0)
i = llList2Integer(groupMemberKeysMap, i);
else if (
(i = llListFindList(
groupMemberNames,
[llToLower(name)]
)) >= 0) {
integer j = llList2Integer(groupMemberNamesMap, i);

groupMemberNames = llDeleteSubList(
groupMemberNames,
i,
i
);
groupMemberNamesMap = llDeleteSubList(
groupMemberNamesMap,
i,
i
);

groupMemberKeys += l;
groupMemberKeysMap += (list)(i = j);
} else i = 0;

if (i != 0) {
list groups = [];
integer j = 0; integer x = groupNames != [];

for (; j < x; ++j) {
if ((i >> j) & 1)
groups += llList2String(groupNames, j);
}

llSay(
0,
"Please welcome " + name +
", member of " + llList2CSV(groups)
);
}

recentCollisions += l;
}
}
}
}
}


To get the nicely formatted version, you should click the "Quote" button on my post and copy/paste from there.

This script takes groups in the following format:

<group_name>: <name_1>, <name_2>, ... <name_n>

i.e - the whole request is on a single-line. If you have multiple-lines with the same <group_name> then they will all be added to the same group, this is useful if you need to enter quite a few names (as scripts can only read 255 characters-per-line).

Here's an example:

Scripters: Haravikk Mistral, Viny Bailey
People: Joe Bloggs, John Smith
Scripters: Someone Else

This will result in a group called "Scripters" with members; Haravikk Mistral, Viny Bailey, and Someone Else. And a group called "People", with members; Joe Bloggs, and John Smith.

NOTE: This script allow avatars to belong to multiple groups (and will list all of them in the greeting), it keeps this speedy by using a 32-bit field, but this means you can only have 32 unique group-names in total.
_____________________
Computer (Mac Pro):
2 x Quad Core 3.2ghz Xeon
10gb DDR2 800mhz FB-DIMMS
4 x 750gb, 32mb cache hard-drives (RAID-0/striped)
NVidia GeForce 8800GT (512mb)
Viny Bailey
Registered User
Join date: 13 Dec 2008
Posts: 5
02-15-2009 13:35
Thank you a lot!!
This works exactly how i wanted it to work.
plus the details u provided were helpfull for comprehension.
Thank you so much.