integer item = 0;
integer maxitem;
integer price = 0;
integer line;
integer last_item;
string texture = "";
integer debug = FALSE;
string listitem = "null";
string note = "Inventory";
string name;
list inven;
list prices;
key query_id;
string title = "Jesus Vendor";
default
{
state_entry()
{
llSetTexture("d2665d83-d5f5-d0a8-7fb7-89656f2d3f7a",ALL_SIDES);
llSetText("OFFLINE MODE!\nAdd/Remove items safely,\nThen click to start.",<1,1,1>,1);
}
touch_start(integer total_number)
{
state run;
}
}
state run
{
state_entry()
{
query_id = llGetNotecardLine(note, 0);
}
touch_start(integer total_number)
{
item += 1;
@debug2;
if (debug == TRUE)
{
item = last_item;
debug = FALSE;
}
if (item > maxitem)
{
item = 0;
}
listitem = llList2String(inven,item);
string tempstring;
string tempstring2;
integer slen = llStringLength(listitem);
integer found = FALSE;
integer number = FALSE;
integer i = 0;
tempstring = listitem;
if (tempstring == ""

{
debug = TRUE;
jump debug2;
}
while (tempstring != ":"

{
tempstring = llGetSubString(listitem, i,i);
tempstring2 += tempstring;
i++;
}
listitem = tempstring2;
slen = llStringLength(listitem);
slen -= 2;
listitem = llGetSubString(listitem, 0, slen);
texture = listitem;
texture += "PIC";
llSetTexture(texture, ALL_SIDES);
llSetText(""+title+"\n"+listitem+"\nPrice: L$"+llList2String(prices, item)+"",<1,1,1>,1);
last_item = item;
}
changed(integer type)
{
if(type & CHANGED_INVENTORY)
{
llOwnerSay("Inventory has changed. the vendor has to reset now. Going offline..."

;
llResetScript();
}
}
dataserver(key queryid, string data)
{
if (query_id == queryid) {
if (data != EOF) {
query_id = llGetNotecardLine(note, line);
string tempstring;
string tempstring2;
integer slen = llStringLength(data);
integer found = FALSE;
integer number = FALSE;
integer i = 0;
for (i = 0; i <= slen; i++)
{
tempstring =llGetSubString(data, i,i);
llSetText("Reading Notecard. Please wait.",<1,1,1>,1);
if (tempstring == ":"
{
found = TRUE;
}
if (found == TRUE)
{
tempstring2 += tempstring;
}
}
prices = prices + [llGetSubString(tempstring2,1,-1)];
inven = inven + [data];
line++;
}
else
{
inven = llDeleteSubList(inven, 0,0);
prices = llDeleteSubList(prices, 0,0);
maxitem = llGetListLength(inven) - 1;
llRequestPermissions(llGetOwner(), PERMISSION_DEBIT);
llOwnerSay("Vendor is ready to go."

;
item = 0;
llSetTexture("733b86a4-576a-e62f-5f07-017fd00f1a50",ALL_SIDES);
llSetText("READY! Touch to browse vendor!",<1,1,1>,1);
last_item = item;
}
}
}
money(key id, integer amount)
{
integer cost = (integer)llList2String(prices, item);
if (amount == cost)
{
llInstantMessage(id,"Thank you for your purchase!"

;
llGiveInventory(id,listitem);
}
if (amount > cost)
{
integer change =0;
llInstantMessage(id,"Here is your change. Thank you for your purchase."

;
llGiveInventory(id,listitem);
change = amount - cost;
llGiveMoney(id, change);
}
if (amount < cost)
{
llInstantMessage(id, "I'm sorry, but that is not enough for the item."

;
llGiveMoney(id, amount);
}
}
run_time_permissions(integer perm)
{
if (perm & PERMISSION_DEBIT)
{
}
else
{
llOwnerSay("Sorry, you must click [Yes] in order for this to work. Please re-rez your Vendor."

;
state black_hole;
}
}
}
state black_hole
{
on_rez(integer start_param)
{
llResetScript();
}
}