Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Discussion: Quick and Dirty Vendor

Jim Guyot
Tinkerer
Join date: 21 Apr 2007
Posts: 38
06-03-2007 21:10
I am posting my Quick and Dirty Vendor here. I hope someone finds good use from it.

One caveat:
The _DATA notecard needs to be in the following format:
Object Name,Price

No space between the comma and the price. And make sure the sale texture is the Object Name with 'PIC' suffixed to it.
CODE

// Quick & Dirty Vendor Script
// By: Jim Guyot
//

integer _N;
list data = [];
integer curr;
string _D = "_DATA";

list parse( integer i ){return llCSV2List( llList2String( data, i ) );}

string form( list l ) {return llList2String( l, 0 ) + "\nL$" + llList2String( l, 1 );}

default{
state_entry() {
llOwnerSay( "Loading.." );
llGetNumberOfNotecardLines( _D );}
on_rez( integer n ){llResetScript();}
dataserver( key k, string s ){
_N = (integer) s;
state load;}}
state load{
state_entry() {
curr = 0;
llGetNotecardLine( _D, curr );}
on_rez( integer n ){llResetScript();}
dataserver( key k, string s ){
if ( s != EOF ){
data += [ s ];
curr++;
llGetNotecardLine( _D, curr );}
else {
state sell;}}}
state sell{
state_entry() {
curr = 0;
llRequestPermissions( llGetOwner(), PERMISSION_DEBIT );
list tempList = parse( curr );
llSetText( form( tempList ), <1,1,1>, 1.0 );
llSetTexture( llList2String( tempList, 0 ) + "PIC", ALL_SIDES );}
on_rez( integer n ){llResetScript();}
run_time_permissions( integer perms ){
if ( !( perms & PERMISSION_DEBIT ) ) llResetScript();}
changed( integer params ){
if ( params & CHANGED_INVENTORY ) llResetScript();}
money( key k, integer i ){
list tempList = parse( curr );
integer tempInt = llList2Integer( tempList, 1 );
if ( i < tempInt ){
llSay( 0, "The item you are purchasing has a higher price than the amount given. Refunding Lindens." );
llGiveMoney( k, i );}
if ( i == tempInt ){
llSay( 0, "Thank you for your purchase." );
llGiveInventory( k, llList2String( tempList, 0 ) );}
if ( i > tempInt ){
llSay( 0, "Thank you for your purchase. As you have overpaid, you will be refunded the balance." );
llGiveInventory( k, llList2String( tempList, 0 ) );
i = i - tempInt;
llGiveMoney( k, i );}}
touch_start( integer n ){
curr++;
if ( curr == _N ) curr = 0;
list tempList = parse( curr );
llSetText( form( tempList ), <1,1,1>, 1.0 );
llSetTexture( llList2String( tempList, 0 ) + "PIC", ALL_SIDES );}}


Good luck and have fun.
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Original Thread
06-04-2007 22:05
/15/4f/188476/1.html
_____________________
i've got nothing. ;)