Don't click here unless you want to be banned.

LSL Wiki : LibraryVendor

HomePage :: PageIndex :: RecentChanges :: RecentlyCommented :: UserSettings :: You are crawl801.us.archive.org
This is a pretty straight forward vendor. It needs 5 scripts, the main vendor script, XyText for the display of the price, next and prev buttons and a display script to show an image. This vendor can sell all kinds of items including objects (vehicles, attachments), clothes, tattoos etc.

Setting up the vendor

Some guidelines for building the vendor:
1. You will need 1 prim for the display, 1 prim for XyText for the price, 1 prim for the next button and 1 prim for the prev button.
2. The design of the vendor is largly up to you with 1 recommendation: make the screenshot display prim very thin and the sides black or hidden by other prims.
3. Link all the prims together and put the appropriate scripts on the appropriate pieces. The XyText prim should be set up prior to linking.
3b I recomend having a seperate parent prim for the main script, but it can just as easily be put anywhere.
4. Add all the items you with to sell, along with all their screenshots/display images
5. Create a notecard named "VendorConfig" that follows the format of the example notecard below.

Example setup notecard
itemForSale,imageName,price
AmaShirt1,amaShirtAd1,100
AmaShirt2,amaShirtAd2,50
AmaShirt3,amaShirtAd3,200

Thanks ChandraPage. The script now accepts blank lines anywhere in the notecard without causing an error.

Main Vendor Script
// Ama Omega Vendor Script v0.3.1
// 06/2004

string name = "Vendor ";

// XyText Message Map.
integer DISPLAY_STRING      = 204000;
integer DISPLAY_EXTENDED    = 204001;
integer REMAP_INDICES       = 204002;
integer RESET_INDICES       = 204003;
integer SET_CELL_INFO       = 204004;

integer display;

list prices;
list pics;
list items;
list sold;

key k;
list temp;
integer line;
integer l;
string s;

string moneyText(string amount)
{
    s = "$" + amount;
    while (llStringLength(s) < 6) 
    {
        s = " " + s;
        if (llStringLength(s) < 6) s = s + " ";
    }
    return s;
}

incSold(integer i)
{
    sold = llListInsertList(llDeleteSubList(sold,i,i),[(integer)(llList2Integer(sold,i) + 1)],i);
}

default
{
    state_entry()
    {
        llMessageLinked(LINK_SET, DISPLAY_STRING, "EMPTY!", "");
        state setup;
    }
}

state setup
{
    state_entry()
    {
        llRequestPermissions(llGetOwner(), PERMISSION_DEBIT);
    }
    
    run_time_permissions(integer perms)
    {
        if (perms & PERMISSION_DEBIT)
        {
            state running;
        }
    }
}
    
state running
{    
    state_entry()
    {
        llListen(0,"",llGetOwner(),"reset vendor");
        llListen(0,"",llGetOwner(),"vendor report");
    }
    
    on_rez(integer param)
    {
        llResetScript();
    }
    
    listen(integer chan, string name, key id, string mes)
    {
        if (mes == "reset vendor")
        {
            state readCard;
        }
        else if (mes == "vendor report")
        {
            integer i;
            for(i=0;i<llGetListLength(sold);i++)
            {
                if (llList2Integer(sold,i) != 0) llWhisper(0,"* Sold " + (string)llList2Integer(sold,i) + " " + llList2String(items,i));
            }
        }
    }
    
    link_message(integer link, integer num, string mes, key id)
    {
        if (llGetPermissions() & !PERMISSION_DEBIT) state broken;
        if (mes == "NEXT")
        {
            display += 1;
            if (display >= llGetListLength(items)) display = 0;
            llSetObjectName(name + llList2String(items,display));
            llMessageLinked(LINK_SET, DISPLAY_STRING, moneyText(llList2String(prices,display)), "");
            llMessageLinked(LINK_SET,1,"PIC",llGetInventoryKey((key)llList2String(pics,display)));
            llMessageLinked(LINK_SET,1,"LOADNEXT",llGetInventoryKey((key)llList2String(pics,display + 1)));
            llMessageLinked(LINK_SET,1,"LOADPREV",llGetInventoryKey((key)llList2String(pics,display - 1)));            
        }
        else if (mes == "PREV")
        {
            display -= 1;
            if (display < 0) display = llGetListLength(items) - 1;
            llSetObjectName(name + llList2String(items,display));
            llMessageLinked(LINK_SET, DISPLAY_STRING, moneyText(llList2String(prices,display)), "");
            llMessageLinked(LINK_SET,1,"PIC",llGetInventoryKey((key)llList2String(pics,display)));
            llMessageLinked(LINK_SET,1,"LOADNEXT",llGetInventoryKey((key)llList2String(pics,display + 1)));
            llMessageLinked(LINK_SET,1,"LOADPREV",llGetInventoryKey((key)llList2String(pics,display - 1)));
        }
    }
    
    money(key id, integer amount)
    {
        if (amount == (integer)llList2String(prices,display))
        {
            incSold(display);
            llGiveInventory(id, llList2String(items,display));
            llWhisper(0,"Thank you for your purchase!");
        }
        else
        {
            llWhisper(0,"Sorry that is the wrong amount for this item.");
            llGiveMoney(id, amount);
        }
    }
}

