User:Daemonika Nightfire/Scripts/Access Tutorial EN
Important: In translation work. My english are not the best if you find mistyped, wrong or stupid comments feel free and improve it, but please don't change the scripts itself. |
General Permissions
The first 4 examples works in all events where you can use llDetectedKey(0) to get the AvatarKey (UUID). For easy understand i just show it with the touch event and for comparisation deeper with the listener event, because there are llDetectedKey(0) impossible.
Public
This easy example are the same like a "New Script" which everyone can create in a simple prim. It has no restrictions and can used by everyone. <lsl> default {
state_entry() { }
touch_start(integer total_number) { llSay(0, "Touched."); } on_rez(integer Dae) { llResetScript(); }
} </lsl>
Owner
The following script are a bit different. If someone click, it will check that the Avatar who clicked it is realy the owner. <lsl> key owner; // global variable for store the OwnerKey.
default {
state_entry() { owner = llGetOwner(); // store the OwnerKey (UUID) }
touch_start(integer num_detected) { if(llDetectedKey(0) == owner) // detected Key == (equal) Owner { llSay(0, "Touched."); } else if(llDetectedKey(0) != owner) // detected Key != (not equal) Owner { llSay(0,"You are not the Owner."); } } on_rez(integer Dae) { llResetScript(); }
} </lsl> The following alternative examples needs the global stored vatiable 'owner' otherwise it must replaced with llGetOwner().
Alternative Methode 1 | Alternative Methode 2 |
---|---|
<lsl>
touch_start(integer num_detected) { key Avatar = llDetectedKey(0); if(Avatar == owner) // detected Key == (equal) Owner { llSay(0, "You are the Owner."); } else if(Avatar != owner) // detected Key == (not equal) Owner { llSay(0,"You are not the Owner."); } } </lsl> |
<lsl>
touch_start(integer num_detected) { key Avatar = llDetectedKey(0); string Message = "You are not the Owner."; // Message will not be changed, so long not the owner click. if(Avatar == owner) { // Message will be replaced, when the owner click. Message = "You are the Owner."; } llSay(0, Message); } </lsl> |
A reverse proof with 'else if' are not needed if you just want to use it for owner only. That will save work and save memory for more important funktions. Except you want different functions for different users, then you have different course as in the above examples.
<lsl>
touch_start(integer num_detected) { key Avatar = llDetectedKey(0); if(Avatar == owner) // detected Key == (equal) Owner { llSay(0, "You are the Owner."); } }
</lsl>
Group
This script looks different again. When someone click, it will check for the group of the avatar who clicked it. It compares the activ group of the avatar with the group with which it is rezzed.
Example 1 | better Method |
---|---|
<lsl>
// This example are just for show whats going on. default { state_entry() { } touch_start(integer num_detected) { // the avatar wear the same group like the object? if(llSameGroup(llDetectedKey(0)) == TRUE) { llSay(0, "Touched."); } // the avatar don't wear the same group like the object? else if(llSameGroup(llDetectedKey(0)) == FALSE) { llSay(0,"You are not wearing the correct group-tag."); } } on_rez(integer Dae) { llResetScript(); } } </lsl> |
<lsl>
default { state_entry() { } touch_start(integer num_detected) { key Avatar = llDetectedKey(0); integer Group = llSameGroup(Avatar); // the avatar wear the same group like the object? if(Group) { llSay(0, "Touched."); } // the avatar don't wear the same group like the object? else if(!Group) { llSay(0,"You are not wearing the correct group-tag."); } } on_rez(integer Dae) { llResetScript(); } } </lsl> |
Accesslist
In this script the whole thing looks completely different. Unlike the first 3 versions where only those of the owner or the entire group be established, you can here more users, regardless of ownership and determine group membership. When the object is clicked, it only checked whether the name of the person who clicked it on the list.
<lsl> // User with Resident as second name will be insert "without dot and without second name" list VIP = ["daemonika.nightfire", "jane.doe", "john.doe"];
default {
state_entry() { }
touch_start(integer num_detected) { if(~llListFindList(VIP, llCSV2List(llGetUsername(llDetectedKey(0))))) // seach the name of the avatar who clicked in the list { llSay(0, "Touched."); } else //if(!~llListFindList(VIP, llCSV2List(llGetUsername(llDetectedKey(0))))) { llSay(0,"You are not listed"); } } on_rez(integer Dae) { llResetScript(); }
} </lsl>
The use of Displaynames is not recommended, because they are not unique. It is better to focus on Usernames or AvatarKey's (UUID). This script also works with keys, replace the corresponding entries for the following examples.
<lsl> // place here the AvatarKey's, which allowd to use the script. list VIP = ["61ee201a-81cf-4322-b9a8-a5eb8da777c2", "00000000-0000-0000-0000-000000000000"];
// This if compares the key of the person who clicked it with the list. if(~llListFindList(VIP, llCSV2List(llDetectedKey(0)))) // seach the key of the avatar who clicked in the list </lsl>
Permissions in listener
The Listener version I introduce only because llDetectedKey(0) does not work, but it also can be distinguished because the listener itself recognizes the 'id' (UUID). Furthermore, this method works in all events, where is not a llDetectedKey (0) possible, however, the 'id' (UUID) is the avatar otherwise recognized.
Listener - Public
This script has no restrictions and can used by everyone. <lsl> default {
state_entry() { llListen(0, "", "", ""); // starts the listener }
listen(integer chan, string name, key id, string message) { if(message == "hello") // Responds to the word 'hello' when it is written in the chat. { llSay(0, "Hello " + llGetDisplayName(id)); } } on_rez(integer Dae) { llResetScript(); }
} </lsl>
Listener - Owner
In this script, the Owner will be entered directly in llListen command. Thus, the script responds exclusively to the owner and the event listener are no further queries necessary.
<lsl> default {
state_entry() { // If the script is only reacting to the Owner, the llGetOwner () query in llListen command is sufficient. llListen(0, "", llGetOwner(), ""); // starts the listener // Alternatively you can also enter the name of the owner directly. // I would not recommend it because it is not dynamic, and in the case of passing not listens to the new owner. //llListen(0, "Daemonika Nightfire", "", ""); // starts the listener }
listen(integer chan, string name, key id, string message) { // At this point, I still have the alternative method to verify with the owner, listed as inactive example. // This method is not necessary because the listener reacts as early as the command above solely to the Owner.
// This requires a completely empty llListen command above: llListen(0, "", "", ""); //if(id == llGetOwner()) //{ if(message == "hello") // Responds to the word 'hello' when it is written in the chat. { llSay(0, "Hello " + llGetDisplayName(id)); } //} } on_rez(integer Dae) { llResetScript(); }
} </lsl>
Listener - Group
To query the group, you have to proceed differently in the following example. Here compares the script in the 'Listener Event', the group of the object with the active group of the avatar and then respond to the message if the group is the same.
<lsl> default {
state_entry() { // here it is impossible to compare the group. llListen(0, "", "", ""); // starts the listener }
listen(integer chan, string name, key id, string message) { if(llSameGroup(id) == TRUE) // is the recognized group of the avatar the same as that of the object RIGHT? { if(message == "hello") // Responds to the word 'hello' when it is written in the chat. { llSay(0, "Hello " + llGetDisplayName(id)); } } } on_rez(integer Dae) { llResetScript(); }
} </lsl>
Listener - Accesslist
Like the Script above compares the following script the key of the avatar with the list inside the listener event.
<lsl> // place here the AvatarKey's, which allowd to use the script. list VIP = ["61ee201a-81cf-4322-b9a8-a5eb8da777c2", "00000000-0000-0000-0000-000000000000"];
default {
state_entry() { // here it is impossible to compare the list. llListen(0, "", "", ""); // startet den listener }
listen(integer chan, string name, key id, string message) { if(~llListFindList(VIP, llCSV2List(id))) // is the recognized key of the avatar stored in the list? { if(message == "hallo") // Responds to the word 'hello' when it is written in the chat. { llSay(0, "Hallo " + llGetDisplayName(id)); } } } on_rez(integer Dae) { llResetScript(); }
} </lsl>
As mentioned in Example touch, you can also query the name of the avatars. Replace the corresponding entries for the following examples.
<lsl> // User with Resident as second name will be insert "without dot and without second name" list VIP = ["daemonika.nightfire", "jane.doe", "john.doe"];
// This if compares the name of the person who clicked it with the list. if(~llListFindList(VIP, llCSV2List(llGetUsername(id)))) // // search the name of the avatar who clicked in the list </lsl>
Bevor jetzt wieder jemand meckert, warum ich das Menue so und nicht anders gemacht habe, sollte man sich vor Augen halten, dass dieses nur ein Beispiel ist und es unzaehlige Varianten zum gestalten eines Menues gibt. Hier geht es einzig und allein um die Unterscheidung der Berechtigungen.
<lsl> key owner; // globale Variable zum speichern des OwnerKey's
// In diese Liste trage die AvatarKey's ein, welche das Scrirpt ausfuehren duerfen. list VIP = ["61ee201a-81cf-4322-b9a8-a5eb8da777c2", "00000000-0000-0000-0000-000000000000"];
integer GroupAccess = FALSE; integer PublicAccess = FALSE;
integer menu_handler; integer menu_channel; menu(key user,string title,list buttons) // diese Funktion erlaubt dir unentlich viele Dialoge mit einem timer. {
llListenRemove(menu_handler); // loescht den letzten bekannten Listener (nuetzlich falls der Timer noch nicht abgelaufen war) menu_channel = (integer)(llFrand(9999999.0) * -1); // zufaelliger channel von -9999999.0 bis 9999999.0 menu_handler = llListen(menu_channel,"","",""); // erstellt hier einen neuen Listener mit dem neuen Channel llDialog(user, title, buttons, menu_channel); // oeffnet hier das Dialog-Fenster fuer den Benutzer llSetTimerEvent(30.0); // startet hier den Timer, der nach ablauf der Zeit den Listener loescht.
}
default {
state_entry() { owner = llGetOwner(); // speichert den OwnerKey (UUID) }
touch_start(integer num_detected) { key Avatar = llDetectedKey(0); if(Avatar == owner) // erkannter Key == (gleich) Owner { menu(owner,"Dieses Menue ist fuer den Besitzer.",["Owner","Group","Public","1","2","3","OK"]); } else if(~llListFindList(VIP, llCSV2List(Avatar))) // sucht hier in der Liste nach dem Key (UUID) des klickenden { menu(Avatar,"Dieses Menue ist fuer VIP's.",["1","2","3","OK"]); } else if(GroupAccess == TRUE) { integer Group = llSameGroup(Avatar); if(Group) { menu(Avatar,"Dieses Menue ist fuer Gruppenmitglieder",["1","2","3","OK"]); } } else if(PublicAccess == TRUE) { menu(Avatar,"Dieses Menue ist oeffentlich",["OK"]); } } listen(integer channel, string name, key id, string message) { // Diese Optionen koennen nur durch den Besitzer geaendert werden. if(message == "Owner") { GroupAccess = FALSE; PublicAccess = FALSE; llOwnerSay("Berechtigung: Besitzer"); } else if(message == "Group") { GroupAccess = TRUE; PublicAccess = FALSE; llOwnerSay("Berechtigung: Besitzer & Gruppenmitglieder."); } else if(message == "Public") { GroupAccess = FALSE; PublicAccess = TRUE; llOwnerSay("Berechtigung: Alle / oeffentlich"); } // Diese Optionen stehen sowohl Besitzer und VIP's als auch Gruppenmitgliedern zur verfuegung. else if(message == "1") { llSay(0,"Besitzer, VIP o. Gruppenmitglied hat die '1' gedrueckt."); } else if(message == "2") { llSay(0,"Besitzer, VIP o. Gruppenmitglied hat die '2' gedrueckt."); } else if(message == "3") { llSay(0,"Besitzer, VIP o. Gruppenmitglied hat die '3' gedrueckt."); } // Diese Option stehen allen zur verfuegung. else if(message == "OK") { llSay(0,"Es wurde auf 'OK' gedrueckt."); } } timer() { llSetTimerEvent(0.0); // stoppt den Timer llListenRemove(menu_handler); // loescht den aktuellen Listener } on_rez(integer Dae) { llResetScript(); }
} </lsl>