Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Discussion: Cart Vendor

Talia Tokugawa
Registered User
Join date: 22 Mar 2005
Posts: 9
05-03-2007 22:31
Okay.. this is possibly the first cart vendor I know of in sl, I made it because I couldn't face making 24 sales textures for a range of jewelry I made, then the simple vendor I started with evolved into something a little more unique..

Features:

Bulk discounts: 10% on two items and an extra 5% for each item after that, so maximum of 30% on 6 items. This I feel is the main "selling" point of this vendor. It encourages people to buy more items in one go. ;)

Locked cart: To stop multiple people using the vendor at the same time and screwing up each others purchases, once one person has made an addition to the cart then all functions of the vendor will get locked for anyone else. There is a timeout based on the number of button presses to fill the cart. (more effort you put into making your selection the longer the timeout).

Supports Split profits : add details to vendor description "key1,%1,key2,%2,key3,%3", this will go four ways if you include the vendor owner.


The Prim-work:
On the model I use for this I have 6 prims..
The Main Prim is the one the main script goes into. You want face one facing forward. Name the prim whatever the vendor is called and make sure this is the master prim.

The forward and back buttons, These need to be called "<" and ">" respectively. I made these into triangles either side of the main prim.

The Cart Prims, these are cubes that have been tapered and flattened so you can see three faces from the front.. (faces 0 2 and 4).. my settings for these are x:0.48 y:0.16 z:0.01 and then X taper set to 0.66. Both of these prim I named "-", as pressing these prims will clear the cart.

The Frame, this prim isn't strictly necessary, although to get rid of it you will need to change some things in the script. Main reason for this prim is so I could use snapshots for the product images and not have to play around with photoshop for hours. I made one tga border for the front of this prim. This prim should go in front of the main prim and you should call it "+" as it's what people press to add things to the cart.

you should have something like this.....

back
| mainprim and frame
| _|_
<|__|> <forward
[][][] <cart prim 1
[][][] <cart prim 2

Usage:
To use you just need to add objects and textures.. and probably reset the script.
Name the objects what ever you want, and then name the textures the same name as the object they represent but with ",price" at the end, eg. "sampleobject.100" would be the name of a texture representing the item "sampleobject".
You also will need the change the extras list on line 11. This is for items that will need to be included in all sales. At the moment it's set to give people the landmark to my island "T3://Island., Opus (125, 135, 29)", so another example of what you could put here would be something like:
CODE

list extras=[
"landmark main store",
"notecard of info"
];


Don't add objects or textures into the list as I am pretty sure they will stop the vendor working properly...

Customer Usage:
The customer just needs to press forward and back to find the items they want. Press the main image to add an item to the cart. Press the cart to clear it. Pay the vendor to receive the contents of the cart. They will get the items in a folder the same name as the vendor, with what ever is in the extras list.


Main Script:
CODE

list cart=[];
integer cartPrice=0;
integer discPrice=0;
integer price=0;
integer current=0;
key cartOwner=NULL_KEY;
list c=[];
list cKey=[];
list cPer=[];
integer setup=0;
integer timeout=0;
list extras=[
"T3://Island., Opus (125, 135, 29)"
];

set()
{
list temp=llCSV2List(llGetInventoryName(INVENTORY_TEXTURE, current));
price=(integer)llList2String(temp, 1);
llSetText((string)(current + 1) + "/" + (string)(llGetInventoryNumber(INVENTORY_OBJECT)) + "\n" + llGetInventoryName(INVENTORY_OBJECT, current) + "\n l$" + (string)price + "\n touch to add to cart", <1,1,1>, 1.0);
llSetTexture(llGetInventoryName(INVENTORY_TEXTURE, current), 1);
}

init()
{
llMessageLinked(LINK_SET, 0, "", "");
llRequestPermissions ( llGetOwner(), PERMISSION_DEBIT );
}

default
{
state_entry()
{
init();
}

on_rez(integer p)
{
llResetScript();
}

run_time_permissions( integer perm )
{
if ( (perm && PERMISSION_DEBIT) )
{
state ready;
}
else
{
llOwnerSay ( "To share proceeds I must have give money(DEBIT) permissions");
llOwnerSay ( "Try again");
llResetScript();
}
}
}

