Interaktion

Dieses Skript lässt Avatare mit Objekten interagieren, die man selbst anhat. Im Beispiel hier sind es Haare, aber Ohren usw. gehen natürlich auch. Das Skript ist zweisprachig, deutsch und englisch. Dazu gehören drei Notecards, in der NC access stehen die Namen der Avatare, denen die Interaktion immer erlaubt ist, und in der NC forbidden die Namen derer, die das nie dürfen. Berührt ein Avatar das Objekt und steht in keiner der beiden Listen, erfolgt eine Abfrage. Sie können aber auch weggelassen werden. Die dritte Notecard namens text enthält die Aktionen und dazugehörigen Texte in der Form

Sprache | Tastenname | Text

Sprache ist dabei de oder en, Tastenname der Text der im Dialog erscheinen soll, und Text der Ausgabetext. Bei diesem wird #u durch den Benutzernamen ersetzt und #o durch den namen des Eigentümers.

Beispiel:

de | Wuscheln | #u wuschelt in #os Haaren.

würde folgenden Text ausgeben:

Heini wuschelt in Rebekkas Haaren.


// script copyright by Rebekka Revnik

integer CHANNEL0 = 55554;
integer CHANNEL1 = 55555;
integer CHANNEL2 = 55556;
integer CHANNEL3 = 55557;
integer CHANNEL4 = 55558;

list Access;
list AName;
list Deny;
list DName;
list Text;
list Button;
list Lang;
list Status;

key User;
string Name;
list Names;
list IDs;

integer Listener;
integer Talk;

string NCNAME = "text";
string ANAME = "access";
string FNAME = "forbidden";

integer NCLine = 0;
key NCid;
key ACid;
key FCid;

string Owner;
integer Language = 0;

Init()
{
	Access = [];
	Deny = [];
	AName = [];
	DName = [];
	Text = [];
	Button = [];
	Lang = [];
	Names = [];
	IDs = [];
	Status = [];
	Owner = llKey2Name(llGetOwner());
	Read(NCNAME);
}

string NEXT = ">>>";
string PREV = "<<<";
integer DlgPage = 0;
list DlgItems;
string msg;

DlgShow()
{
	list Dlg = [];
	integer Count = llGetListLength(DlgItems);
	integer Start = (DlgPage - 1) * 10 + 11;
	if(DlgPage = 0) Start = 0;
	if(DlgPage == 0)
	{
		Start = 0;
		if(Count < 13) Dlg = DlgItems;
		else Dlg = llList2List(DlgItems, 0, 1) + [NEXT] + llList2List(DlgItems, 2, 10);
	} else
{
	if(Count < Start + 12) Dlg = [PREV] + llList2List(DlgItems, Start, Start + 11);
	else Dlg = [PREV] + llList2List(DlgItems, Start, Start) + [NEXT] + llList2List(DlgItems, Start + 1, Start + 9);
}
	llListenRemove(Listener);
	Listener = llListen(CHANNEL2, "", NULL_KEY, "");
	llDialog(User, msg, Dlg, CHANNEL2);
}

integer DlgMain()
{
	integer result = TRUE;
	if(msg == PREV)
	{
		DlgPage--;
		DlgShow();
	} else if(msg == NEXT)
	{
		DlgPage++;
		DlgShow();
	} else if(msg == " ") DlgShow();
	else result = FALSE;
	return result;
}

Read(string nc)
{
	NCLine = 0;
	if(nc == NCNAME)
	{
		if(llGetInventoryType(NCNAME) != INVENTORY_NONE)
		{
			if(Language == 0) llOwnerSay("Lese Notecard text...");
			else llOwnerSay("Reading text nc...");
			NCid = llGetNotecardLine(NCNAME, NCLine++);
		} else
		{
			if(Language == 0) llOwnerSay("Keine Notecard text gefunden.");
			else llOwnerSay("No text nc found.");
		}
	}
	if(nc == ANAME)
	{
		if(llGetInventoryType(ANAME) != INVENTORY_NONE)
		{
			if(Language == 0) llOwnerSay("Lese Notecard access...");
			else llOwnerSay("Reading access nc...");
			ACid = llGetNotecardLine(ANAME, NCLine++);
		} else
		{
			if(Language == 0) llOwnerSay("Keine Notecard access gefunden.");
			else llOwnerSay("No access nc found.");
			nc = FNAME;
		}
	}
	if(nc == FNAME)
	{
		if(llGetInventoryType(FNAME) != INVENTORY_NONE)
		{
			if(Language == 0) llOwnerSay("Lese Notecard forbidden...");
			else llOwnerSay("Reading forbidden nc...");
			FCid = llGetNotecardLine(FNAME, NCLine++);
		} else
		{
			if(Language == 0) llOwnerSay("Keine Notecard deny gefunden.");
			else llOwnerSay("No forbidden nc found. Ready");
			Menu0();
		}
	}
}

