Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Discussion: Passive (no lag) Vendor

Wolf Rocco
Registered User
Join date: 31 Dec 2004
Posts: 38
07-15-2005 20:21
Yep all passive when not in use, this wont show up on the active scanner when its idle.

This vendor was intended to replace hiro's vendor for funtionality but still remain passive.

I'll post 3 kinds here Turn key, Halo, and an animations vendor (the sit kind)


First thing is the Turn key

MainVendor Code
CODE

//No Lag vendor (no listens... PERIOD!)
//Doesn't use reasources when not being paid
//Maximum handling is about 20 objects don't go crazy ;)
//Designed to be a heavy setup but super light running script

//Variables (editable)
integer sell_type = INVENTORY_OBJECT; //The type of items the vendor will be tracking
vector text_color = <1,1,1>; //White color
float text_alpha = 1; //Alpha set text is at

//System Variables (DO NOT TOUCH!!!)
list items;
list descriptions;
list prices;
list times_sold;
list last_sold;
integer notecardline;
integer current_item;

//Functions
//Help
//ListTop10
//ListLast10
//ListBottom10
//ListBestSeller
//ListWorstSeller


//Scroll to the next item with a roll over
Next_Item()
{
//Update current_item
current_item++;

//Check for overlap
if(current_item >= llGetListLength(items))
{
current_item = 0;
}

//Setup the item
llMessageLinked(LINK_SET,10,llList2String(descriptions,current_item) + "\n$L" + llList2String(prices,current_item),NULL_KEY);
llSetTexture(llList2String(items,current_item) + "PIC",0);
}

//List the last item with a roll over
Prev_Item()
{
//Update current_item
current_item--;

//Check for overlap
if(current_item < 0)
{
current_item = llGetListLength(items) - 1;
}

//Setup the item
llMessageLinked(LINK_SET,10,llList2String(descriptions,current_item) + "\n$L" + llList2String(prices,current_item),NULL_KEY);
llSetTexture(llList2String(items,current_item) + "PIC",0);
}

//Tell the owner how to use this sucker
Show_Help()
{
//Give some advice
llOwnerSay("This is a notecard based vendor, meaning that you follow a notecard format to enter items");
llOwnerSay("When the items are inside the vendor touch the selling screen (the big one) to start the vendor up.");
llOwnerSay("All items need a picture associated with them with the same name and PIC at the end like the demo objects.");
llOwnerSay("If you add/remove items to the vendor it will be forced into setup mode again.");
llOwnerSay("This is the green (help) button the others are as follows.");
llOwnerSay("Blue is the last 10 items sold.");
llOwnerSay("Yellow is the top 10 items sold.");
llOwnerSay("Red is the worst 10 items sold.");

}

//List the last 10 items sold
Last_10()
{
//Variables
integer i;

//Say the title
llOwnerSay("Last 10 items sold:");

//For each item in the list tell the owner the name
for(i=0; i<llGetListLength(last_sold); i++)
{
llOwnerSay((string)i + " - " + llList2String(items,llList2Integer(last_sold,i)));
}
}

//Top 10 sellers
Top_10()
{
//Variables
list temp;
integer i;
integer stop;

//need a strided list for all this crap so lets make a temp one
for(i=0; i<llGetListLength(times_sold); i++)
{
temp += [llList2Integer(times_sold,i)];
temp += ;
}

//Sort the list decending
temp = llListSort(temp,2,FALSE);

//How long is the list? if its too short we'll just set the end to the end of the list
if(llGetListLength(times_sold) < 10)
{
stop = llGetListLength(temp);
}

//Say the title
llOwnerSay("Top 10 items sold:";);

//List the top 10 now
for(i=0; i<stop; i++)
{
llOwnerSay((string)(i/2) + " - " + llList2String(items,llList2Integer(temp,i+1)) + " sold " + llList2String(temp,i) + " times.";);
i++;
}

}

//Worst 10 sellers hehe the irony!
Worst_10()
{
//Variables
list temp;
integer i;
integer stop;

//need a strided list for all this crap so lets make a temp one
for(i=0; i<llGetListLength(times_sold); i++)
{
temp += [llList2Integer(times_sold,i)];
temp += ;
}

//Sort the list accending
temp = llListSort(temp,2,TRUE);

//How long is the list? if its too short we'll just set the end to the end of the list
if(llGetListLength(times_sold) < 10)
{
stop = llGetListLength(temp);
}


//Say the title
llOwnerSay("Worst 10 items sold:";);

//List the worst 10 now
for(i=0; i<stop; i++)
{
llOwnerSay((string)(i/2) + " - " + llList2String(items,llList2Integer(temp,i+1)) + " sold " + llList2String(temp,i) + " times.";);
i++;
}
}