state ready
{
state_entry()
{
current=0;
list temp = llCSV2List(llGetObjectDesc());
cKey=[];
cPer=[];
c=[];
cKey += llList2String(temp,0);
cPer += (float)llList2String(temp,1);
cKey += llList2String(temp,2);
cPer += (float)llList2String(temp,3);
cKey += llList2String(temp,4);
cPer += (float)llList2String(temp,5);
llRequestAgentData ( llList2String(cKey,0), DATA_NAME );
llOwnerSay("Online::" + (string)llGetInventoryNumber(INVENTORY_OBJECT) + " items found");
llMessageLinked(LINK_SET, -1, "Cart Empty", "");
set();
llSleep(0.66);
}

dataserver( key id, string NAME )
{
c+=NAME;
if (NAME!="") llOwnerSay(NAME + " will recieve " + (string)((integer)llList2Float(cPer, setup)) + "% of sales from this vendor.");
++setup;
if (setup<=2)
{
llRequestAgentData ( llList2String(cKey,setup), DATA_NAME );
}
}

touch_start(integer total_number)
{
timeout+=1;
string touched=llGetLinkName(llDetectedLinkNumber(0));
integer num=llGetInventoryNumber(INVENTORY_OBJECT);
integer total=llGetListLength(cart);
if (cartOwner==NULL_KEY||cartOwner==llDetectedKey(0))
{
if (touched=="<")
{
--current;
if (current==-1) current=num - 1;
set();
}
else if (touched==">")
{
++current;
if (current==num) current=0;
set();
}
else if (touched=="+"&&llGetListLength(cart)!=6)
{
cartOwner=llDetectedKey(0);
cart=(cart=[]) + cart + llGetInventoryName(INVENTORY_OBJECT, current);
cartPrice+=price;
total=llGetListLength(cart);
llMessageLinked(LINK_SET, total, "", llGetInventoryKey(llGetInventoryName(INVENTORY_TEXTURE, current)));
float disc=llGetListLength(cart) * 0.05;
if (llGetListLength(cart)==1) disc=0;
discPrice=(integer)(cartPrice * (1 - disc));
if (discPrice!=0) llSetPayPrice(PAY_HIDE, [discPrice, PAY_HIDE, PAY_HIDE, PAY_HIDE]);
llMessageLinked(LINK_SET, -1, "Items: " + (string)total + "\n Discount: " + (string)((integer)(disc * 100)) + "% \n Total: " + (string)discPrice + "l$ \n Cart Owner: " + llKey2Name(cartOwner) + "\n touch to clear cart", "");
}
else if (touched=="+"&&total==6)
{
llInstantMessage(llDetectedKey(0), "Cart Full, pay or touch cart to empty.");
}
else if (touched=="-")
{
cartOwner=NULL_KEY;
cart=[];
cartPrice=0;
llMessageLinked(LINK_SET, 0, "", "");
llMessageLinked(LINK_SET, -1, "Cart Empty", "");
timeout=0;
llSetTimerEvent(0.0);
}
else set();
llSetTimerEvent(15.0);
}
}

timer()
{
--timeout;
if (timeout==0)
{
llSetTimerEvent(0.0);
cartOwner=NULL_KEY;
cart=[];
cartPrice=0;
llMessageLinked(LINK_SET, 0, "", "");
llMessageLinked(LINK_SET, -1, "Cart Empty", "");
}
else if (timeout==1&&cart!=[])
{
llWhisper(0, "Cart will timeout in 15 seconds");
}
}

money ( key id, integer amount )
{
if ( amount != discPrice )
{
llInstantMessage( id, "Sorry the price for this item is " + (string)discPrice +". Your payment has been refunded");
llGiveMoney( id, amount );
return;
}
llGiveInventoryList( id, llGetObjectName(), extras + cart );
llInstantMessage ( id, "Thank you for your purchase - We hope you enjoy");
float calc = amount + 0.0;
integer x=0;
while (x<=2)
{
float a = calc * (llList2Float(cPer, x) / 100);
if (a!=0)
{
llGiveMoney((key)llList2String(cKey, x), (integer)a);
llInstantMessage((key)llList2String(cKey, x), "You have been paid " + (string)((integer)a) + "l$ for the sale of: " + llList2CSV(cart) + " in " + llGetRegionName());
}
++x;
}
llOwnerSay("The items: " + llList2CSV(cart) + " were sold from " + llGetObjectName() + " in " + llGetRegionName());
cart=[];
cartPrice=0;
llMessageLinked(LINK_SET, 0, "", "");
llMessageLinked(LINK_SET, -1, "Cart Empty", "");
timeout=0;
llSetTimerEvent(0.0);
cartOwner=NULL_KEY;
}
}

Cart Panel 1
CODE

default
{
link_message(integer sn, integer n, string m, key id)
{
if (n==-1)
{
llSetText(m, <1,1,1>, 0.8);
}
else if (n==0)
{
llSetColor(<0,0,0>, 4);
llSetColor(<0,0,0>, 2);
llSetColor(<0,0,0>, 0);
}
else if (n==1)
{
llSetTexture(id, 4);
llSetColor(<1,1,1>, 4);
}
else if (n==2)
{
llSetTexture(id, 0);
llSetColor(<1,1,1>, 0);
}
else if (n==3)
{
llSetTexture(id, 2);
llSetColor(<1,1,1>, 2);
}
}
}

Cart Panel 2
CODE

default
{
link_message(integer sn, integer n, string m, key id)
{
if (n==0)
{
llSetColor(<0,0,0>, 4);
llSetColor(<0,0,0>, 2);
llSetColor(<0,0,0>, 0);
}
else if (n==4)
{
llSetTexture(id, 4);
llSetColor(<1,1,1>, 4);
}
else if (n==5)
{
llSetTexture(id, 0);
llSetColor(<1,1,1>, 0);
}
else if (n==6)
{
llSetTexture(id, 2);
llSetColor(<1,1,1>, 2);
}
}
}
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Original Thread
05-10-2007 00:08
/15/1e/181594/1.html
_____________________
i've got nothing. ;)
Milambus Oh
Registered User
Join date: 6 Apr 2007
Posts: 224
05-10-2007 05:51
Is there someplace we can pickup a working version of this in world, so that we don't have to recreate the prims?
Janttu Winkler
Registered User
Join date: 21 May 2007
Posts: 1
What does this mean?
07-23-2007 08:26
Hi.

I'm having problems with this part:
The Cart Prims, these are cubes that have been tapered and flattened so you can see three faces from the front.. (faces 0 2 and 4).. my settings for these are x:0.48 y:0.16 z:0.01 and then X taper set to 0.66. Both of these prim I named "-", as pressing these prims will clear the cart.

What to do excactly now?

Thank you already :).