integer HasAccess(key ava)
{
	if(ava == llGetOwner()) return TRUE;
	if(llListFindList(Deny, [ava]) != -1) return FALSE;
	if(llListFindList(Access, [ava]) != -1)return TRUE;
	return FALSE;
}

AddAccess(key ava, string name)
{
	if(llListFindList(Access, [ava]) != -1)
	{
		if(Language == 0) llOwnerSay(llKey2Name(ava) + "ist bereits in der Access-Liste.");
		else llOwnerSay(llKey2Name(ava) + "is already in the access list.");
	} else if(llListFindList(Deny, [ava]) != -1)
	{
		if(Language == 0) llOwnerSay(llKey2Name(ava) + "ist in der Deny-Liste. Bitte erst löschen.");
		else llOwnerSay(llKey2Name(ava) + "is in the deny list. Please delete first.");
	} else
	{
		Access += [ava];
		AName += [name];
		if(Language == 0) llOwnerSay(name + " wurde zur Access-Liste hinzugefügt.");
		else llOwnerSay(name + " added to the access list.");
	}
}

DelAccess(string name)
{
	integer x = llListFindList(AName, [name]);
	if(x == -1)
	{
		if(Language == 0) llOwnerSay(name + " ist nicht in der Access-Liste.");
		else llOwnerSay(name + " is not in the access list.");
	} else
	{
		Access = llDeleteSubList(Access, x, x);
		if(Language == 0) llOwnerSay(name + " wurde aus der Access-Liste entfernt.");
		else llOwnerSay(name + " removed from the access list.");
		AName = llDeleteSubList(AName, x, x);
	}
}

AddDeny(key ava, string name)
{
	if(llListFindList(Deny, [ava]) != -1)
	{
		if(Language == 0) llOwnerSay(llKey2Name(ava) + "ist bereits in der Deny-Liste.");
		else llOwnerSay(llKey2Name(ava) + "is already in the deny list.");
	} else if(llListFindList(Access, [ava]) != -1)
	{
		if(Language == 0) llOwnerSay(llKey2Name(ava) + "ist in der Access-Liste. Bitte erst löschen.");
		else llOwnerSay(llKey2Name(ava) + "is in the access list. Please delete first.");
	} else
	{
		Deny += [ava];
		DName += [name];
		if(Language == 0) llOwnerSay(name + " wurde zur Deny-Liste hinzugefügt.");
		else llOwnerSay(name + " added to the deny list.");
	}
}

DelDeny(string name)

{
	integer x = llListFindList(DName, [name]);
	if(x == -1)
	{
		if(Language == 0) llOwnerSay(name + " ist nicht in der Deny-Liste.");
		else llOwnerSay(name + " is not in the deny list");
	}else
	{
		Deny = llDeleteSubList(Deny, x, x);
		if(Language == 0) llOwnerSay(llList2String(DName, x) + " wurde aus der Forbidden-Liste entfernt.");
		else llOwnerSay(llList2String(DName, x) + " removed from the deny list.");
		DName = llDeleteSubList(DName, x, x);
	}
}

ListAccess()
{
	integer i;
	if(Language == 0) llOwnerSay("Avatare in der Access-Liste:");
	else llOwnerSay("Avatars in the access list:");
	for(i = 0; i < llGetListLength(Access); i++) llOwnerSay(llList2String(AName, i));
}

ListDeny()
{
	integer i;
	if(Language == 0) llOwnerSay("Avatare in der Deny-Liste:");
	else llOwnerSay("Avatars in the deny list:");
	for(i = 0; i < llGetListLength(Deny); i++) llOwnerSay(llList2String(DName, i));
}

