From Second Life Wiki
Revision as of 06:10, 2 August 2011 by Kira Komarov (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Created by Kira Komarov.

I have seen a number of commercial givers out there on the marketplace and wanted to implement a free one. What is does is offer a menu on touch with forward and backward browsing capabilities and lists the items contained in the same prim as the script resides in. When a user clicks a button, named after the object in the prim, the script gives a copy of that object to the user.

This script has multiple applications depending on what you want to use it for; for example, a simple application would be an automated bartender that people can click to browse and get a drink. Another example would be landmark and notecard givers.

One limitation is that the objects within the prim should have names smaller in length than 24 bytes. Also, please bear in mind that the menu buttons are generated from the inventory contents of the prim, so if your object has a long name, it will be truncated when it appears on the button. A simple way to avoid this is to give simple and meaningful names to the items in the giver prim. In case you want to add items or remove items, just reset the script after you have done your adjustments: I could have included an event handler to trigger when the inventory changes but I preferred to keep things simple.

<lsl> ////////////////////////////////////////////////////////// // [K] Komarov - 2011, License: GPLv3 // // Please see: // // for legal details, rights of fair usage and // // the disclaimer and warranty conditions. // //////////////////////////////////////////////////////////

list storage = []; integer runner = 0; integer comHandle; list cList = [];

list mFwd() {

   if(runner+1>llGetListLength(storage)) return cList;
   return (cList = llListInsertList(llListInsertList(llList2List(storage, ++runner, runner+=9), ["<= Back"], 0), ["Next =>"], 2));


list mBwd() {

   if(runner-19<0) return cList;
   return (cList = llListInsertList(llListInsertList(llList2List(storage, runner-=19, runner+=9), ["<= Back"], 0), ["Next =>"], 2));


default {

       integer itra;
       for(itra=0; itra<llGetInventoryNumber(INVENTORY_ALL); ++itra) {
           if(llGetInventoryName(INVENTORY_ALL, itra) == llGetScriptName())
               jump continue;
           storage += llGetInventoryName(INVENTORY_ALL, itra);


       cList = llListInsertList(llListInsertList(llList2List(storage, runner, runner+=9), ["<= Back"], 0), ["Next =>"], 2);
   listen( integer channel, string name, key id, string message ) {
       if(message == "<= Back") {
           llDialog(id, "Please browse the available items:\n", mBwd(), channel);
       if(message == "Next =>") {
           llDialog(id, "Please browse the available items:\n", mFwd(), channel);
       llGiveInventory(id, message);
   touch_start(integer total_number)
       integer comChannel = ((integer)("0x"+llGetSubString((string)llGetKey(),-8,-1)) & 0x3FFFFFFF) ^ 0xBFFFFFFF;
       comHandle = llListen(comChannel, llDetectedName(0), llDetectedKey(0), "");
       llDialog(llDetectedKey(0), "Please browse the available items:\n", cList, comChannel);

} </lsl>

To use the script, create a prim and add objects, notecards, or whatever you want people to be able to get from the prim. After that, drop this script in the prim. You can configure the script easily, here are some pointers for some cosmetic changes you might want to make to the script:

  • The back and forward buttons for the dialog are named in the code "<= Back" and "Next =>" respectively. If you want to change those to something more fancy, just replace every instance of "<= Back" and "Next =>" with your desired text.
  • The dialog text is set to "Please browse the available items:\n". Again, if you wish to enter your own text, just replace every instance of "Please browse the available items:\n" with what you want the dialog to say.