rednet.open("right")
CurrItems = {}
list = ":"
function readFile()
local file = fs.open("disk/items.txt","r")
CurrItems = textutils.unserialise(file.readAll())
file.close()
end
chatbox = peripheral.wrap("bottom")
chatbox.setName("ItemRouter")
function fetchItem(item, itemAmount)
if (checkItem(item)) then
item = CurrItems[item]
for i = 1,2 do
turtle.turnLeft()
end
for i = 1,1 do
turtle.forward()
end
for i = 1,item.location[1] do
turtle.forward()
end
for i = 1,item.location[2] do
turtle.up()
end
turtle.turnRight()
while itemAmount > 0 do
if (itemAmount > 64) then
turtle.suck(64)
turtle.select(turtle.getSelectedSlot()+1)
itemAmount = itemAmount - 64
else
turtle.suck(itemAmount)
itemAmount = 0
end
end
turtle.turnLeft()
for i = 1,item.location[2] do
turtle.down()
end
for i = 1,item.location[1] do
turtle.back()
end
for i = 1,1 do
turtle.back()
end
for i = 1,2 do
turtle.turnRight()
end
for i = 1,16 do
turtle.select(i)
turtle.drop()
end
turtle.select(1)
return true
else
return false
end
end
function checkItem(item)
if (CurrItems[item] ~= nil) then
print(CurrItems[item])
return true
else
return false
end
end
while true do
readFile()
getitem = false
list = ":"
cmd = ""
item = ""
itemAmount = ""
term.clear()
term.setCursorPos(1,1)
print("Type 'item' to get an item, type 'list' to get a list of all the items")
event, side, name, cmd = os.pullEvent("chat_message")
if (cmd ~= "getItem list") then
if (name == "FireDemonite" or name == "aleroqu") then
for w in string.gmatch(cmd, "%d+") do
itemAmount = w
end
for w in string.gmatch(cmd, "%a+") do
if ( w == "getItem") then
getitem = true
end
if (getitem and w ~= "getItem") then
item = item.." "..w
end
end
item = string.sub(item,2)
crafting = false
-- for i = 1,11 do
-- if (i ~= 4 and i ~= 8) then
-- if ( CurrItems[item].map[i] == true) then
-- crafting = true
-- end
-- end
-- end
--print("Item: "..item.." Amount: "..itemAmount)
if (getitem and crafting == false) then
term.clear()
term.setCursorPos(1,1)
sleep(1)
chatbox.say("Item: "..item)
term.write("Item: "..item)
sleep(1)
chatbox.say("Amount: "..itemAmount)
print("ItemAmount: "..itemAmount)
if (fetchItem(item, tonumber(itemAmount))) then
print("Getting items...")
sleep(5)
else
print("Not an exisiting item")
chatbox.say("Not a valid item")
sleep(1)
end
end
end
else
i = 1
for k,v in pairs(CurrItems) do
--chatbox.say(k)
if (i>1) then
list = list..", "..k
else
list = k
end
i = i + 1
end
--list = list.sub(list,2)
sleep(1)
chatbox.say(list)
end
end
Comments