Menu0()
{
	llListenRemove(Listener);
	Listener = llListen(CHANNEL0, "", llGetOwner(), "");
	string s = "Wähle deine Sprache\nChooose your language\nMomentan/Actually: ";
	if(Language == 0) s += "Deutsch/German";
	else s += "English/Englisch";
	list l = ["DE (german)", "EN (english)"];
	llDialog(llGetOwner(), s, l, CHANNEL0);
}

Menu1()
{
	llListenRemove(Listener);
	Listener = llListen(CHANNEL1, "", llGetOwner(), "");
	string s = llKey2Name(User) + " macht sich an deinem Haar zu schaffen. Erlaubst du das?";
	if(Language == 1) s = llKey2Name(User) + " grabs into your hair. Do you allow that?";
	list l = ["Ja", "Nein", "Immer", "Nie"];
	if(Language == 1) l = ["Yes", "No", "Always", "Never"];
	llDialog(llGetOwner(), s, l, CHANNEL1);
}

Menu2()
{
	DlgItems = [];
	integer i;
	msg = "Auswahl";
	if(Language == 1) msg = "Choose";
	for(i = 0; i < llGetListLength(Lang); i++)
	{
		if(llList2String(Lang, i) == "de" && Language == 0) DlgItems += [llList2String(Button, i)];
		else if(llList2String(Lang, i) == "en" && Language == 1) DlgItems += [llList2String(Button, i)];
	}
	DlgShow();
}

Menu3()
{
	list l = ["Access +", "Access -", "List Access", "Deny +", "deny -", "List Deny", "DE (german)", "EN (english)"];
	if(Language == 0) l += ["Zurück"]; else l += ["Back"];
	llListenRemove(Listener);
	Listener = llListen(CHANNEL3, "", llGetOwner(), "");
	string s = "Auswahl";
	if(Language == 1) s = "Choose an option";
	llDialog(llGetOwner(), s, l, CHANNEL3);
}

Say(string s)
{
	list l = llParseString2List(Owner, [" "], []);
	string o = llList2String(l, 0);
	l = llParseString2List(llKey2Name(User), [" "], []);
	string u = llList2String(l, 0);
	while(llSubStringIndex(s, "#u") != -1)
	{
		integer x = llSubStringIndex(s, "#u");
		if(x > 0) s = llGetSubString(s, 0, x-1) + u + llGetSubString(s, x+2, llStringLength(s));
		else s = u + llGetSubString(s, x+2, llStringLength(s));
	}
	while(llSubStringIndex(s, "#o") != -1)
	{
		integer x = llSubStringIndex(s, "#o");
		if(x > 0) s = llGetSubString(s, 0, x-1) + o + llGetSubString(s, x+2, llStringLength(s));
		else s = o + llGetSubString(s, x+2, llStringLength(s));
	}
	llSay(0, s);
}

