summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--shop.lua17
1 files changed, 16 insertions, 1 deletions
diff --git a/shop.lua b/shop.lua
index c3c22b2..3f55971 100644
--- a/shop.lua
+++ b/shop.lua
@@ -43,6 +43,21 @@ function stock_amt()
return out
end
+function give(amt)
+ amt = amt or 1
+ -- assumes that we have at least amt in stock already
+ for i=1,16 do
+ local x = turtle.getItemDetail(i)
+ if x and x.name == ITEM then
+ local a = math.min(amt,x.count)
+ turtle.select(i)
+ turtle.drop(a)
+ amt = amt - a
+ if amt <= 0 then break end
+ end
+ end
+end
+
function proctrans(tr)
if tr.to ~= our_addr then return end
if tr.type ~= "transfer" then return end
@@ -57,7 +72,7 @@ function proctrans(tr)
tell(tostring(amt))
if amt>0 then
- turtle.drop()
+ give(1)
tell("thank you!!! :3")
end