I've chopped out some tedious boring menu choices bits (those all work WHEN the thing is working).
CODE
string CONFIG_CARD = "drinksprice";
integer PRICE = 5;
integer NotecardLine;
key QueryID;
integer channel; // channel that we are listening on
integer listener; // internal number representing the listener
key agentKey; // persons key who is using menu
string agentName; // person who is using menu
float timeout = 60; // number of seconds before dialogs time out
string menu = ""; // current menu being displayed to user
// menu buttons ...
list mainButtons = ["ManSize", "LadySize"];
list ManSizeButtons = ["IcedTea", "PomegraKiss", "Coffee", "Martini","Margarita","WhiteWine","Rum Fizz","TeqBomber","RedWine","Beer","MangoSling", "CocoChocSm"];
list LadySizeButtons = ["IcedTea", "PomegraKiss", "Coffee", "Martini","Margarita","WhiteWine","Rum Fizz","TeqBomber","RedWine","Beer","MangoSling", "CocoChocSm"];
init()
{
stopListening();
}
stopListening()
{
if(listener != 0)
{
llListenRemove(listener);
listener = 0;
}
menu = "";
// forget current user
agentKey = NULL_KEY;
agentName = "";
channel = 0;
llSetTimerEvent(0);
}
mainMenuHandler(string message)
{
menu = message;
if(message == "ManSize")
llDialog(agentKey, "What'll you have Sir?", ManSizeButtons, channel);
else if(message == "LadySize")
llDialog(agentKey, "What'll you have Ma'am?", LadySizeButtons, channel);
else
{
llInstantMessage(agentKey, "Unknown menu item - " + message);
stopListening();
return;
}
// extend timeout
llSetTimerEvent(timeout);
}
manMenuHandler(string message)
{
bunch of choices and give inventory stuff in here and this works
}
stopListening();
}
ladyMenuHandler(string message)
{
bunch of choices and give inventory stuff in here and this works.
}
stopListening();
}
unknownMenuHandler(string message)
{
llInstantMessage(agentKey, "Unknown menu item - " + message);
stopListening();
}
default
{
on_rez(integer start_param)
{
init();
llResetScript();
}
changed( integer change )
{
if( change & CHANGED_INVENTORY )
llResetScript();
}
state_entry()
{
llOwnerSay("Initializing…");
if (llGetInventoryType(CONFIG_CARD) == INVENTORY_NOTECARD)
{
NotecardLine = 0;
QueryID = llGetNotecardLine( CONFIG_CARD, NotecardLine );
}
else
{
llOwnerSay("Configuration notecard missing, using defaults.");
state run;
}
}
dataserver( key queryid, string data )
{
list temp;
string name;
string value;
if ( queryid == QueryID )
{
if ( data != EOF )
{
if ( llGetSubString(data, 0, 0) != "#" && llStringTrim(data, STRING_TRIM) != "" )
{
temp = llParseString2List(data, ["="], []);
name = llStringTrim(llToLower(llList2String(temp, 0)), STRING_TRIM);
value = llStringTrim(llList2String(temp, 1), STRING_TRIM);
if ( name == "price" )
{
PRICE = (integer)value;
}
}
NotecardLine++;
QueryID = llGetNotecardLine( CONFIG_CARD, NotecardLine );
}
else
{
state run;
}
}
}
state_exit()
{
llOwnerSay("Drinks Price Set");
}
}
state run
{
touch_start(integer total_number)
{
// someone else using this?
if(listener != 0 && llDetectedKey(0) != agentKey)
{
llInstantMessage(llDetectedKey(0), agentName + " is ordering right now, please wait a moment.");
return;
}
// remember who is using this
agentKey = llDetectedKey(0);
agentName = llDetectedName(0);
// if we are not listening already
if(listener == 0)
{
// set a random channel betweed -4000 and -2000
channel = (integer)(llFrand(2000) - 4000);
// start listening only to the agent on our hidden channel
listener = llListen(channel, agentName, agentKey, "");
llInstantMessage(llDetectedKey(0), agentName + " Please pay " + (string)PRICE + "L");
}
}
money(key id, integer amount)
{
if(llKey2Name(agentKey) == agentName)
{
if(amount == PRICE)
{
llSleep(2);
// menu to default
menu = "";
// show them buttons
llDialog(agentKey, "What size drink can I get you?", mainButtons, channel);
// set timeout
llSetTimerEvent(timeout);
}
}
}
listen(integer channel, string name, key id, string message)
{
// handle results based on menu end-user was viewing
if(menu == "") mainMenuHandler(message);
else if(menu == "ManSize") manMenuHandler(message);
else if(menu == "LadySize") ladyMenuHandler(message);
else unknownMenuHandler(message);
}
timer()
{
// let agent know that we are not listening
llInstantMessage(agentKey, "Your menu has timed out!");
stopListening();
}
}
