From 7d96a1d9475813aa3cce88432a149aed0e87e728 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Thu, 29 Dec 2022 23:07:14 +0000 Subject: shop --- shop.lua | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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 -- cgit v1.2.3