Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --tablo
- local term=require('term')
- local event=require('event')
- local shell=require('shell')
- local com = require("component")
- local fs=require('filesystem')
- local serialization=require('serialization')
- local function saveTbl(tbl, fl) file = io.open(fl, 'w') file:write(serialization.serialize(tbl)) file:close() end
- local function loadTbl(fl) file = io.open(fl, 'r') if not file then file = io.open(fl, 'w') file:write('{}') return {} else return serialization.unserialize(file:read('*a')) end file:close() end
- local gpu=com.gpu
- local m=com.modem
- local addressRobot='e51089c7-42c7-465b-9791-ccd8758480ea'
- m.open(1)
- items1={} price1={}
- local thread=require('thread')
- thread.init()
- gpu.setResolution(80,29)
- A,B=gpu.getResolution()
- col={blue=0x0000FF,blue1=0x0000AF,grey=0x898989,grey1=0xACACAC}
- function top()
- gpu.setBackground(col.grey) term.clear()
- gpu.setBackground(col.grey1) gpu.fill(51,2,15,28,' ')
- gpu.setBackground(col.blue1) gpu.fill(1,1,A,1,' ')
- term.setCursor(5,1) io.write('Предмет:')
- gpu.setBackground(col.blue) term.setCursor(51,1) io.write(' В наличии: ') gpu.setBackground(col.blue1)
- term.setCursor(A-12,1) io.write('Цена за шт:')
- end
- function wr()
- top()
- while true do
- items=loadTbl('items.txt') for i=1,#items do items1[i]=items[i] end
- for i=1,#items do
- os.sleep(0.1)
- if items1[i]~=nil then
- if i==29 and i<57 then top() os.sleep(15) term.clear()
- elseif i==1 then term.clear() top()
- elseif i==56 and i>28 then top() os.sleep(15) term.clear()
- elseif i==84 and i>56 then top() os.sleep(15) term.clear() end
- mas=loadTbl(items[i]..'.txt')
- if #items1<29 then gpu.setBackground(col.grey) term.setCursor(2,i+1) io.write(items[i]) term.setCursor(57,i+1) gpu.setBackground(col.grey1) io.write(mas[1]) term.setCursor(A-8,i+1) gpu.setBackground(col.grey) io.write(mas[2]) end
- if i<29 then gpu.setBackground(col.grey) term.setCursor(2,i+1) io.write(items[i]) term.setCursor(57,i+1) gpu.setBackground(col.grey1) io.write(mas[1]) term.setCursor(A-8,i+1) gpu.setBackground(col.grey) io.write(mas[2])
- elseif i<47 and i>28 then gpu.setBackground(col.grey) term.setCursor(2,i+1) io.write(items[i]) term.setCursor(57,i+1) gpu.setBackground(col.grey1) io.write(mas[1]) term.setCursor(A-8,i+1) gpu.setBackground(col.grey) io.write(mas[2])
- elseif i<85 and i>48 then gpu.setBackground(col.grey) term.setCursor(2,i+1) io.write(items[i]) term.setCursor(57,i+1) gpu.setBackground(col.grey1) io.write(mas[1]) term.setCursor(A-8,i+1) gpu.setBackground(col.grey) io.write(mas[2]) end
- end
- end
- os.sleep(20)
- end
- end
- gpu.setBackground(col.grey)
- function osn()
- while true do
- c=nil price=nil amount=nil b=nil
- key,_,address,port,_,message = event.pull()
- if key=='modem_message' then
- if message~=nil then
- c=string.sub(message,1,3) price=string.sub(message,4,9) amount=string.sub(message,10,13) b=string.sub(message,14)
- items=loadTbl('items.txt')
- amount=tonumber(amount)
- price=tonumber(price)
- if c=='add' then
- for i=1,#items1 do if items[i]==b then per=1 per2=i break else per=0 end end
- if per==0 then items1[#items1+1]=b saveTbl(items1,'items.txt') f1=io.open(b..'.txt','w') f1:write('{'..amount..','..price..'}') f1:close()
- elseif per==1 then f2=loadTbl(items1[per2]..'.txt') f2[1]=amount saveTbl(f2,items1[per2]..'.txt') end
- elseif c=='del' then
- for i=1,#items do if items[i]==b then per=1 per2=i break else per=0 end end
- if per==1 then
- shell.execute('del '..items[per2]..'.txt')
- items1={}
- for sp=1,#items do if items[sp]~=items[per2] then items1[#items1+1]=items[sp] end end
- items=loadTbl('items.txt') saveTbl(items1,'items.txt') end
- end end end end end
- m.send(addressRobot,1,'check')
- thread.create(wr)
- thread.create(osn)
- thread.waitForAll()
Advertisement
Add Comment
Please, Sign In to add comment