Difference between revisions of "User:Daemonika Nightfire/Scripts/Access Tutorial EN"

From Second Life Wiki
Jump to navigation Jump to search
m (<lsl> tag to <source>)
 
(2 intermediate revisions by one other user not shown)
Line 6: Line 6:


==General Permissions==
==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.
The first 4 examples works in all events where you can use [[LlDetectedKey|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|llDetectedKey(0)]] impossible.


==Public==
==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.
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>
<source lang="lsl2">
default
default
{
{
Line 28: Line 28:
     }
     }
}
}
</lsl>
</source>


==Owner==
==Owner==
The following script are a bit different. If someone click, it will check that the Avatar who clicked it is realy the 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>
<source lang="lsl2">
key owner; // global variable for store the OwnerKey.
key owner; // global variable for store the OwnerKey.


Line 59: Line 59:
     }
     }
}
}
</lsl>
</source>
The following alternative examples needs the global stored vatiable 'owner' otherwise it must replaced with llGetOwner().
The following alternative examples needs the global stored vatiable 'owner' otherwise it must replaced with llGetOwner().
{| class="sortable" width="100%" {{Prettytable}}
{| class="sortable" width="100%" {{Prettytable}}
Line 66: Line 66:
! '''Alternative Methode 2'''
! '''Alternative Methode 2'''
|-
|-
||<lsl>
||<source lang="lsl2">
     touch_start(integer num_detected)
     touch_start(integer num_detected)
     {
     {
Line 79: Line 79:
         }
         }
     }
     }
</lsl>
</source>
||<lsl>
||<source lang="lsl2">
     touch_start(integer num_detected)
     touch_start(integer num_detected)
     {
     {
Line 93: Line 93:
         llSay(0, Message);
         llSay(0, Message);
     }
     }
</lsl>
</source>
|-
|-
|}
|}
Line 99: Line 99:
  That will save work and save memory for more important funktions.
  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.
  Except you want different functions for different users, then you have different course as in the above examples.
<lsl>
<source lang="lsl2">
     touch_start(integer num_detected)
     touch_start(integer num_detected)
     {
     {
Line 108: Line 108:
         }
         }
     }
     }
</lsl>
</source>


==Group==
==Group==
Line 117: Line 117:
! '''better Method'''
! '''better Method'''
|-
|-
||<lsl>
||<source lang="lsl2">
// This example are just for show whats going on.
// This example are just for show whats going on.


Line 147: Line 147:
     }
     }
}
}
</lsl>
</source>
||<lsl>
||<source lang="lsl2">
default
default
{
{
Line 178: Line 178:
     }
     }
}
}
</lsl>
</source>
|-
|-
|}
|}
Line 185: Line 185:
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.
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>
<source lang="lsl2">
// User with Resident as second name will be insert "without dot and without second name"
// User with Resident as second name will be insert "without dot and without second name"
list VIP = ["daemonika.nightfire", "jane.doe", "john.doe"];  
list VIP = ["daemonika.nightfire", "jane.doe", "john.doe"];  
Line 213: Line 213:
     }
     }
}
}
</lsl>
</source>
----
----
  The use of Displaynames is not recommended, because they are not unique.
  The use of Displaynames is not recommended, because they are not unique.
  It is better to focus on Usernames or AvatarKey's (UUID).
  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.
  This script also works with keys, replace the corresponding entries for the following examples.
<lsl>
<source lang="lsl2">
// place here the AvatarKey's, which allowd to use the script.
// place here the AvatarKey's, which allowd to use the script.
list VIP = ["61ee201a-81cf-4322-b9a8-a5eb8da777c2", "00000000-0000-0000-0000-000000000000"];
list VIP = ["61ee201a-81cf-4322-b9a8-a5eb8da777c2", "00000000-0000-0000-0000-000000000000"];
Line 224: Line 224:
// This if compares the key of the person who clicked it with the list.
// This if compares the key of the person who clicked it with the list.
if(~llListFindList(VIP, llCSV2List(llDetectedKey(0)))) // search the key of the avatar who clicked in the list
if(~llListFindList(VIP, llCSV2List(llDetectedKey(0)))) // search the key of the avatar who clicked in the list
</lsl>
</source>