default
{
	state_entry()
	{
		Init();
	}
	changed(integer change)
	{
		if(change & CHANGED_OWNER) Owner = llKey2Name(llGetOwner());
		if(change & CHANGED_INVENTORY) Init();
	}
	listen(integer channel, string name, key id, string message)
	{
		if(channel == CHANNEL0)
		{
			if(message == "DE (german)") Language = 0;
			else if(message == "EN (english)") Language = 1;
			return;
		}
		if(channel == CHANNEL1)
		{
			if(message == "Ja" || message == "Yes")
			{
				Menu2();
			} else if(message == "Nein" || message == "No")
		{
			return;
		} else if(message == "Immer" || message == "Always")
		{
			AddAccess(User, Name);
			Menu2();
		} else if(message == "Nie" || message == "Never")
		{
			AddDeny(User, Name);
			return;
		}
		} else if(channel == CHANNEL2)
	{
		if(DlgMain()) return;
		if(message == "Optionen" || message== "Options")
		{
			Menu3();
			return;
		} else
	{
		integer x = llListFindList(Button, [message]);
		if(x != -1) Say(llList2String(Text, x));
	}
	} else if(channel == CHANNEL3)
	{
		Talk = 0;
		llListenRemove(Listener);
		if(message == "DE (german)") Language = 0;
		if(message == "EN (english)") Language = 1;
		if(message == "Access +") Talk = 1;
		if(message == "Access -") Talk = 2;
		if(message == "deny +") Talk = 3;
		if(message == "Deny -") Talk = 4;
		if(message == "List Access") ListAccess();
		if(message == "List Deny") ListDeny();
		if(message == "Zurück" || message == "Back")
		{
			Menu2();
			return;
		}
		if(Talk != 0)
		{
			if(Language == 0) llOwnerSay("Sag den Namen auf /" + (string)CHANNEL4 + ". Du hast 30 Sekunden Zeit.");
			else llOwnerSay("Say the name on channel /" + (string)CHANNEL4 +". You have 30 seconds to do so.");
			llSetTimerEvent(30);
			llListenRemove(Listener);
			Listener = llListen(CHANNEL4, "", User, "");
		}
	} else if(channel == CHANNEL4)
	{
		Name = message;
		if(Talk == 2) DelAccess(Name);
		else if(Talk == 4) DelDeny(Name);
		else if(Talk == 1 || Talk == 3)
		{
			Status += [Talk];
			Names += [Name];
			IDs += [llHTTPRequest("http://w-hat.com/name2key?terse=1&name="+llEscapeURL(Name), [], "")];
		}
		llListenRemove(Listener);
		llSetTimerEvent(0);
	}
	}
	touch_start(integer total_number)
	{
		User = llDetectedKey(0);
		Name = llDetectedName(0);
		Menu2();
	}
	timer()
	{
		if(Language == 0) llOwnerSay("Die Zeit für die Eingabe ist abgelaufen.");
		else llOwnerSay("Time for input expired.");
		llListenRemove(Listener);
		llSetTimerEvent(0);
	}
	http_response(key request_id, integer status, list metadata, string body)
	{
		integer x = llListFindList(IDs, [request_id]);
		if(x != -1)
		{
			if (status != 499 && status != 200 && (key)body != NULL_KEY)
			{
				key k = (key)body;
				integer y = llList2Integer(Status, x);
				string s = llList2String(Names, x);
				if(y == 1) AddAccess(k, s);
				else if(y == 3) AddDeny(k, s);
				llSetTimerEvent(0);
				IDs = llDeleteSubList(IDs, x, x);
				Status = llDeleteSubList(Status, x, x);
				Names = llDeleteSubList(Names, x, x);
			}
		}
	}
	dataserver(key requested, string data)
	{
		integer x = llSubStringIndex(data, "//");
		if(x != -1) data = llDeleteSubString(data, x, llStringLength(data)-1);
		if(requested == NCid)
		{
			if(data != EOF)
			{
				list l = llParseString2List(data, ["|"],[]);
				if(llGetListLength(l) == 3)
				{
					Lang += [llToLower(llStringTrim(llList2String(l, 0), STRING_TRIM))];
					Button += [llStringTrim(llList2String(l, 1), STRING_TRIM)];
					Text += [llStringTrim(llList2String(l, 2), STRING_TRIM)];
				}
				NCid = llGetNotecardLine(NCNAME, NCLine++);
			} else
			{
				llOwnerSay("fertig.");
				return;
			}
		} else if(requested == ACid)
		{
			if(data != EOF)
			{
				data = llStringTrim(data, STRING_TRIM);
				if(data != "")
				{
					Status += [1];
					Names += [data];
					IDs += [llHTTPRequest("http://w-hat.com/name2key?terse=1&name="+llEscapeURL(data), [], "")];
				}
				ACid = llGetNotecardLine(ANAME, NCLine++);
			} else
			{
				Read(FNAME);
				return;
			}
		} else if(requested == FCid)
		{
			if(data != EOF)
			{
				data = llStringTrim(data, STRING_TRIM);
				if(data != "")
				{
					Status += [3];
					Names += [data];
					IDs += [llHTTPRequest("http://w-hat.com/name2key?terse=1&name="+llEscapeURL(data), [], "")];
				}
				FCid = llGetNotecardLine(FNAME, NCLine++);
			} else
			{
				if(Language == 0) llOwnerSay("bereit.");
				else llOwnerSay("Ready.");
				Menu0();
			}
		}
	}
}