//The Setup State (check all lists) add / remove items
default
{
state_entry()
{
//Waiting for items or setup
llMessageLinked(LINK_SET,10,"",NULL_KEY);
llSetText("Setup mode waiting for items, touch the main panel to begin setup checks",text_color,text_alpha);

//Black Background for no item to show ;)
llSetTexture("5fca20ad-fad1-97cb-5f07-f73099808525",0);
}

//touch in the inventory will make it check items
touch(integer number)
{
if(llDetectedKey(0) == llGetOwner())
{
state check_items;
}
}
}

//The Check State (check all lists) add / remove items
state check_items
{
//This is the only necessary procedure (check all objects)
state_entry()
{
//Update set text
llSetText("Check inventory for neccessary components",text_color,text_alpha);

//Lets so the checks first off we need ITEMS!
if(llGetInventoryNumber(sell_type) == 0)
{
//PROBLEM!
llOwnerSay("You have nothing in your inventory.. script halting for now";);
llResetScript();
}

//Is the notecard there?
if(llGetInventoryKey("VendorItems";) == NULL_KEY)
{
llOwnerSay("Could not find the notecard for sellable items named VendorItems.";);
llOwnerSay("Remeber the name of the notecard is important and CaSe sensitive.";);
llResetScript();
}
else
{
//Notecard present lets get a listing of items
//First 10 lines are comments so leave those out
llGetNumberOfNotecardLines("VendorItems";);
}
}

//Dataserver returns number of lines
dataserver(key queryid, string data)
{
if((integer)(((integer)data - 10)/3) != llGetInventoryNumber(sell_type))
{
//Currently the number items doesn't match
llOwnerSay("Number items in notecard doesn't match items in inventory add or change as neccessary.";);
llResetScript();
}
else
{
//The number matches so we should setup the vendor now
state setup_items;
}
}

//Rezzed in this state? you have to be kidding..
on_rez(integer start_param)
{
//Get to the setup state
llResetScript();
}
}

//Setup all vendor items
state setup_items
{

state_entry()
{
//Tell the user whats up
llSetText("Updating inventory database",text_color,text_alpha);

//Current inventory number
current_item = 0;


//Next we get each line of the notecard until it ends
notecardline = 10;
llGetNotecardLine("VendorItems",notecardline);
}

//The dataserver actually gets the notecard
dataserver(key query_id, string data)
{
//Not the end yet
if (data != EOF)
{

//What thing are we dealing with first of all
integer item_mode = (notecardline - 10) % 3;

if(item_mode == 0) //First line
{

//Check to see if item exists
if(llGetInventoryKey(data) == NULL_KEY)
{
//Problem this thing doesn't exist
llOwnerSay("Item: " + data + " couldn't be found in inventory please update notecard";);

//Goto the setup state again..
llResetScript();
}
else
{
//Make sure the picture for the item is present
if(llGetInventoryKey(data + "PIC";) == NULL_KEY)
{
//Tell them to check pictures
llOwnerSay("Couldn't find the picture for " + data + " named " + data + "PIC please check all items for correct names.";);

//Reset
llResetScript();
}

//Add to the database
items += [data];

}
}
else if(item_mode == 1)//Description line
{
//Add to database
descriptions += [data];

}
else if(item_mode == 2)//Price line
{
//Add to database
prices += [data];

//Last thing is clear up the times they were sold
times_sold += [0];
}

//Next line
notecardline++;

//Get the line
llGetNotecardLine("VendorItems",notecardline);
}
else
{
//We're done here start selling
state run_store;
}
}

//Rezzed in this state? you have to be kidding..
on_rez(integer start_param)
{
//Get to the setup state
llResetScript();
}
}

state run_store
{

//setup the vendor for the first (maybe only item)
state_entry()
{
//Get Permissions for refund
llRequestPermissions(llGetOwner(),PERMISSION_DEBIT);

//Current item is 0
current_item = 0;

//Setup the first item
llSetText("",<1,1,1>,0.0);
llMessageLinked(LINK_SET,8,(string)text_color,NULL_KEY);
llMessageLinked(LINK_SET,9,(string)text_alpha,NULL_KEY);
llMessageLinked(LINK_SET,10,llList2String(descriptions,0) + "\n$L" + llList2String(prices,0),NULL_KEY);

llSetTexture(llList2String(items,0) + "PIC",0);
}

//We rezzed... reset
on_rez(integer start_param)
{
llResetScript();
}

//If the inventory changes the force an update of the vendor
changed(integer type)
{
if(type & CHANGED_INVENTORY)
{
llResetScript();
}
}

//Changes in premissions
run_time_permissions(integer type)
{
if(type & PERMISSION_DEBIT)
{
//Excellent the owner gave us the go ahead
}
else
{
//no no no... that wont do
llOwnerSay("Permissions must be granted for refund setup incomplete.. reseting";);
llResetScript();
}
}

//Money means they are trying to buy something
money(key giver, integer amount)
{
if(amount != llList2Integer(prices,current_item))
{
//Refund and say correct price
llSay(0,"The correct price is L$" + llList2String(prices,current_item));
llGiveMoney(giver,amount);
}
else
{
//Give them the item
llGiveInventory(giver,llList2String(items,current_item));

//Update time_sold list (wish there was a better way)

//First get the current value and add 1
integer new_number = llList2Integer(times_sold,current_item) + 1;

//Delete the value from the old list
times_sold = llDeleteSubList(times_sold,current_item,current_item);

//Put in new value
times_sold = llListInsertList(times_sold,[new_number],current_item);

//Update the last 10 items sold
if(llGetListLength(last_sold) == 10)
{
//Delete the first item
last_sold = llDeleteSubList(last_sold,0,0);

//Add item
last_sold += [current_item];
}
else
{
last_sold += [current_item];
}
}
}

//Messages that should do something i can care less who they are from
link_message(integer sender, integer number, string message, key id)
{

if(message == "NEXT";)
{
Next_Item();
}
else if (message == "PREV";)
{
Prev_Item();
}
else if (message == "HELP";)
{
Show_Help();
}
else if (message == "LAST10";)
{
Last_10();
}
else if (message == "TOP10";)
{
Top_10();
}
else if (message == "WORST10";)
{
Worst_10();
}

}
}


Next the text display code
CODE

//Sets the text of the object when asked

//system variables it will need
vector text_color = <1,1,1>;
float text_alpha = 1.0;

default
{
state_entry()
{
llSetText("",text_color,text_alpha);
}

on_rez(integer statr_param)
{
llSetText("",text_color,text_alpha);
}

link_message(integer prim_num,integer num, string message, key id)
{
if(num == 8)
{
text_color = (vector)message;
}
else if (num == 9)
{
text_alpha == (float)message;
}
else if(num == 10)
{
llSetText(message,text_color,text_alpha);
}
}
}


Now for the buttons:
Next Button
CODE

default
{
state_entry()
{}

touch_start(integer total_number)
{
llMessageLinked(LINK_SET,0,"NEXT",NULL_KEY);
}
}


Back Button
CODE

default
{
state_entry()
{}

touch_start(integer total_number)
{
llMessageLinked(LINK_SET,0,"NEXT",NULL_KEY);
}
}


Owner only buttons (these do the printouts ie: top10 last10)
Running help button (disabled when not in use)
CODE

default
{
state_entry()
{}

touch_start(integer total_number)
{
if(llDetectedKey(0) == llGetOwner())
{
llMessageLinked(LINK_SET,0,"HELP",NULL_KEY);
}
}
}


Last 10 items sold
CODE

default
{
state_entry()
{}

touch_start(integer total_number)
{
if(llDetectedKey(0) == llGetOwner())
{
llMessageLinked(LINK_SET,0,"LAST10",NULL_KEY);
}
}
}


Top 10 items sold
CODE

default
{
state_entry()
{}

touch_start(integer total_number)
{
if(llDetectedKey(0) == llGetOwner())
{
llMessageLinked(LINK_SET,0,"TOP10",NULL_KEY);
}
}
}


Worst 10
CODE

default
{
state_entry()
{}

touch_start(integer total_number)
{
if(llDetectedKey(0) == llGetOwner())
{
llMessageLinked(LINK_SET,0,"WORST10",NULL_KEY);
}
}
}
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Original Thread
07-19-2005 21:52
/15/a4/54012/1.html
_____________________
i've got nothing. ;)
Unshra Riva
Registered User
Join date: 23 Jun 2005
Posts: 9
07-20-2005 07:48
Looks good I'll try it out this weekend, I only have one correction that I noticed.

From: Wolf Rocco
Back Button
CODE

default
{
state_entry()
{}

touch_start(integer total_number)
{
llMessageLinked(LINK_SET,0,"NEXT",NULL_KEY);
}
}



Should be:

Back Button
CODE

default
{
state_entry()
{}

touch_start(integer total_number)
{
llMessageLinked(LINK_SET,0,"PREV",NULL_KEY);
}
}
Dartavia Vesperia
Gorean
Join date: 19 Jul 2005
Posts: 150
07-26-2005 16:17
Anyone get this to work? I've been working on it all day and all it's doing is giving me errors. 1) Telling me there is no inventory - there is
2) Telling me it can't find the note card - copy/paste the name for the note in the script and named
3) Telling me the number listed on the note isn't the same as in inventory - only have 2 things there with their PIC - easy to do!

Any help on this?
Be well :)
WhiteFire Sondergaard
Registered User
Join date: 17 Jun 2005
Posts: 21
07-27-2005 20:01
Looks like Wolf forgot to include the example notecard. You can get the entire system at Furnation Prime in the bottom of the pyramid in the center of the building. The ones there have examples of the notecard config.

I'm sure he will post it here soon too.