Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Networked Vending Machine

Clayton Cinquetti
Registered User
Join date: 17 May 2005
Posts: 38
01-24-2007 22:51
I am trying to build a networked vending machine. The way I want it to work is that an item placed in the inventory of any one of my vending machines appears for sale on any of the other vending machines in my network.

My question is that according to the LSL Guide llGiveInventory only works within one sim. What do I do if one of my vending machines is in another sim? How do I get my inventory there? How does SL Exchange do it?

(I have complete details of what I'm trying to build on my blog at www.secondlifehowto.com. Also, although this is just a hobby project, if anybody thinks they can just knock this out, I would be willing to pay for help.)
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
01-24-2007 23:01
its more like agent interacts with a client terminal somewhere in SL, sends data to a server object and that sends the inventory from server to AV

its also alot ezier to control inventory when its centralized in one point
Geuis Dassin
Filming Path creator
Join date: 3 May 2006
Posts: 565
01-24-2007 23:03
Read again my friend:

"Gives the named inventory item to the agent or object with the key destination. Objects have to be in the same sim but agents can recieve inventory regardless of where they are. "

You can give to anyone, anywhere. Its only objects that have that limitation.

On another note if you're looking for a good network vendor thats already out there I'm using Apez.biz, as was recommended to me by Nand Nerd. Works pretty good once you're setup.

Geuis
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
01-25-2007 00:39
The 'usual' system is to have a server somepalce in world.
This is the actual repository for all items.

The vendors are then reasonably dumb, just communicating with the server to display whats for sale.
When you walk up and buy something, the vendor sends your key and the id of the item to the server which then sends you the item.

Having each vendor having its own content is still possible, but could, read WILL, be a maintenance nightmare.

In this scenario when something new is deposited into any vendor, the vendor registers the update with the central server which then updates all the others as before. But it also maintains a list of where the item is held.

Now when you buy something the vendor first checks to see if the item is in its inventory, if it is it gives it to you.

If it isnt it contacts the central server. The central server checks its list of items against vendors and contacts the appropriate vendor which then gives you the item.

Hope that makes sense
Clayton Cinquetti
Registered User
Join date: 17 May 2005
Posts: 38
01-25-2007 12:43
Thanks. Both of these replys were helpful.

You're right, I was misreading the guide. I didn't realize that the limitation on being in the same sim was just for objects giving items to other objects. That definitely solves one of my problems. It still leaves open a second part of the problem.

I want an individual (other than me) to be able to add an item for sale to one vending machine and then have the advertisement for the item appear on all vending machines no matter where they are located including whether they are located in other sims. The act of getting the advertisement from one machine to the other still violates the rule preventing the giving of objects to other objects in the same sim.

One workaround that I could imagine is that I guess I could personally walk around to each of the vending machines and pick up the advetisements and pass them out to the others. But that sounds pretty bad. Does anyone have any better ideas?
Atashi Toshihiko
Frequently Befuddled
Join date: 7 Dec 2006
Posts: 1,423
01-25-2007 13:14
If the 'advertisement' is just a texture that has been uploaded then couldn't you pass the UUID of the texture through IM or email or whatever method you use to get info from one vender to another?

You don't need to move the texture itself, just send the appropriate UUID when you send the item's name and price.

-Atashi
Woopsy Dazy
Registered User
Join date: 12 Nov 2006
Posts: 173
01-25-2007 13:30
Be careful with notecards tho. They change UUID all the time (well sometimes). So better to store them in a server object. One place to administrate. I would force my sellers to Head Quarters to add items and textures. It's just a teleport away. And why not spam them with other offers while they are there ;)
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
01-26-2007 00:35
From: Clayton Cinquetti
Thanks. Both of these replys were helpful.

You're right, I was misreading the guide. I didn't realize that the limitation on being in the same sim was just for objects giving items to other objects. That definitely solves one of my problems. It still leaves open a second part of the problem.

I want an individual (other than me) to be able to add an item for sale to one vending machine and then have the advertisement for the item appear on all vending machines no matter where they are located including whether they are located in other sims. The act of getting the advertisement from one machine to the other still violates the rule preventing the giving of objects to other objects in the same sim.

One workaround that I could imagine is that I guess I could personally walk around to each of the vending machines and pick up the advetisements and pass them out to the others. But that sounds pretty bad. Does anyone have any better ideas?


As I said in my post you have the vendors pass the information back to the server NOT the Object. The Server them propogates it around to all the other vendors. As Atashi stated, if the advert is a texture then pass back the UUID so that others can use it.

Notecard's change UUID when ever they are edited and then saved, so once dropped they should be static.
Yumi Murakami
DoIt!AttachTheEarOfACat!
Join date: 27 Sep 2005
Posts: 6,860
01-26-2007 07:31
From: Clayton Cinquetti
I want an individual (other than me) to be able to add an item for sale to one vending machine and then have the advertisement for the item appear on all vending machines no matter where they are located including whether they are located in other sims. The act of getting the advertisement from one machine to the other still violates the rule preventing the giving of objects to other objects in the same sim.


In this case, essentially every single vending machine has to act as a server as well as a client.

You could have a single server, which is your item catalogue. When a new item is added to a vendor (let's call it the "hosting vendor";), it calls the catalogue server, and includes its own (that is, the hosting vendor's) key in the catalogue entry. Then when the item is sold, the vendor from which the purchase is made reads the key of the hosting vendor from the catalogue entry and sends it a message saying "deliver the object to this person".

Bear in mind that it is not possible to safely design a vendor which allows other people to add objects automatically. The problem is permissions: when they put the item into your vendor, that's a transfer (because it's going into your ownership). Because it's a transfer, the item will switch to "next owner" permissions. Thus if the "next owner" permissions don't include copy and transfer, then the vendor can't sell the item. But if the "next owner" permissions do include copy and transfer, then they still will when the item is sold to a customer (unfortunately scripts can't change permissions), and the customer will get to hand out free copies to all and sundry.
Clayton Cinquetti
Registered User
Join date: 17 May 2005
Posts: 38
Simple Networked Vending Machine Demo
02-04-2007 14:30
I've started working on creating my networked vending machine. The code below is demo code that I used to confirm what people said above about being able to sell things across sims. I'll summarize my progress here. There is more information if your interested on my blog www.secondlifehowto.com.

What I’ve created and described below is a demo of a vending machine where the purchase is made at one vending machine and the item is delivered to the purchaser from a different central vending machine server. All the remote server has is a notecard which describes the item in the central server.

There are two scripts used in this demo: RemoteVendor.lsl and VendorServer.lsl. I’ll describe each of them here.

RemoteVendor.lsl
This script does the following:
1. Starts up and reads the notecard SaleItem1. I’ve hard coded this demo for one sales item for simplicity. A real version would obviously have multiple items.
2. Based on the data in the SaleItem1 notecard it puts a short description of the item for sale above the vending machine in red hover text and puts the price just below it. It also sets the pay price for the item.
3. When a purchaser pays the vending machine an email is sent to the central server. The email contains the key of the person who paid and the name of the purchased item.

VendorServer.lsl
This script does the following:
1. Starts up and says the key of the vendor server object. (This is required so that you can fill out the notecard for the item you want to sell with the original vendor of the item for sale.)
2. Starts up a timer that regularly checks email.
3. Up receipt of an email, it parses the email, determines who bought what and gives it to them.

Remote Vendor Code:
CODE

// Detailed explination of this script can be found at www.secondlifehowto.com
// This is a simplified demo of a remote vendor that sells an item located at a central
// vendor. This example is hard coded to sell one item that is described in a notecard
// that is hand placed in this vendor object.

list gCurrentItemBeingDisplayed=[];
integer ITEM_DISPLAYED_SHORT_DESCRIPTION_INDEX = 0;
integer ITEM_DISPLAYED_PRICE_INDEX = 1;
integer ITEM_DISPLAYED_ORIGINAL_VENDOR_KEY_INDEX = 2;
integer ITEM_DISPLAYED_ITEM_NAME_INDEX = 3;

string gCurrentItemNoteCardName = "SaleItem1";
key gIdCurrentNoteCardQuery;
integer gLineCurrentNoteCardQuery=0;

