summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--shop.lua36
1 files changed, 18 insertions, 18 deletions
diff --git a/shop.lua b/shop.lua
index d14aa32..11baf60 100644
--- a/shop.lua
+++ b/shop.lua
@@ -64,27 +64,27 @@ function proctrans(tr)
if not (tr.sent_metaname == our_name[1] and tr.sent_name == our_name[2]) then return end
local meta = parsemeta(tr.metadata)
local function tell(msg) if meta.username then chatbox.tell(meta.username,msg) end end
-
-
- if tr.value == PRICE then
- tell("stocking")
- local amt = stock_amt()
- tell(tostring(amt))
-
- if amt>0 then
- give(1)
- tell("thank you!!! :3")
- end
-
+ local function refund() if meta['return'] then sendws { type="make_transaction", to=meta['return'], amount=tr.value } end end
+ local remainder = tr.value % 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)
+ refund()
else
- tell("that's the wrong about of money. please send "..PRICE.."kst.")
- if meta['return'] then
- sendws { type="make_transaction", to=meta['return'], amount=tr.value }
-
- end
+ local in_stock = stock_amt()
+ 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)
+ if to_give > in_stock then
+ tell("i don't have that many items in stock, sorry")
+ refund()
+ else
+ give(to_give)
+ tell("thank you!!! :3")
+ end
end
-
end
function run_shop()