Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

A Two-Button Texture Vendor

Karandas Banjo
Registered User
Join date: 7 Jan 2005
Posts: 35
05-29-2005 04:07
This is a simple script I whipped up, using some code I found in the Products Wanted forum as a base, that makes a 3+ prim vendor that vends individual textures. The price stays constant for every texture in the vendor, but apart from that, it works well.

Note: The next and previous buttons dont need any scripts, the prims just have to be named "next" and "prev" respectively (and without the "s of course ;) )

CODE

// TWO-BUTTON TEXTURE VENDOR
// Origional script by Thili Playfair
// Heavily Modified by Karandas Banjo
// Please include these names if you modify or
// re-distribute this code ^_^

// To set up your vendor, you will need at least 3 prims,
// the main prim, and two buttons.

// The two buttons must both be linked to the main prim,
// one must be called "next", the other called "prev".

// Next, enter the price of the textures in this vendor,
// and if you want, time to wait for auto-scrolling.

// After that, just drop your textures into the main prim,
// and press one of the scroll buttons, and you're ready
// to go!

integer price = 50; // The price of any texture in this
// vendor.


float time = 0; // Enter a value if you want time based
// scrolling otherwise set to zero.

// NO TOUCHY BELOW HERE

string vendorname;
integer total;
integer counter;
integer change;

next()
{
total=llGetInventoryNumber(INVENTORY_TEXTURE);
vendorname = llGetObjectName();
counter++;
if(counter>=total)
{
counter=0;
}
llSetTexture(llGetInventoryName(INVENTORY_TEXTURE, counter),ALL_SIDES);
if (price > 0)
{
llSetText(vendorname + "\n" + llGetInventoryName(INVENTORY_TEXTURE, counter) + "\n L$" + (string)price + "\n", <1,1,1>, 1);
}
else
{
llSetText(vendorname + "\n" + llGetInventoryName(INVENTORY_TEXTURE, counter) + "\n Touch to recieve \n", <1,1,1>, 1);
}
llTriggerSound("Pressed", 1);
}
prev()
{
total=llGetInventoryNumber(INVENTORY_TEXTURE);
vendorname = llGetObjectName();
if (counter > 0)
{
counter--;
}
else
{
counter=total - 1;
}
llSetTexture(llGetInventoryName(INVENTORY_TEXTURE, counter),ALL_SIDES);
if (price > 0)
{
llSetText(vendorname + "\n" + llGetInventoryName(INVENTORY_TEXTURE, counter) + "\n L$" + (string)price + "\n", <1,1,1>, 1);
}
else
{
llSetText(vendorname + "\n" + llGetInventoryName(INVENTORY_TEXTURE, counter) + "\n Touch to recieve \n", <1,1,1>, 1);
}
llTriggerSound("Pressed", 1);
}

default
{
state_entry()
{
llRequestPermissions(llGetOwner(),PERMISSION_DEBIT);
next();
llSetTimerEvent(time);
}
touch_start(integer total_number)
{
if ( llGetLinkName(llDetectedLinkNumber(0)) == "next" )
{
next();
}
else if ( llGetLinkName(llDetectedLinkNumber(0)) == "prev" )
{
prev();
}
else
{
if (price > 0)
{
llWhisper(0, "Pay L$" + (string)price + " to buy");
}
else
{
llGiveInventory(llDetectedKey(0), llGetInventoryName(INVENTORY_TEXTURE, counter));
}
}
}
timer()
{
next();
}
money(key giver, integer amount)
{
if (amount < price)
{
llSay(0, "Too little payed, refunding");
llGiveMoney(giver, amount);
}
else if (amount > price)
{
change = amount - price;
llSay(0, "Overpaid. vending item and giving L$" + (string)change + " change");
llGiveMoney(giver, change);
llGiveInventory(giver, llGetInventoryName(INVENTORY_TEXTURE, counter));
llInstantMessage(llGetOwner(), llKey2Name(giver) + " bought " + llGetInventoryName(INVENTORY_TEXTURE, counter) + " for L$" + (string)price);
}
else if (amount == price)
{
llGiveInventory(giver, llGetInventoryName(INVENTORY_TEXTURE, counter));
llInstantMessage(llGetOwner(), llKey2Name(giver) + " bought " + llGetInventoryName(INVENTORY_TEXTURE, counter) + " for L$" + (string)price);
}
}
on_rez(integer start_param)
{
llResetScript();
}
}


EDIT: Added touch-giving for when price is set to L$0
SeXXXy Bliss
SL Addict
Join date: 21 Dec 2004
Posts: 436
Discussion Thread:
05-29-2005 16:21
/54/05/48403/1.html