default
{
//--------------------------------------------------------------
// On startup, a request is made to read the first line of a notecard. This eventually causes
// a call to be made to dataserver with the resulting line. From there dataserver will read the
// rest of the items
//--------------------------------------------------------------
state_entry()
{
// Start read of notecard
gIdCurrentNoteCardQuery = llGetNotecardLine(gCurrentItemNoteCardName, gLineCurrentNoteCardQuery);
}

//--------------------------------------------------------------
// dataserver is called whenever a line is read out from a notecard. The call within this
// event to llGetNotecardLine continues the read of the notecard in a loop until End Of File
// is reached
//--------------------------------------------------------------
dataserver(key query_id, string data)
{
if (query_id == gIdCurrentNoteCardQuery)
{
if (data != EOF)
{
// Notecard is structured line by line to correspond with the items to go in the
// gCurrentItemBeingDisplayed list, so add it to the list line by line
gCurrentItemBeingDisplayed += data;
gLineCurrentNoteCardQuery++; // increase line count
gIdCurrentNoteCardQuery = llGetNotecardLine(gCurrentItemNoteCardName, gLineCurrentNoteCardQuery); // request next line
}
else
{
// We've reached the end of the notecard and should have copied everything into our list
// Now update the display
string description = llList2String(gCurrentItemBeingDisplayed, ITEM_DISPLAYED_SHORT_DESCRIPTION_INDEX);
string price = llList2String(gCurrentItemBeingDisplayed, ITEM_DISPLAYED_PRICE_INDEX);
llSetText(description + "\nL$"+price, <1,0,0>, 1.0);

// Now set the pay price
llSetPayPrice(PAY_HIDE, [(integer)price, PAY_HIDE, PAY_HIDE, PAY_HIDE]);
}
}
}

//--------------------------------------------------------------
// This function is activated when someone pays the points dispenser
// it only takes the givers money if they have a HUD active
//--------------------------------------------------------------
money(key giver, integer amount)
{
string price_string = llList2String(gCurrentItemBeingDisplayed, ITEM_DISPLAYED_PRICE_INDEX);

if (amount >= (integer) price_string)
{
string item_name = llList2String(gCurrentItemBeingDisplayed, ITEM_DISPLAYED_ITEM_NAME_INDEX);
string original_vendor = llList2String(gCurrentItemBeingDisplayed, ITEM_DISPLAYED_ORIGINAL_VENDOR_KEY_INDEX);
llEmail(original_vendor + "@lsl.secondlife.com", "Purchase", item_name + "," + (string)giver);
}

}

}


Vendor Server Code:
CODE

// Detailed explination of this script can be found at www.secondlifehowto.com
// This is a simplified demo of a remote vendor that sells an item located at a central
// server. This server has no security. It just hands out the object to anyone that
// emails it the name of an item it has and the key of who it should go to
default
{

//------------------------------------------------------------------------------------
//On startup the server states it's key. This key is required for making sale item
//notecards
//------------------------------------------------------------------------------------
state_entry()
{
llWhisper(0, "VendorServer Key is " + (string)llGetKey());
llSetTimerEvent(2.5); // Poll for emails.

}

//------------------------------------------------------------------------------------
//Every time the timer expires, check for emails
//------------------------------------------------------------------------------------
timer()
{
llGetNextEmail("", "Purchase"); // Check for email with any sender address and subject.
}

//------------------------------------------------------------------------------------
//If we get an email, hand out the specified item
//------------------------------------------------------------------------------------
email(string time, string address, string subj, string message, integer num_left)
{

// Remove the header
message = llDeleteSubString(message, 0, llSubStringIndex(message, "\n\n") + 1);

// Break of the message
list purchase_request = llParseString2List(message,[","],[" "]);
string item_name = llList2String(purchase_request, 0);
key purchasers_key = (key) llList2String(purchase_request, 1);

// Debug
llWhisper(0,"item name: " + item_name);
llWhisper(0,"purchasers_key: " + (string) purchasers_key);

// give item specified in the email to person described in email
llGiveInventory(purchasers_key,item_name);
}


}