Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Midori's Bartender Script Modification?

Dioxide DeSantis
Registered User
Join date: 2 Feb 2007
Posts: 63
03-25-2009 15:18
Original Script Link
/54/37/212535/1.html

What I want to do is change the list from the buttons to a simple list like in the buky radio that I can just choose a number. Right now its rather limiting on drink name length.

Thing is I have tried to figure out how to do it but I am getting completely lost. Any help you all could give or point in th right direction would be great.

Dioxide

Original Script

CODE

//
// Bartender Script
// by Midori Mikazuki
//
// Copyright 2007. This script is hearby released into the public domain.
//
// Drop this script into an object that will act as a bartender.
// The script assumes that all objects contained within the bartender
// are drinks to be given out. When someone touches the bartender,
// (s)he is presented with a list of the installed drinks; if there
// are more than 10 drinks in the bartender, the menu will page through
// them. Clicking on one of the drink names in the menu will cause the
// bartender to give the avatar a copy of that drink.
//
// The bartender menu listens on a randomly generated channel, so it
// should be fine to have several bartenders in close proximity without
// worrying that they will all give out a drink at the same time.

integer CHANNEL;
integer handle;
key touched;

list DRINKS;

string TITLE = "Touch me for a free drink";

RebuildDrinkList()
{
DRINKS = [];

integer count = llGetInventoryNumber(INVENTORY_OBJECT);
integer i;

for (i = 0; i < count; ++i)
{
string name = llGetInventoryName(INVENTORY_OBJECT, i);
name = llGetSubString(name, 0, 24);
DRINKS = (DRINKS=[]) + DRINKS + [ name ];
}
}

DisplayMenu(integer page)
{
integer length = llGetListLength(DRINKS);
integer start = page * 9;
integer end = start + 9;
list menu = [];

page += 1;

if (start > 0) {
menu = [ "Page " + (string)(page - 1) ];
}
else {
menu = [ " " ];
}

menu = (menu=[]) + menu + llList2List(DRINKS, start, start);

if (end < length) {
menu = (menu=[]) + menu + [ "Page " + (string) (page + 1) ];
}
else {
menu = (menu=[]) + menu + [ " " ];
}

menu = (menu=[]) + menu + llList2List(DRINKS, start + 1, end);

llDialog(touched, "\nDrink Menu: ", menu , CHANNEL);
}

default
{
state_entry()
{
llSetText(TITLE, <1.0, 1.0, 1.0>, 1.0);

RebuildDrinkList();

llListenRemove(handle);
CHANNEL = (integer)llFrand(2000000000.0);
llListen(CHANNEL, "", NULL_KEY, "");
}

on_rez(integer start)
{
llResetScript();
}

changed(integer change)
{
if (change == CHANGED_INVENTORY)
{
llOwnerSay("Rebuilding drink list");
RebuildDrinkList();
llOwnerSay("Done.");
}
}

touch_start(integer total_number)
{
touched = llDetectedKey(0);
if (touched)
{
DisplayMenu(0);
}
}

listen(integer channel, string name, key id, string message)
{
if (llSubStringIndex(message, "Page ") != -1) {
string page = llGetSubString(message, 5, -1);
DisplayMenu(((integer) page) - 1);
}
else {
integer drink = llListFindList(DRINKS, [ message ]);
if (drink != -1) {
llGiveInventory(id, llGetInventoryName(INVENTORY_OBJECT, drink));
}
}
}
}
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
03-25-2009 20:49
i'm not sure how to build the list of buttons with numbers, but i think you can use llDumpList2string and use \n as the spacer to make it put them on different lines
_____________________
Dark Heart Emporium

http://www.xstreetsl.com/modules.php?name=Marketplace&MerchantID=133020

want more layers for tattoos, specifically for the head? vote here
http://jira.secondlife.com/browse/VWR-1449?

llDetectedCollision* Functions similar to touch
http://jira.secondlife.com/browse/SVC-3369
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
03-25-2009 21:35
I don't think I missed any punctuation.... (added some tweaks, removed some no-op code)
CODE

//
// Bartender Script
// by Midori Mikazuki
//
// Copyright 2007. This script is hearby released into the public domain.
//-- Modified by Void Singer
//
// Drop this script into an object that will act as a bartender.
// The script assumes that all objects contained within the bartender
// are drinks to be given out. When someone touches the bartender,
// (s)he is presented with a list of [numbered choices for] the installed drinks; if there
// are more than 10 drinks in the bartender, the menu will page through
// them. Clicking on one of the drink numbers(vs) in the menu will cause the
// bartender to give the avatar a copy of that drink.
//
// The bartender menu listens on a randomly generated channel, so it
// should be fine to have several bartenders in close proximity without
// worrying that they will all give out a drink at the same time.

integer CHANNEL;
key touched;

list DRINKS;

string TITLE = "Touch me for a free drink";

RebuildDrinkList(){
llOwnerSay ( "Rebuilding drink list" );
DRINKS = [];

integer count = llGetInventoryNumber( INVENTORY_OBJECT );

while (count){ //-- for (i = 0; i < count; ++i){
DRINKS = (list)llGetInventoryName( INVENTORY_OBJECT, --count ) + DRINKS;
}
llOwnerSay( "Done." );
}

DisplayMenu( integer page ){
integer length = llGetListLength( DRINKS );
integer start = page * 10;
integer end = start + 9;
list menu = [];

if (start > 0) {
menu += (list)("Page " + (string)page);
}else {
menu += (list)" ";
}

if (end < length) {
menu += [(string)end, "Page " + (string)(page + 2)];
}else {
end = --length;
menu += [(string)end, " "];
}
--end;

while (start < (end - 1)){
menu += [(string)(end - 2), (string)(end - 1), (string)end];
end -= 3;
}
while (start <= end){
menu += (list)((string)start);
++start;
}

llDialog( touched, "\nDrink Menu: ", menu , CHANNEL );
}

default{
state_entry(){
llSetText( TITLE, <1.0, 1.0, 1.0>, 1.0 );

RebuildDrinkList();

CHANNEL = ( integer )llFrand( 2000000000.0 );
llListen( CHANNEL, "", NULL_KEY, "" );
}

on_rez( integer start ){
llResetScript();
}

changed( integer change ){
if ( change & CHANGED_INVENTORY ){
llSetTimerEvent( 10.0 );
}
}

touch_start( integer total_number ){
touched = llDetectedKey( 0 );
DisplayMenu( 0 );
}

listen( integer channel, string name, key id, string message ){
if (~llSubStringIndex( message, "Page " )) {
string page = llGetSubString( message, 5, -1 );
DisplayMenu(((integer) page) - 1);
}else if (" " != message) {
llGiveInventory( id, llList2String( DRINKS, (integer)message ) );
}
}

timer(){
llSetTimerEvent ( 0 );
llResetScript();
}
}

should list numbers X through X+9, maybe you want to post a drink chart, and now you have 10 seconds after adding a drink to inventory to add another before it starts rebuilding the list

EDIT: removed LSO memory conservation hacks, fixed, tested working in mono
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Dioxide DeSantis
Registered User
Join date: 2 Feb 2007
Posts: 63
03-26-2009 16:50
I had to add this line to be able to compile it

integer handle;

I still get a script error once its compiled and I go to touch it

llDialog: button list too long, must be 12 or fewer entries
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
03-27-2009 05:20
Try this one, which is a slight modification of a script at http://lslwiki.net/lslwiki/wakka.php?wakka=ZenMondo

CODE
/////////////////////////////////////////
/// Bartender script based on
///
// ZenMondo's Object Giver 2.21 by ZenMondo Wormser
// Developed for Caledon Library System
//
// Menu-Driven Item Giver.
// Can be Used by one person at a time.
//////////////////////////////////////

///////////////////////////
// This work is licensed under the Creative Commons Attribution-Noncommercial-Share
// Alike 3.0 License. To view a copy of this license, visit
// http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative
// Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.
//
// Attribution:
// If unmodified you must keep the filename intact
// If a derivative work you must say "Based on the CodePoetry of ZenMondo Wormser"
//////////////////////////

//Global Variables
string float_text = "Touch me for a free drink";

integer object_counter=0;
list inventory_list = [];
list menu_list = [];

integer menu_page;
integer last_menu;

integer handle;
integer UserChan = -11811;

key current_user = NULL_KEY;

integer using;

//Functions
//generate a channel based on the prim's uuid
integer channel() { // top of script in functions
return (integer)("0x"+llGetSubString((string)llGetKey(),-8,-1));
}


//Compact function to put buttons in "correct" human-readable order ~ Redux
//Taken from http://lslwiki.net/lslwiki/wakka.php?wakka=llDialog
list order_buttons(list buttons)
{
return llList2List(buttons, -3, -1) + llList2List(buttons, -6, -4) + llList2List(buttons, -9, -7) + llList2List(buttons, -12, -10);
}


//Function to Build the two lists we will use
// Could have put it all in state_entry but may be a handy function
// to use in another similar script so I put it here.
BuildLists()
{
integer counter=0;
integer inventory_num = llGetInventoryNumber(INVENTORY_OBJECT);

while(counter < inventory_num)
{
string object_name = llGetInventoryName(INVENTORY_OBJECT, counter);

inventory_list = (inventory_list=[]) + inventory_list + object_name;
menu_list = (menu_list=[]) + menu_list + [(string) (++counter) + ")" + object_name]; //Incrimenting the the counter in this line. Probably bad practice
//But it solves two problems, incrimenting the counter in the loop
// and making a human readale list startign at "1" instead of "0"

}

if(counter % 9 == 0) //Multiples of 9 won't round down right.
{
--counter;
}

last_menu = llFloor(counter / 9.0); //I say 9.0 so it treats it like a float
// and will round down correctly.



}


//Function to Display the pages of the Menu
// Instead of defining my menus ahead of time
// (and in so doing putting a limit on the number of items)
// I build the pages of the menu dynamicaly
DisplayMenu(key id)
{
//These are the buttons, they will be numbers
// Based on what page of the menu we are on.

string b1 = (string) (menu_page *9 +1);
string b2 = (string) (menu_page *9 +2);
string b3 = (string) (menu_page *9 +3);
string b4 = (string) (menu_page *9 +4);
string b5 = (string) (menu_page *9 +5);
string b6 = (string) (menu_page *9 +6);
string b7 = (string) (menu_page *9 +7);
string b8 = (string) (menu_page *9 +8);
string b9 = (string) (menu_page *9 +9);


list menu = [b1, b2, b3, b4, b5, b6, b7, b8, b9, "<<PREV", "CANCEL", "NEXT>>"]; //will use the order_buttons function to put these in a good order for llDialog

list menu_text = "Please choose a drink: "+llList2List(menu_list, menu_page * 9, menu_page * 9 + 8); //This is the part of the list for menu text for this page.

// integer menu_length = llGetListLength(menu_text);//WRONG
integer menu_length = llGetListLength(menu_text)-1; // RIGHT

if(menu_length < 9) //Don't Need all the buttons
{
menu = llDeleteSubList(menu, menu_length, 8); //Trim the menu buttons
}

llDialog(id, llDumpList2String(menu_text, "\n"), order_buttons(menu), UserChan); //Display the Menu

}



default
{
state_entry()
{
menu_page = 0;

UserChan = -channel(); // negative channel based on prim's uuid -- pretty sure to be unique on the sim

BuildLists();

llSetText(float_text, <0, 1, 1>, 1.0);
}

touch_start(integer total_number)
{if(using) //Object in use
{
if(current_user != llDetectedKey(0))
{

llDialog(llDetectedKey(0), "I'm sorry another patron is using me at this time, please wait a moment and try again.", ["OK"], 1181111811);
}

else // Our user
{
DisplayMenu(current_user); //Give the menu again but not more time
// This is in case they accidently hit "ignore"
}
}

else //Giver is available and ready for use
{
current_user = llDetectedKey(0);
using = TRUE;
handle = llListen(UserChan, "", current_user, "");
llSetTimerEvent(90); //90 Second limit to make a choice or reset if walk away
DisplayMenu(current_user);
llSetText("Currently in Use, \nplease wait a moment...", <1,0,0>, 1.0);
}


}


listen(integer channel, string name, key id, string message)
{
if(message == "CANCEL")
{
llSetTimerEvent(0);
llListenRemove(handle);
using = FALSE;
current_user = NULL_KEY;
menu_page = 0;
llSetText(float_text, <0, 1, 1>, 1.0);

}

else if(message == "<<PREV")
{
menu_page--;
if(menu_page == -1)
{
menu_page = last_menu;
}

DisplayMenu(current_user);
}

else if(message == "NEXT>>")
{
menu_page++;
if(menu_page > last_menu)
{
menu_page = 0;
}

DisplayMenu(current_user);
}

else //Patron Chose a Number
{
llSetTimerEvent(0);
llListenRemove(handle);

integer get_item = (integer) message;
get_item--; //Humans like to count from 1, but computers like 0 better.

llGiveInventory(current_user, llList2String(inventory_list, get_item));


using = FALSE;
current_user = NULL_KEY;
menu_page = 0;
llSetText(float_text, <0, 1, 1>, 1.0);

}
}



timer()
{
llSetTimerEvent(0);
llListenRemove(handle);
llDialog(current_user, "I'm sorry time has expired to make a menu choice." , ["OK"], 1181111811);
using= FALSE;
current_user = NULL_KEY;
menu_page = 0;
llSetText(float_text, <0, 1, 1>, 1.0);
}

changed(integer change)
{
if(change & CHANGED_INVENTORY)
{
llResetScript();
}


}


}
Dioxide DeSantis
Registered User
Join date: 2 Feb 2007
Posts: 63
03-27-2009 15:14
Innula that seems to be almost perfectly what I am looking for but for some reason there is always a number past the total items. So if there is 8 items in there it would show 9 numbers on the menu for selection with the number 9 fiving a script error.

I have looked through but to my untrained eyes I don't see anything obvious t hat would tell me oh thats it.

Dioxide
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
03-27-2009 20:41
Oops.. I hadn't tested it properly. The mistake -- now corrected and noted -- is at line 109. It should read
CODE
integer menu_length = llGetListLength(menu_text)-1;
The original didn't have anything in the text section but the option numbers and names, and when I added the bit about "Please choose a drink" I forgot to allow for this extra item in menu_text.

Sorry about that.
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
03-27-2009 22:13
From: Dioxide DeSantis
I had to add this line to be able to compile it

integer handle;

I still get a script error once its compiled and I go to touch it

llDialog: button list too long, must be 12 or fewer entries

you can take that back out (since I took the line that used it back out... as it was never used (thought I deleted it) and I fixed the dialog count... should have been end = start + 9, not +10
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Dioxide DeSantis
Registered User
Join date: 2 Feb 2007
Posts: 63
03-28-2009 09:01
From: Void Singer
you can take that back out (since I took the line that used it back out... as it was never used (thought I deleted it) and I fixed the dialog count... should have been end = start + 9, not +10


Void I also have to change the line

From: someone

menu = (menu=[]) + menu + (list)((string)end)) ;


to

menu = (menu=[]) + menu + (list)((string)end) ;

one too many ) at the end to compile but it does not show any items in the list now.
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
03-28-2009 09:26
hmm, try this maybe? i haven't tried the script, so i don't know for sure

menu = (menu=[]) + menu + [(string)end] ;



also, instead what about

menu += [(string)end];
_____________________
Dark Heart Emporium

http://www.xstreetsl.com/modules.php?name=Marketplace&MerchantID=133020

want more layers for tattoos, specifically for the head? vote here
http://jira.secondlife.com/browse/VWR-1449?

llDetectedCollision* Functions similar to touch
http://jira.secondlife.com/browse/SVC-3369
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
03-28-2009 09:54
From: Dioxide DeSantis
Void I also have to change the line



to

menu = (menu=[]) + menu + (list)((string)end) ;

one too many ) at the end to compile but it does not show any items in the list now.

good catch will fix.... really all those (list=[])+ hacks can come out for mono compiles too, since it doesn't save memory in mono as it did in LSO... it really was a quick rewrite =)

ETA: fixed, dunno why it gave you no options, actually gave me too many (forget to correct for past the end of list)
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -