rednet.open("top")
local file = fs.open("disk/items.txt","r")
CurrItems = textutils.unserialise(file.readAll())
file.close()
local map = {
[1] = false, [2] = false, [3] = false,
[5] = false, [6] = false, [7] = false,
[9] = false, [10] = false, [11] = false
}
while true do
id, msg = rednet.receive()
item = string.sub(msg,string.find(msg,":")+1)
if (CurrItems[item] ~= nil) then
rednet.send(id,CurrItems[item].location)
else
currBestX = 0
currBestY = 0
for k,v in pairs(CurrItems) do
if (CurrItems[k].location[1] > currBestX) then
currBestX = CurrItems[k].location[1]
end
if (CurrItems[k].location[2] > currBestY) then
currBestY = CurrItems[k].location[2]
end
end
if (currBestX + 1 > 4) then
y = currBestY + 1
x = 0
else
x = currBestX + 1
end
CurrItems[item] = {
count = 1,
location = {tonumber(x),tonumber(y)},
map = map
}
File = fs.open("disk/items.txt", "r")
FileData = textutils.unserialise(File.readAll())
table.insert(FileData[item], CurrItems[item])
File.close()
File = fs.open("disk/items.txt", "w")
File.write(textutils.serialise(FileData))
File.close()
Comments