summaryrefslogtreecommitdiff
path: root/shop.lua
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2022-12-29 22:55:02 +0000
committerubq323 <ubq323@ubq323.website>2022-12-29 22:55:02 +0000
commit3f34d40f24579dcdc6e0f8f2fab02c842fcf35cd (patch)
tree616340b14e100c88f0e8ebdabb297ef8b98b0c2e /shop.lua
parent4ed1b1d21be8f35dcbd4b7afb289214a6f47df76 (diff)
shop
Diffstat (limited to 'shop.lua')
-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