Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Enhanced Single-Item, Single-Prim Item Vendor

Mark Assia
'Eeeeeeeey.
Join date: 10 Jul 2005
Posts: 26
08-02-2006 02:55
This is my first submission to the library, so I might as well make it a useful one. Earlier today I was building a new storefront and wondered how cool it'd be to have the vendors in my storefront interact (sort-of) with my SLExchange listings for all of my items. So, I tossed my clunky JEVN vendor aside and sat down for an hour in front of Wednesday Grimm's Single Item vendor script.

After an hour of recoding and tweaking, I couldn't be happier to release my finished script for free to the masses.

It's pretty well documented, at least in the parts that you should edit. Here's somewhat of a flowchart of what it does:

1. First thing's first - Variable-modifying in the state_entry.
-Checks to see if the string "gItemURL" is defined as an actual URL.
-If not, it disregards all llLoadURL and listen functionality. (Disabling the listen helps to reduce lag)
-If so, it checks the settings and determines which link it's pointing to by reading the domain name. Supported marketplaces at this time are SLExchange, SLBoutique and Gigas.
-After determining the destination, it selects the proper verbal cue for loading the listing URL. It then modifies the second item summary to inform the customer of the verbal cue.

3. On touch, it checks to see if there's a domain name present.
-If so, the object will place the item info in a dialog box and present that to the customer, along with the option to load the URL.
-If not, the object will M the detected avatar with the two summary lines.

4. On request (via dialog), the object will perform llLoadURL.

5. Upon payment, the object will check the item's price. It will determine whether the paid amount is higher, lower or correct. This is practically impossible as Fast Pay is the only payment option. I've left the lower and higher functions in there just in case there's some sort of Fast Pay loophole that a customer unknowingly found.
-If correct, delivery proceeds normally. The object will IM the buyer and thank them using their first name.
-If lower, the object will refund the money and notify the buyer of the low payment and how short they are of the total price.
-If higher, delivery will continue as if the payment was correct, and the correct change will be refunded.

Without further adieu... ;)
EDIT: The updated Sans-Sensor version... :)
CODE

//Adapted from an original Single Item, One Prim Vendor script written by Wednesday Grimm. Modifications and new features added by Mark Assia.
//Not for resale unless adapted to a commercial product and adequate changes to this script have been made.
integer gPrice = 50; // EDIT THIS! Cost of the item
string gItemURL = "http://www.slexchange.com/modules.php?name=Marketplace&file=item&ItemID=21411"; //EDIT THIS! The URL of your item's listing. Leaving this as "" will disable all Marketplace functions in this vendor. Make sure you include the full "http://www." before the domain name! Putting just "slexchange.com", for example, will confuse the vendor!

string itemName = "Generic Widget v1.0";
string summary1 = "Spiff up your whatchamacallit with this doohickey!";
string summary2 = "L$50";
//Don't touch anything below this unless you know what you're doing!
key agentkey;
string gMktplc;
string gAgentname;
integer CHANNEL;
list MENU_MAIN = ["Load URL"];
dispense(key toWhom)
{
llGiveInventory(toWhom, itemName);
}