==Permissions in listener==
==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.
The Listener version I introduce only because [[LlDetectedKey|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|llDetectedKey(0)]] possible, however, the 'id' (UUID) is the avatar otherwise recognized.


==Listener - Public==
==Listener - Public==
This script has no restrictions and can used by everyone.  
This script has no restrictions and can used by everyone.  
<lsl>
<source lang="lsl2">
default
default
{
{
Line 252: Line 252:
     }
     }
}
}
</lsl>
</source>


==Listener - Owner==
==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.
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>
<source lang="lsl2">
default
default
{
{
Line 290: Line 290:
     }
     }
}
}
</lsl>
</source>


==Listener - Group==
==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.
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>
<source lang="lsl2">
default
default
{
{
Line 320: Line 320:
     }
     }
}
}
</lsl>
</source>


==Listener - Accesslist==
==Listener - Accesslist==
Like the Script above compares the following script the key of the avatar with the list inside the listener event.
Like the Script above compares the following script the key of the avatar with the list inside the listener event.


<lsl>
<source lang="lsl2">
// place here the AvatarKey's, which allowd to use the script.
// place here the AvatarKey's, which allowd to use the script.
list VIP = ["61ee201a-81cf-4322-b9a8-a5eb8da777c2", "00000000-0000-0000-0000-000000000000"];  
list VIP = ["61ee201a-81cf-4322-b9a8-a5eb8da777c2", "00000000-0000-0000-0000-000000000000"];  
Line 353: Line 353:
     }
     }
}
}
</lsl>
</source>
  As mentioned in Example touch, you can also query the name of the avatars.
  As mentioned in Example touch, you can also query the name of the avatars.
  Replace the corresponding entries for the following examples.
  Replace the corresponding entries for the following examples.


<lsl>
<source lang="lsl2">
// User with Resident as second name will be insert "without dot and without second name"
// User with Resident as second name will be insert "without dot and without second name"
list VIP = ["daemonika.nightfire", "jane.doe", "john.doe"];  
list VIP = ["daemonika.nightfire", "jane.doe", "john.doe"];  
Line 363: Line 363:
// This if compares the name of the person who clicked it with the list.
// 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
if(~llListFindList(VIP, llCSV2List(llGetUsername(id)))) // // search the name of the avatar who clicked in the list
</lsl>
</source>


==Changeable authorization example with menu==
==Changeable authorization example with menu==
Before someone complains again why I have the menu so and not otherwise made​​, it should be borne in mind that this is just an example and there are countless variations of a design for menus. This is solely for the distinction of permissions.
Before someone complains again why I have the menu so and not otherwise made​​, it should be borne in mind that this is just an example and there are countless variations of a design for menus. This is solely for the distinction of permissions.


<lsl>
<source lang="lsl2">
key owner; // global variable for store the OwnerKey.
key owner; // global variable for store the OwnerKey.


Line 480: Line 480:
     }
     }
}
}
</lsl>
</source>

Latest revision as of 19:16, 24 January 2015

Language: Solution provider flag us.gif Solution provider flag de.gif

KBcaution.png Important: 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.

default
{
    state_entry()
    {
        
    }

    touch_start(integer total_number)
    {
        llSay(0, "Touched.");
    }
    
    on_rez(integer Dae)
    {
        llResetScript();
    }
}

Owner

The following script are a bit different. If someone click, it will check that the Avatar who clicked it is realy the owner.

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();
    }
}

The following alternative examples needs the global stored vatiable 'owner' otherwise it must replaced with llGetOwner().

Alternative Methode 1 Alternative Methode 2
    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.");
        }
    }
    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);
    }
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.
    touch_start(integer num_detected)
    {
        key Avatar = llDetectedKey(0);
        if(Avatar == owner) // detected Key == (equal) Owner
        {
            llSay(0, "You are the Owner.");
        }
    }

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
// 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();
    }
}
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();
    }
}

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.

// 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))))) // search 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();
    }
}

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.
// 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)))) // search the key of the avatar who clicked in the list

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.

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();
    }
}

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.

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();
    }
}

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.

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();
    }
}

Listener - Accesslist

Like the Script above compares the following script the key of the avatar with the list inside the listener event.

// 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();
    }
}
As mentioned in Example touch, you can also query the name of the avatars.
Replace the corresponding entries for the following examples.
// 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

Changeable authorization example with menu

Before someone complains again why I have the menu so and not otherwise made​​, it should be borne in mind that this is just an example and there are countless variations of a design for menus. This is solely for the distinction of permissions.

key owner; // global variable for store the OwnerKey.

// place here the AvatarKey's, which allowd to use the script.
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) // this funktion allows you to use endless different dialogs with one timer.
{
    llListenRemove(menu_handler); // delete the last known listener (useful when a timer still running)
    
    menu_channel = (integer)(llFrand(9999999.0) * -1);  // random channel from -9999999.0 to 9999999.0
    menu_handler = llListen(menu_channel,"","","");     // create a new Listener with new Channel
    llDialog(user, title, buttons, menu_channel);       // open the dialog for the user
    
    llSetTimerEvent(30.0); // starts the timer which after expiration of the time deletes the listener.
}

default
{
    state_entry()
    {
        owner = llGetOwner(); // store the OwnerKey (UUID)
    }

    touch_start(integer num_detected)
    {
        key Avatar = llDetectedKey(0);
        
        if(Avatar == owner) // detected Key == (equal) Owner
        {
            menu(owner,"This menue are for the owner.",["Owner","Group","Public","1","2","3","OK"]);
        }
        
        else if(~llListFindList(VIP, llCSV2List(Avatar))) // search the key of the avatar who clicked in the list
        {
            menu(Avatar,"This menue are for VIP's.",["1","2","3","OK"]);
        }
        
        else if(GroupAccess == TRUE)
        {
            integer Group = llSameGroup(Avatar);
            if(Group)
            {
                menu(Avatar,"This menue are for group-members",["1","2","3","OK"]);
            }
        }
        
        else if(PublicAccess == TRUE)
        {
            menu(Avatar,"This menue is bublic",["OK"]);
        }
    }
    
    listen(integer channel, string name, key id, string message)
    {
        // These options can be changed only by the owner.
        if(message == "Owner")
        {
            GroupAccess = FALSE;
            PublicAccess = FALSE;
            llOwnerSay("Access: Owner");
        }
        else if(message == "Group")
        {
            GroupAccess = TRUE;
            PublicAccess = FALSE;
            llOwnerSay("Access: Owner & Group-Members.");
        }
        else if(message == "Public")
        {
            GroupAccess = FALSE;
            PublicAccess = TRUE;
            llOwnerSay("Access: All / public");
        }
        
        // This options can be used by Owner, VIP and Group-Members.
        else if(message == "1")
        {
            llSay(0,"Owner, VIP or Group-Members pressed '1'.");
        }
        else if(message == "2")
        {
            llSay(0,"Owner, VIP or Group-Members pressed '2'.");
        }
        else if(message == "3")
        {
            llSay(0,"Owner, VIP or Group-Members pressed '3'.");
        }
        
        // This option can used by all, then public is set.
        else if(message == "OK")
        {
            llSay(0,"Someone pressed 'OK'.");
        }
    }
    
    timer()
    {
        llSetTimerEvent(0.0); // stop the Timer
        llListenRemove(menu_handler); // delete the current Listener
    }
    
    on_rez(integer Dae)
    {
        llResetScript();
    }
}