From bc8d921d661beb1d6b51d409266c11b4bdc9d6df Mon Sep 17 00:00:00 2001 From: ubq323 Date: Thu, 5 Jan 2023 05:32:22 +0000 Subject: shop2 --- shop2.lua | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/shop2.lua b/shop2.lua index 3659402..f3da107 100644 --- a/shop2.lua +++ b/shop2.lua @@ -107,24 +107,30 @@ local function proctrans(tr) local function refund() if meta['return'] then sendws { type="make_transaction", to=meta['return'], amount=tr.value } end end local mtn = tr.sent_metaname - + local idesc = ITEMS[mtn] + if not idesc then + -- some other metaname that has nothing to do with us + -- presumably some other service @ac.kst. so just ignore it + return + end - local remainder = tr.value % PRICE + local remainder = tr.value % idesc.price if remainder ~= 0 then - tell("i can only give you a whole number of items. make sure the amount you gave me is a multiple of "..PRICE) + tell("i can only give you a whole number of items. make sure the amount you gave me is a multiple of "..idesc.price) refund() else - local in_stock = stock_amt() + local si = take_stock() + local in_stock = stock_amt(si,idesc) if in_stock == 0 then tell("we are out of stock! please yell at ubq323 about this") refund() else - local to_give = math.floor(tr.value / PRICE) + local to_give = math.floor(tr.value / idesc.price) if to_give > in_stock then tell("i don't have that many items in stock, sorry") refund() else - give(to_give) + give(si,idesc,to_give) tell("thank you!!! :3") end end -- cgit v1.2.3