default
{
state_entry()
{
CHANNEL = (integer)llFrand(-2147483648);
llListen(CHANNEL, "", "", "");
llSetPayPrice(gPrice, [gPrice]);
llRequestPermissions(llGetOwner(), PERMISSION_DEBIT);
if (gItemURL != "")
{
if (llGetSubString(gItemURL, 0, 25) == "http://www.slexchange.com/")
gMktplc = "SL Exchange";
else if (llGetSubString(gItemURL, 0, 25) == "http://www.slboutique.com/")
gMktplc = "SL Boutique";
else if (llGetSubString(gItemURL, 0, 27) == "http://www.secondserver.net/")
gMktplc = "Gigas/SecondServer";
}
}
touch_end(integer total_number)
{
key id = llDetectedKey(0);
if (gItemURL != "")
{
llDialog(id, itemName + "\n\n" + summary1 + "\n\n" + summary2 + "\n\nL$" + (string)gPrice, MENU_MAIN, CHANNEL);
}
else
{
llInstantMessage(id, summary1);
llInstantMessage(id, summary2);
}
}
listen(integer channel, string name, key id, string message)
{
if (message == "Load URL")
llLoadURL(id, "You have requested to load a listing from " + gMktplc + ". Continue?", gItemURL);
}


money(key id, integer amt)
{
string firstname = llDeleteSubString(llKey2Name(id), llSubStringIndex(llKey2Name(id), " "), -1);
if (amt == gPrice)
{
dispense(id);
llInstantMessage(id, "Thank you for your purchase, " + firstname + "!");
}
else if (amt < gPrice)
{
integer short = gPrice - amt;
llGiveMoney(id, amt);
llInstantMessage(id, "Sorry, you have not paid the full total of this purchase. You are short of the sale price by L$" + (string)short + ".");
}
else
{
integer change = amt - gPrice;
dispense(id);
llInstantMessage(id, "You have overpaid. I will dispense your change now. Thank you for your purchase, " + firstname + "!");
llGiveMoney(id, change);
}
}
}
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Discussion Thread
08-02-2006 22:59
/54/da/126670/1.html
_____________________
i've got nothing. ;)
Mark Assia
'Eeeeeeeey.
Join date: 10 Jul 2005
Posts: 26
Sans-Sensor
08-03-2006 03:54
Sans-Sensor Version:
-Removed laggy sensor and In-Range feature
-Added dialog. If a URL is present, information will be given via dialog on-touch. If not, information will be IMed to the customer.
-Fixed error with change function (or rather, lack thereof).
-Added Fast Pay as the only option for payment. Leaving in the change/refund features just in case there's a way to work around Fast Pay that I haven't discovered yet.

CODE

//Adapted from an original Single Item, One Prim Vendor script written by Wednesday Grimm. Modifications and new features added by Mark Assia.
//Not for resale unless adapted to a commercial product and adequate changes to this script have been made.
integer gPrice = 50; // EDIT THIS! Cost of the item
string gItemURL = "http://www.slexchange.com/modules.php?name=Marketplace&file=item&ItemID=21411"; //EDIT THIS! The URL of your item's listing. Leaving this as "" will disable all Marketplace functions in this vendor. Make sure you include the full "http://www." before the domain name! Putting just "slexchange.com", for example, will confuse the vendor!

string itemName = "Generic Widget v1.0";
string summary1 = "Spiff up your whatchamacallit with this doohickey!";
string summary2 = "L$50";
//Don't touch anything below this unless you know what you're doing!
key agentkey;
string gMktplc;
string gAgentname;
integer CHANNEL;
list MENU_MAIN = ["Load URL"];
dispense(key toWhom)
{
llGiveInventory(toWhom, itemName);
}

default
{
state_entry()
{
CHANNEL = (integer)llFrand(-2147483648);
llListen(CHANNEL, "", "", "");
llSetPayPrice(gPrice, [gPrice]);
llRequestPermissions(llGetOwner(), PERMISSION_DEBIT);
if (gItemURL != "")
{
if (llGetSubString(gItemURL, 0, 25) == "http://www.slexchange.com/")
gMktplc = "SL Exchange";
else if (llGetSubString(gItemURL, 0, 25) == "http://www.slboutique.com/")
gMktplc = "SL Boutique";
else if (llGetSubString(gItemURL, 0, 27) == "http://www.secondserver.net/")
gMktplc = "Gigas/SecondServer";
}
}
touch_end(integer total_number)
{
key id = llDetectedKey(0);
if (gItemURL != "")
{
llDialog(id, itemName + "\n\n" + summary1 + "\n\n" + summary2 + "\n\nL$" + (string)gPrice, MENU_MAIN, CHANNEL);
}
else
{
llInstantMessage(id, summary1);
llInstantMessage(id, summary2);
}
}
listen(integer channel, string name, key id, string message)
{
if (message == "Load URL")
llLoadURL(id, "You have requested to load a listing from " + gMktplc + ". Continue?", gItemURL);
}


money(key id, integer amt)
{
string firstname = llDeleteSubString(llKey2Name(id), llSubStringIndex(llKey2Name(id), " "), -1);
if (amt == gPrice)
{
dispense(id);
llInstantMessage(id, "Thank you for your purchase, " + firstname + "!");
}
else if (amt < gPrice)
{
integer short = gPrice - amt;
llGiveMoney(id, amt);
llInstantMessage(id, "Sorry, you have not paid the full total of this purchase. You are short of the sale price by L$" + (string)short + ".");
}
else
{
integer change = amt - gPrice;
dispense(id);
llInstantMessage(id, "You have overpaid. I will dispense your change now. Thank you for your purchase, " + firstname + "!");
llGiveMoney(id, change);
}
}
}