From 3f34d40f24579dcdc6e0f8f2fab02c842fcf35cd Mon Sep 17 00:00:00 2001 From: ubq323 Date: Thu, 29 Dec 2022 22:55:02 +0000 Subject: shop --- shop.lua | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/shop.lua b/shop.lua index 5c2caa6..7427ffb 100644 --- a/shop.lua +++ b/shop.lua @@ -4,6 +4,7 @@ key=assert(settings.get"krist.pkey","please set private key") our_name = {"d","ac"} PRICE = 5 +ITEM = "minecraft:cobblestone" sres =textutils.unserializeJSON( http.post("https://krist.dev/ws/start","privatekey="..key).readAll()) assert(sres.ok,"not ok") @@ -33,13 +34,40 @@ function parsemeta(m) return out end +function stock_amt() + local out = 0 + for i=1,16 do + local x = turtle.getItemDetail(i) + if x.name == ITEM then out = out + x.count end + end + return out +end + function proctrans(tr) if tr.to ~= our_addr then return end if tr.type ~= "transfer" then return end 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 + turtle.drop() + tell("thank you!!! :3") + end + + + else + tell("that's the wrong about of money. please send "..PRICE.."kst. (todo: refund you)") + if meta.return then + -- todo: refund + end + end end -- cgit v1.2.3