Very Simple Dialog Menu Inventory Giver ( V3 )

Written by Kitsune

 

  • Name this script something like "0000000000000000000" (zeros) so that it is definitely the first inventory item listed alphabetically.

Limited script. Not at all advanced. Only 12 inventory items (will update at some point). If giving away scripts, set them to not running.

 

 

// V3 //
 
integer lis;
 
integer channel;
 
integer busy;
 
integer noi;
 
list StrideOfList(list src, integer stride, integer start, integer end)
{
    list l = [];
    integer ll = llGetListLength(src);
    if(start < 0)start += ll;
    if(end < 0)end += ll;
    if(end < start) return llList2List(src, start, start);
    while(start <= end)
    {
        l += llList2List(src, start, start);
        start += stride;
    }
    return l;
}
 
default
{
    changed(integer change)
    {
        if(change & CHANGED_INVENTORY)
        llResetScript();
    }
    on_rez(integer param)
    {
        llResetScript();
    }
    state_entry()
    {
        noi = (llGetInventoryNumber(INVENTORY_ALL) - 1);
    }
    touch_start(integer nd)
    {
        if((!busy) && noi)
        {
            busy = TRUE;
            key agent = llDetectedKey(0);
            list stuff = [];
            string name = "";
            integer index = 0;
            while((llGetListLength(stuff) < 24) && (index < 12))
            {
                if((name = llGetInventoryName(INVENTORY_ALL, (++index))) != llGetScriptName())
                {
                    if(name != "")
                    stuff += [(((string)index) + " - " + name), ((string)index)];
                }
            }
            llListenRemove(lis);
            channel = (llRound(llFrand(-10000000)) - 100000);
            lis = llListen(channel, llDetectedName(0), agent, "");
            llDialog(agent, ("\nSelect your inventory offer -\n" +
                            llDumpList2String(StrideOfList(stuff, 2, 0, -1), "\n")), StrideOfList(stuff, 2, 1, -1), channel);
            llSetTimerEvent(30.0);
        }
    }
    listen(integer chan, string name, key id, string msg)
    {
        string item = "";
        if(llGetInventoryType((item = llGetInventoryName(INVENTORY_ALL, ((integer)msg)))) != -1)
        {
            llSetTimerEvent(0.0);
            llListenRemove(lis);
            llGiveInventory(id, item);
            busy = FALSE;
        }
    }
    timer()
    {
        llSetTimerEvent(0.0);
        llListenRemove(lis);
        busy = FALSE;
    }
}
[edit]