summaryrefslogtreecommitdiff
path: root/shop.lua
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2022-12-29 23:59:24 +0000
committerubq323 <ubq323@ubq323.website>2022-12-29 23:59:24 +0000
commite301c9c7f3946daf881c08376f5e8fb6953717b1 (patch)
tree0181928d30165a3df242e8360261d7bae4c3b0c6 /shop.lua
parente8e476f28df1f585541e127d2b2271d4f55ee33e (diff)
shop
Diffstat (limited to 'shop.lua')
-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()