Give to ♯RLV (LSL)

From Catznip
Jump to: navigation, search

This example script demonstrates giving a folder to the script owners #RLV folder and checking for successful acceptance.

Instructions

  • Rez a prim and add the following script.
  • Touch the prim.
  • You will be offered a folder containing a copy of the script that uses Give to #RLV to place the contents directly into your #RLV folder.
  • @notify is used to inform the script when the inventory has been accepted.
  • If you do not accept, the script will time out and inform.

MIT Licence

Copyright (C) 2014 Catznip Viewer (http://catznip.com)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


// Example Script - Give to #RLV with @notify
// Copyright (C) 2014 Catznip Viewer (http://catznip.com)
// Released under the MIT Licence (http://opensource.org/licenses/MIT)

// Documentation
// http://catznip.com/index.php/Give_to_♯RLV_(LSL)


// Constants
string  FOLDER_NAME = "~TestFolder";
integer NOTIFY_CHANNEL = 12345;

// Global variables
integer ListenHandle = 0;

// Functions
CleanupInventoryOffer()
{
    // Remove the RLV notification (if you have multiple @notify you don't want to use clear)
    llOwnerSay("@clear=notify");

    // Clean up the listen and mark it as unused so we can process another inventory offer
    llListenRemove(ListenHandle);
    ListenHandle = 0;
    
    // Stop our time
    llSetTimerEvent(0.0);
}

default
{
    state_entry()
    {
    }

    touch_start(integer total_number)
    {
        // This is a simple script and we'll only handle one inventory offer at a time
        if (ListenHandle != 0)
        {
            llSay(0, "Waiting for previous offer to be accepted. Try again later");
            return;
        }
        
        // Get the key of the (first) avatar who touched us
        key avKey = llDetectedKey(0);
        // For demo purposes we'll only allow you to touch; normally you'll need to go through the toucher's relay
        if (avKey != llGetOwner())
        {
            llSay(0, "Only the owner of this prim can try this demo.");
            return;
        }
        
        // Set up the listen so we'll know when the avatar accepts/rejects the folder
        ListenHandle = llListen(NOTIFY_CHANNEL, "", avKey, "");
        // Time-out waiting for user to accept the folder after 2 minutes
        llSetTimerEvent(120);
        // Set up an RLV notfication to monitor folder messages
        llOwnerSay("@notify:" + (string)NOTIFY_CHANNEL + ";inv_offer=add");
        
        llSay(0, "Offering folder " + FOLDER_NAME + " to secondlife:///app/agent/" + (string)avKey + "/about");
        
        // Actually offer the folder (with only this script for contents)
        llGiveInventoryList(avKey, "#RLV/" + FOLDER_NAME, [ llGetScriptName() ]);
    }
    
    listen(integer channel, string name, key id, string message)
    {
        // Check if this response came in on the RLV listen channel
        if (NOTIFY_CHANNEL == channel)
        {
            list response = llParseString2List(message, [ " " ], []);
            
            string behaviour = llList2String(response, 0);
            if ("/accepted_in_rlv" == behaviour)
            {
                llSay(0, "User accepted the folder in their #RLV folder");
                CleanupInventoryOffer();
            }
            else if ("/accepted_in_inv" == behaviour)
            {
                llSay(0, "User accepted the folder in their regular inventory (Forbid Give-to-#RLV is enabled)");
                CleanupInventoryOffer();
            }
            else if ("/declined" == behaviour)
            {
                llSay(0, "User declined the offered inventory");
                CleanupInventoryOffer();
            }
        }
    }
    
    timer()
    {
        if (ListenHandle != 0)
        {
            llSay(0, "User did not accept or decline the inventory offer in a timely fashion");
            CleanupInventoryOffer();
            return;
        }
    }
}

Notes

This script is not suitable for use in a finished product (such as a transformation toy) which would need to access an RLV Relay in order to issue the commands, however it is enough to demonstrate the technique required on yourself.

The script gives a copy of itself simply as convenience, it is the only thing that is definitely going to be in the prim and you can not give empty folders. In actual use, you probably don't want to do this.

Personal tools
Namespaces

Variants
Actions
Catznip
Developer
Second Life™ and Linden Lab™ are trademarks or registered trademarks of Linden Research, Inc. No infringement is intended.
Toolbox