summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--shop.lua28
1 files changed, 28 insertions, 0 deletions
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