state readCard
{
    state_entry()
    {
        line = 0;
        k = llGetNotecardLine("VendorConfig",line++);
        items = [];
        pics = [];
        prices = [];
    }
    
    dataserver(key q, string data)
    {
        if (q == k)
        {
            temp = llCSV2List(data);
            if (llParseString2List(data,[" "],[""]) == []);
            else if (data == EOF)
            {
                display = 0;
                llMessageLinked(LINK_SET, DISPLAY_STRING, moneyText(llList2String(prices,display)), "");
                llMessageLinked(LINK_SET,1,"PIC",llGetInventoryKey(llList2String(pics,0)));
                llWhisper(0," * Vendor setup complete : " + (string)llGetFreeMemory() + " bytes free.");
                state running;
            }
            else if (llGetListLength(temp) != 3)
            {
                llWhisper(0,"Error, improperly formatted line #" + (string)(line - 1));
                state running;
            }
            else
            {
                items += llList2String(temp,0);
                pics += llList2String(temp,1);
                prices += llList2String(temp,2);
                sold += [(integer)0];
                if ( llGetInventoryKey((key)llList2String(temp,0)) == NULL_KEY || llGetInventoryKey((key)llList2String(temp,1)) == NULL_KEY)
                {
                    llWhisper(0,"Error, missing inventory or picture from line : " + data);
                    state running;
                }
                k = llGetNotecardLine("VendorConfig",line++);
            }
        }
    }
}

state broken
{
    state_entry()
    {
        llWhisper(0,"This machine has lost permissions! Please check back later!");
        llListen(0,"",llGetOwner(),"fix " + llGetObjectName());
    }
    
    listen(integer chan, string name, key id, string mes)
    {
        state setup;
    }
}

Next Button
default
{
    touch_start(integer total_number)
    {
        llMessageLinked(LINK_SET,1,"NEXT",llDetectedKey(0));
    }
}

Prev Button
default
{
    touch_start(integer total_number)
    {
        llMessageLinked(LINK_SET,1,"PREV",llDetectedKey(0));
    }
}

Image Display
This one may need to be modified depending on the orientation of your display.
integer front = 0;  // Set this to the face of the prim you want the image on.
//Note: This script assumes that the sides of the display are either black or nonvisible.

default
{
    link_message(integer link, integer num, string mes, key id)
    {
        if (id != NULL_KEY)
        {
            if (mes == "PIC") 
            {
                llSetTexture(id,front);
            }
            else if (mes == "LOADPREV")
            {
                // If you change front then this may need to be adjusted, or disabled.
                llSetTexture(id,front + 1);
            }
            else if (mes == "LOADNEXT")
            {
                // If you change front then this may need to be adjusted, or disabled.
                llSetTexture(id,front + 2);
            }
        }
    }
}


ScriptLibrary
Comments [Hide comments/form]
Great change, Ama. I always prefer to see a code-based solution to a documentation-based one. :)
-- ChandraPage (2004-10-27 18:23:25)
Btw there is a bug introduced with the last change - if there is an empty line in the notecard, the next line never gets requested (if the (llParseString2List(data,[" "],[""]) == []) statement evaluates to true). Just add a call to llGetNotecardLine inside that block.
-- MsoLambert (2005-09-05 05:13:22)
Why doesn't it use llSetPayPrice()? I'd add it myself, but don't really have time right now..
-- SgeoComet (2006-11-26 22:09:25)
I would change this:

incSold(integer i)
{
    sold = llListInsertList(llDeleteSubList(sold,i,i),[(integer)(llList2Integer(sold,i) + 1)],i);
}

to this

incSold(integer i)
{
    sold = llListReplaceList(sold, [ llList2Integer(sold,i) + 1 ], i, i);
}

Performs the same functionality, and is shorter.
-- HeusDens (2007-08-18 11:34:31)
1) Can some moderator up here take action against spam?
2) The scripts as released here don't work; the Next/Prev button syntax is simply in error (Next button says "NEXT" while the message to listen to is "LOADNEXT")
3) SeoComet:You don't use llSetPayPrice on a Vendor since you are not selling the Vendor itself, only the items it contains.
-- a82-93-140-232.adsl.xs4all.nl (2007-10-04 04:50:34)
Attach a comment to this page: