In Part 1 we added in touch support, pay support, refunding and displaying menus. In Part 2, we are going to do work in the listen event. Also note if two or more items have the same name, you may run in to a conflict. So far the script looks like the following:
[code lang="lsl2"]integer chan; integer debit = FALSE; list drinkbuyers; list alcoholicbuyers; list snacksbuyers; list mealsbuyers; refundalready(key user, string menu) { integer refund; string itemtitle; if (menu == "drink") { refund = 1; itemtitle = "drink"; } else if (menu == "alcoholic") { refund = 2; itemtitle = "alcoholic drink"; } else if (menu == "snack") { refund = 3; itemtitle = "snack"; } else if (menu == "meal") { refund = 4; itemtitle = "meal"; } else { refund = 0; } if (refund > 0) { if (debit) { llGiveMoney(user, refund); llDialog(user, "Hello " + llGetDisplayName(user) + ", You paid me twice for a " + itemtitle + "... I sent you a refund.",["Okay"], chan); } else { llDialog(user, "Hello " + llGetDisplayName(user) + ", You paid me twice for a " + itemtitle + " and i do not have premission to refund you. Please contact the owner of me for a refund.",["Okay"], chan); } } } list drinks = ["soda","Apple Juice", "Grape Juice", "Water","Smoothie"]; list alcoholic = ["Beer","Wine"]; list snack = ["Chips","Popcorn","Candy bar","Pumkin Pie","Cake"]; list meal = ["Cheeseburger", "Hotdog","Chicken Nuggets"]; ordermenu(key user, list menu) { list buttons = menu + "Cancel"; llDialog(user, "Hello " + llGetDisplayName(user) + ", Please pick a item from the menu",order_buttons(buttons), chan); } list order_buttons(list buttons) { return llList2List(buttons, -3, -1) + llList2List(buttons, -6, -4) + llList2List(buttons, -9, -7) + llList2List(buttons, -12, -10); } default { state_entry() { chan = (integer)(llFrand(-1000000000.0) - 1000000000.0); llListen(chan,"", NULL_KEY,""); llSetPayPrice(PAY_HIDE,[0,0,0,0]); llRequestPermissions(llGetOwner(),PERMISSION_DEBIT); } listen(integer channel, string name, key id, string message) { } money(key id, integer amount) { if (amount == 1) // drink { if(llListFindList(drinkbuyers,[id]) == -1) { drinkbuyers+= [id]; ordermenu(id,drinks); } else { refundalready(id,"drink"); } } else if (amount == 2) //alcoholic drink { if(llListFindList(alcoholicbuyers,[id]) == -1) { alcoholicbuyers+= [id]; ordermenu(id,alcoholic); } else { refundalready(id,"alcoholic"); } } else if (amount == 3) // snack { if(llListFindList(snacksbuyers,[id]) == -1) { snacksbuyers+= [id]; ordermenu(id,snack); } else { refundalready(id,"snack"); } } else if (amount == 4) //meal { if(llListFindList(mealsbuyers,[id]) == -1) { mealsbuyers+= [id]; ordermenu(id,meal); } else { refundalready(id,"meal"); } } else { if (debit) { llGiveMoney(id, amount); } else { llDialog(id, "Hello " + llGetDisplayName(id) + ", You paid me to wrong amount and i do not have premission to refund you. Please contact the owner of me for a refund.",["Okay"], chan); } } } run_time_permissions(integer p) { if(p & PERMISSION_DEBIT) { debit = TRUE; llSetPayPrice(PAY_HIDE, [1,2,3,4]); llOwnerSay("I'm now ready to accept orders!"); } else { llOwnerSay("You must accept permissions in order for this to work... Touch me for premission dialog again."); } } touch_start(integer total_number) { key avatar = llDetectedKey(0); if (debit) { if(llListFindList(drinkbuyers,[avatar]) != -1 || llListFindList(alcoholicbuyers,[avatar]) != -1 || llListFindList(snacksbuyers,[avatar]) != -1 || llListFindList(mealsbuyers,[avatar]) != -1) { list buttons; if (llListFindList(drinkbuyers,[avatar]) != -1) { buttons += "Drinks"; } if (llListFindList(alcoholicbuyers,[avatar]) != -1) { buttons += "Alcoholic Drinks"; } if (llListFindList(snacksbuyers,[avatar]) != -1) { buttons += "Snacks"; } if (llListFindList(mealsbuyers,[avatar]) != -1) { buttons += "Meals"; } llOwnerSay((string)llGetListLength(buttons)); if (llGetListLength(buttons) > 1) { buttons += "Cancel"; llDialog(avatar, "Hello " + llGetDisplayName(avatar) + ", You already paid me, which menu would you like to reopen?",order_buttons(buttons), chan); } else { string singleitem = llList2String(buttons,0); if (singleitem == "Drinks") { ordermenu(avatar,drinks); } else if (singleitem == "Alcoholic Drinks") { ordermenu(avatar,alcoholic); } else if (singleitem == "Snacks") { ordermenu(avatar,snack); } else if (singleitem == "Meals") { ordermenu(avatar,meal); } } } else { llDialog(avatar, "Hello " + llGetDisplayName(avatar) + ", I am Billy a robot the serves you food and drinks. My Menu is: \n\nL$1: Drinks \nL$2: Alcoholic Drinks \nL$3: Snacks \nL$4 Meals \n\nYou can pay me the price of the menu item you want, then pick a item. If you don't see anything you like, don't worry as i can refund you.",["Okay"], chan); } } else { if (llDetectedKey(0) == llGetOwner()) { llRequestPermissions(avatar,PERMISSION_DEBIT); } else { llDialog(avatar, "Hello " + llGetDisplayName(avatar) + ", I am Billy a robot the serves you food and drinks. I'm sorry to inform you that i can not take orders right now as my owner has not enabled me. I hope you can try me later as i look forward to serving you.",["Okay"], chan); } } } on_rez(integer start_param) { llResetScript(); } }[/code]
So we are going to go to the listen event to write if statements to check for cancel, and then check if they are in the buy list and the item is in a item menu. Then this script should be done!
The basic layout of the listen event so far should be:
[code lang="lsl2"]listen(integer channel, string name, key id, string message) { if (message == "Cancel") // If they click cancel do a refund { } else if (llListFindList(drinkbuyers,[id]) != -1 && llListFindList(drinks,[message]) != -1) { } else if (llListFindList(alcoholicbuyers,[id]) != -1 && llListFindList(alcoholic,[message]) != -1) { } else if (llListFindList(snacksbuyers,[id]) != -1 && llListFindList(snack,[message]) != -1) { } else if (llListFindList(mealsbuyers,[id]) != -1 && llListFindList(meal,[message]) != -1) { } }[/code]
Now in event of the if statements to check if the user is in the buy list and the item is in the list of items, we can then write a llGiveInventory to give the itme, and then we need to remove the person from the buyers list.
To do this, we need to write the following in the last 4 if statements, replacing the buyer list name for the one to go with the right if statement.
[code lang="lsl2"]llGiveInventory(id,message); integer pos=llListFindList(drinkbuyers,[id]); if(pos!=-1) { drinkbuyers=llDeleteSubList(drinkbuyers,pos,pos); }[/code]
Lastly we have the Cancel event to worry about. For that, we are going to check if they are in any of the buy lists, and then check which ones and add up to a refund integer and removing them from each list, then pay out.
The final script should look like the following:
[code lang="lsl2"]integer chan; integer debit = FALSE; list drinkbuyers; list alcoholicbuyers; list snacksbuyers; list mealsbuyers; refundalready(key user, string menu) { integer refund; string itemtitle; if (menu == "drink") { refund = 1; itemtitle = "drink"; } else if (menu == "alcoholic") { refund = 2; itemtitle = "alcoholic drink"; } else if (menu == "snack") { refund = 3; itemtitle = "snack"; } else if (menu == "meal") { refund = 4; itemtitle = "meal"; } else { refund = 0; } if (refund > 0) { if (debit) { llGiveMoney(user, refund); llDialog(user, "Hello " + llGetDisplayName(user) + ", You paid me twice for a " + itemtitle + "... I sent you a refund.",["Okay"], chan); } else { llDialog(user, "Hello " + llGetDisplayName(user) + ", You paid me twice for a " + itemtitle + " and i do not have premission to refund you. Please contact the owner of me for a refund.",["Okay"], chan); } } } list drinks = ["soda","Apple Juice", "Grape Juice", "Water","Smoothie"]; list alcoholic = ["Beer","Wine"]; list snack = ["Chips","Popcorn","Candy bar","Pumkin Pie","Cake"]; list meal = ["Cheeseburger", "Hotdog","Chicken Nuggets"]; ordermenu(key user, list menu) { list buttons = menu + "Cancel"; llDialog(user, "Hello " + llGetDisplayName(user) + ", Please pick a item from the menu",order_buttons(buttons), chan); } list order_buttons(list buttons) { return llList2List(buttons, -3, -1) + llList2List(buttons, -6, -4) + llList2List(buttons, -9, -7) + llList2List(buttons, -12, -10); } default { state_entry() { chan = (integer)(llFrand(-1000000000.0) - 1000000000.0); llListen(chan,"", NULL_KEY,""); llSetPayPrice(PAY_HIDE,[0,0,0,0]); llRequestPermissions(llGetOwner(),PERMISSION_DEBIT); } listen(integer channel, string name, key id, string message) { if (message == "Cancel") // If they click cancel do a refund { if(llListFindList(drinkbuyers,[id]) != -1 || llListFindList(alcoholicbuyers,[id]) != -1 || llListFindList(snacksbuyers,[id]) != -1 || llListFindList(mealsbuyers,[id]) != -1) { integer refund; if (llListFindList(drinkbuyers,[id]) != -1) { integer pos=llListFindList(drinkbuyers,[id]); if(pos!=-1) { drinkbuyers=llDeleteSubList(drinkbuyers,pos,pos); } refund = refund + 1; } if (llListFindList(alcoholicbuyers,[id]) != -1) { integer pos=llListFindList(alcoholicbuyers,[id]); if(pos!=-1) { alcoholicbuyers=llDeleteSubList(alcoholicbuyers,pos,pos); } refund = refund + 2; } if (llListFindList(snacksbuyers,[id]) != -1) { integer pos=llListFindList(snacksbuyers,[id]); if(pos!=-1) { snacksbuyers=llDeleteSubList(snacksbuyers,pos,pos); } refund = refund + 3; } if (llListFindList(mealsbuyers,[id]) != -1) { integer pos=llListFindList(mealsbuyers,[id]); if(pos!=-1) { mealsbuyers=llDeleteSubList(mealsbuyers,pos,pos); } refund = refund + 4; } if (debit) { llGiveMoney(id, refund); } else { llDialog(id, "Hello " + llGetDisplayName(id) + ", You clicked cancel and i do not have premission to refund you. Please contact the owner of me for a refund.",["Okay"], chan); } } } else if (llListFindList(drinkbuyers,[id]) != -1 && llListFindList(drinks,[message]) != -1) { llGiveInventory(id,message); integer pos=llListFindList(drinkbuyers,[id]); if(pos!=-1) { drinkbuyers=llDeleteSubList(drinkbuyers,pos,pos); } } else if (llListFindList(alcoholicbuyers,[id]) != -1 && llListFindList(alcoholic,[message]) != -1) { llGiveInventory(id,message); integer pos=llListFindList(alcoholicbuyers,[id]); if(pos!=-1) { alcoholicbuyers=llDeleteSubList(alcoholicbuyers,pos,pos); } } else if (llListFindList(snacksbuyers,[id]) != -1 && llListFindList(snack,[message]) != -1) { llGiveInventory(id,message); integer pos=llListFindList(snacksbuyers,[id]); if(pos!=-1) { snacksbuyers=llDeleteSubList(snacksbuyers,pos,pos); } } else if (llListFindList(mealsbuyers,[id]) != -1 && llListFindList(meal,[message]) != -1) { llGiveInventory(id,message); integer pos=llListFindList(mealsbuyers,[id]); if(pos!=-1) { mealsbuyers=llDeleteSubList(mealsbuyers,pos,pos); } } } money(key id, integer amount) { if (amount == 1) // drink { if(llListFindList(drinkbuyers,[id]) == -1) { drinkbuyers+= [id]; ordermenu(id,drinks); } else { refundalready(id,"drink"); } } else if (amount == 2) //alcoholic drink { if(llListFindList(alcoholicbuyers,[id]) == -1) { alcoholicbuyers+= [id]; ordermenu(id,alcoholic); } else { refundalready(id,"alcoholic"); } } else if (amount == 3) // snack { if(llListFindList(snacksbuyers,[id]) == -1) { snacksbuyers+= [id]; ordermenu(id,snack); } else { refundalready(id,"snack"); } } else if (amount == 4) //meal { if(llListFindList(mealsbuyers,[id]) == -1) { mealsbuyers+= [id]; ordermenu(id,meal); } else { refundalready(id,"meal"); } } else { if (debit) { llGiveMoney(id, amount); } else { llDialog(id, "Hello " + llGetDisplayName(id) + ", You paid me to wrong amount and i do not have premission to refund you. Please contact the owner of me for a refund.",["Okay"], chan); } } } run_time_permissions(integer p) { if(p & PERMISSION_DEBIT) { debit = TRUE; llSetPayPrice(PAY_HIDE, [1,2,3,4]); llOwnerSay("I'm now ready to accept orders!"); } else { llOwnerSay("You must accept permissions in order for this to work... Touch me for premission dialog again."); } } touch_start(integer total_number) { key avatar = llDetectedKey(0); if (debit) { if(llListFindList(drinkbuyers,[avatar]) != -1 || llListFindList(alcoholicbuyers,[avatar]) != -1 || llListFindList(snacksbuyers,[avatar]) != -1 || llListFindList(mealsbuyers,[avatar]) != -1) { list buttons; if (llListFindList(drinkbuyers,[avatar]) != -1) { buttons += "Drinks"; } if (llListFindList(alcoholicbuyers,[avatar]) != -1) { buttons += "Alcoholic Drinks"; } if (llListFindList(snacksbuyers,[avatar]) != -1) { buttons += "Snacks"; } if (llListFindList(mealsbuyers,[avatar]) != -1) { buttons += "Meals"; } if (llGetListLength(buttons) > 1) { buttons += "Cancel"; llDialog(avatar, "Hello " + llGetDisplayName(avatar) + ", You already paid me, which menu would you like to reopen?",order_buttons(buttons), chan); } else { string singleitem = llList2String(buttons,0); if (singleitem == "Drinks") { ordermenu(avatar,drinks); } else if (singleitem == "Alcoholic Drinks") { ordermenu(avatar,alcoholic); } else if (singleitem == "Snacks") { ordermenu(avatar,snack); } else if (singleitem == "Meals") { ordermenu(avatar,meal); } } } else { llDialog(avatar, "Hello " + llGetDisplayName(avatar) + ", I am Billy a robot the serves you food and drinks. My Menu is: \n\nL$1: Drinks \nL$2: Alcoholic Drinks \nL$3: Snacks \nL$4 Meals \n\nYou can pay me the price of the menu item you want, then pick a item. If you don't see anything you like, don't worry as i can refund you.",["Okay"], chan); } } else { if (llDetectedKey(0) == llGetOwner()) { llRequestPermissions(avatar,PERMISSION_DEBIT); } else { llDialog(avatar, "Hello " + llGetDisplayName(avatar) + ", I am Billy a robot the serves you food and drinks. I'm sorry to inform you that i can not take orders right now as my owner has not enabled me. I hope you can try me later as i look forward to serving you.",["Okay"], chan); } } } on_rez(integer start_param) { llResetScript(); } }[/code]
Also the item has to be in the inventory of the same script for it to give out the item. This script seems finished, and should work now. Don’t blame me if it messes up and pays some random noob millions of your L$! Hope you enjoyed this. Some of the ideas you could do to improve it is maybe add on ways for it to walk, maybe if you have a restaurant create a few of them that goes to tables and stuff, maybe add AI. You could add on to make this better, but i think this is a good start!