Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CHEST_SIDE= 'right'
- MODEM_SIDE= 'top'
- MAIN_SERVER_ID= 1
- function send(id,data,r)
- c= 0
- while true do
- c= c+1
- rednet.send(id,data)
- ids,message= rednet.receive(1)
- if (ids == id and message == #data..'') then
- return true
- end
- if (c == r) then break end
- end
- end
- function receive(timeout)
- while true do
- id,message= rednet.receive(timeout)
- if (id ~= nil and #message~= nil) then
- rednet.send(id,#message..'')
- return id,message
- end
- end
- end
- function getID(NumberSlot)
- info= chest.getStackInSlot(NumberSlot)
- id= ''
- if (info == nil) then return -1 end
- for k,v in pairs(info) do
- if (k == 'id') then id= v end
- if (k == 'dmg') then if (v ~= 0) then return id..':'..v end return id end
- end
- return -1
- end
- function getAmount(NumberSlot)
- info= chest.getStackInSlot(NumberSlot)
- if (info == nil) then return -1 end
- for k,v in pairs(info) do
- if (k == 'qty') then return v end
- end
- return -1
- end
- function addA(arr1,arr2)
- for i=1,#arr2 do
- arr1[#arr1+1]= arr2[i]
- end
- return arr1
- end
- function drawA(arr)
- for i=1,#arr do
- print(arr[i])
- end
- end
- rednet.open(MODEM_SIDE)
- chest= peripheral.wrap(CHEST_SIDE)
- --ID_LIST= {}
- --AMOUNT_LIST= {}
- while true do
- ID_LIST= {}
- AMOUNT_LIST= {}
- count= 0
- InventorySize= chest.getInventorySize()
- while true do
- id,message= receive()
- if (id == MAIN_SERVER_ID and message == 'start') then
- break
- end
- end
- for i=1,InventorySize do
- d= chest.getAllStacks()
- Rsize= #d
- temp1= getID(i)
- temp2= getAmount(i)
- if (temp1 ~= -1 and temp2 ~= -1) then
- count= count+1
- stat= false
- for d=1,#ID_LIST do
- if (temp1 == ID_LIST[d]) then
- stat= true
- AMOUNT_LIST[d]= tonumber(AMOUNT_LIST[d])+temp2
- break
- end
- end
- if (stat == false) then
- ID_LIST[#ID_LIST+1]= temp1
- AMOUNT_LIST[#AMOUNT_LIST+1]= temp2
- end
- end
- end
- Rez= {}
- Rez= addA(ID_LIST,AMOUNT_LIST)
- table.insert(Rez,1,'DATA:'..#Rez..'')
- data= textutils.serialize(Rez)
- send(MAIN_SERVER_ID,data,10)
- sleep(0)
- end
- rednet.close(MODEM_SIDE)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement