Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local term=require('term')
- local r=require('robot')
- local event=require('event')
- local shell=require('shell')
- local com = require("component")
- local fs=require('filesystem')
- local sides=require('sides')
- 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 is=com.inventory_controller
- local s = require("sides")
- local gpu=com.gpu
- local m = com.modem
- chn31={}
- m.open(1)
- loc ={["x"]=0,["y"]=0,["z"]=0}
- men=1 men2=3 abl={} abl2={} plk='▌' b={"╔═══════════════════════════╗",'Launch sort ',' Add chest ',' Chest list ','Delete chest',' Exit ','╚═══════════════════════════╝'}
- function pal(men) if men==1 then gpu.set(32,1,plk) gpu.set(32,2,plk) gpu.set(32,3,plk) elseif men==2 then gpu.set(32,4,plk) gpu.set(32,5,plk) gpu.set(32,6,plk) elseif men==3 then gpu.set(32,7,plk) gpu.set(32,8,plk) gpu.set(32,9,plk) elseif men==4 then gpu.set(32,10,plk) gpu.set(32,11,plk) gpu.set(32,12,plk) elseif men==5 then gpu.set(32,13,plk) gpu.set(32,14,plk) gpu.set(32,15,plk) end end
- function helps() gpu.set(34,1,'▬▬▬▬▬[Help]▬▬▬▬▬') gpu.set(34,2,'Для перемещения ') gpu.set(34,3,'по меню исполь- ') gpu.set(34,4,'зуйте стрелки. ') gpu.set(34,5,'Выбрать: Enter .') gpu.set(34,6,'▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬') gpu.set(34,7,'Программа созда-') gpu.set(34,8,'на для личного ') gpu.set(34,9,'пользования. ') gpu.set(34,10,'[Авторы]: ') gpu.set(34,11,' MeXaN1cK ') gpu.set(34,12,'PandaDoddo72rus') gpu.set(34,13,' (vah) ') gpu.set(34,14,'▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬') gpu.set(34,15,' |hil.su| ') gpu.set(34,16,'▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬') end
- 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
- function getxy()
- key,_,_,k2,_,message=event.pull()
- if key=='key_up' then return k2 end
- if key=='modem_message' then
- if message=='check' then check() end end end
- function pal2(men2) if men2==1 then term.setCursor(18,16) io.write(plk) elseif men2==2 then term.setCursor(30,16) io.write(plk) elseif men2==3 then term.setCursor(45,16) io.write(plk) end end
- wc={'1fbd74ac-c1cd-46b8-9125-a46d14ecaab0',
- '1147a439-09cf-4ebb-b07b-2259aa7afc87',
- '82b0b45e-d89e-49a2-a686-0ff15c9aee7a'}
- function delFile()
- term.clear()
- gpu.set(7,5,'═════════════╬Delete╬═════════════') gpu.set(7,9,'══════════════════════════════════')
- term.setCursor(27,7) gpu.set(7,7,"Enter chestname: ") chn2=tostring(io.read())
- chn3=loadTbl("chests.txt")
- for i=1,#chn3 do
- if chn3[i]==chn2 then delo=1 pe2=i break else delo=0 end
- end
- if delo==0 then gpu.set(5,5,'═════════════╬Delete╬═════════════') gpu.set(10,7,'Cannot find this name!') gpu.set(5,9,'══════════════════════════════════') os.sleep(2)
- else
- shell.execute('del /chests/'..chn2..".txt")
- chn3=loadTbl('chests.txt')
- chn31={}
- for sp=1,#chn3 do if chn3[sp]~=chn2 then chn31[#chn31+1]=chn3[sp] end end
- chn3=loadTbl('chests.txt') saveTbl(chn31,"chests.txt")
- term.clear()
- gpu.set(5,5,'═════════════╬Delete╬═════════════')
- gpu.set(15,7,'Chest: '..chn2..' deleted!')
- gpu.set(5,9,'══════════════════════════════════')
- os.sleep(1.7)
- mes='del'..'000000'..'0000'..chn2
- for i=1,#wc do m.send(wc[i],1,mes) end
- end
- end
- function addChest()
- r.select(1)
- gpu.set(7,5,'═══════════╬Add chest╬════════════') gpu.set(7,9,'══════════════════════════════════')
- term.setCursor(27,7) gpu.set(7,7,"Enter price: ") price=tonumber(io.read())
- term.clear() gpu.set(5,5,'═══════════╬Add chest╬════════════') gpu.set(5,6,' Положите предмет в 1 слот робота. ') gpu.set(5,7,' После чего нажмите любую клавишу!') gpu.set(5,8,'══════════════════════════════════') getxy() term.clear()
- gpu.set(5,5,'═══════════╬Add chest╬════════════') gpu.set(5,9,'══════════════════════════════════') term.setCursor(15,6) io.write("Enter X: ") fx=tonumber(io.read()) term.setCursor(15,7) io.write("Enter Y: ") fy=tonumber(io.read()) term.setCursor(15,8) io.write("Enter Z: ") fz=tonumber(io.read())
- scans = is.getStackInInternalSlot(1)
- a = scans["label"]
- a=string.gsub(a,' ','_')
- ch=loadTbl('chests.txt')
- ch[#ch+1]=a
- saveTbl(ch,'chests.txt')
- fil=io.open('/chests/'..a..'.txt','w')
- fil:write('{["x"]='..fx..',["y"]='..fy..',["z"]='..fz..'}')
- fil:close() getxy()
- if price<9 then price='00000'..price
- elseif price<99 and price > 9 then price='0000'..price
- elseif price<999 and price>99 then price='000'..price
- elseif price<9999 and price>999 then price='00'..price
- elseif price<99999 and price>9999 then price='0'..price
- elseif price<999999 and price>99999 then price=price end
- mes='add'..price..'0000'..a
- for i=1,#wc do m.send(wc[i],1,mes) end
- end
- function chestList()
- ab1=loadTbl('chests.txt')
- for i=1,#ab1 do abl[i]=ab1[i] end
- page=1
- k=1 j=14
- et3=true
- oldPage=0
- while et3 do
- gpu.fill(1,15,50,2,' ')
- term.setCursor(2,16) io.write('Page: ',page)
- term.setCursor(19,16) io.write('<Back|Next>')
- term.setCursor(46,16) io.write('Exit') pal2(men2)
- term.setCursor(1,1)
- if oldPage ~= page then
- gpu.fill(1,1,50,14,' ')
- for i=k,j do
- os.sleep(0.000001)
- if ab1[#ab1]~=nil then
- if ab1[i]~=nil then
- ab2='["'..abl[i]..'"]='
- os.sleep(0.000001)
- ab3=loadTbl('/chests/'..ab1[i]..'.txt')
- ab2=ab2..ab3['x']..','..ab3['y']..','..ab3['z']
- print(ab2)
- end
- oldPage=page
- else
- term.setCursor(15,7) io.write('Пусто!') break
- end end end
- p2=getxy()
- if p2==203 then men2=men2-1 if men2<1 then men2=1 end
- elseif p2==205 then men2=men2+1 if men2>3 then men2=3 end
- elseif p2==28 then
- if men2==1 then if k~=1 then k=k-14 j=j-14 page=page-1 end
- elseif men2==2 then k=k+14 j=j+14 page=page+1
- elseif men2==3 then term.clear() et3=false end end
- end
- end
- function goToHome()
- r.turnLeft()
- if loc["z"] > 0 then for i=1,loc["z"] do r.down() end end
- if loc["y"] > 0 then for i=1,loc["y"] do r.forward() end end r.turnLeft()
- if loc["x"] > 0 then for i=1,loc["x"] do r.forward() end end r.turnAround()
- end
- local ami
- function calc()
- am=0
- for i=1,108 do
- ami=is.getStackInSlot(3,i)
- if ami~=nil then
- ami1=ami['size']
- am=am+ami1
- end end
- return am
- end
- function check()
- loc ={["x"]=0,["y"]=0,["z"]=0}
- amountItem=nil
- chests=loadTbl('chests.txt') chests1={} for i=1,#chests do chests1[i]=chests[i] end
- for i=1,#chests do
- chst=loadTbl('/chests/'..chests[i]..'.txt')
- goToChest(chst)
- amountItem=calc()
- if amountItem<9 then amountItem='000'..amountItem
- elseif amountItem<99 and amountItem > 9 then amountItem='00'..amountItem
- elseif amountItem<999 and amountItem>99 then amountItem='0'..amountItem
- elseif amountItem<9999 and amountItem>999 then amountItem=amountItem end
- for los=1,#wc do m.send(wc[los],1,'add'..'000010'..amountItem..chests1[i]) end
- end
- goToHome()
- end
- function goToChest(arr)
- x=loc["x"]-arr["x"] y=loc["y"]-arr["y"] z=loc["z"]-arr["z"]
- if x < 0 then x=x*-1 for i=1, x do r.forward() loc["x"]=loc["x"]+1 end elseif x>0 then for i=1,x do loc["x"]=loc["x"]-1 r.back() end end r.turnRight()
- if y < 0 then y=y*-1 for i=1, y do r.forward() loc["y"]=loc["y"]+1 end elseif y>0 then for i=1,y do loc["y"]=loc["y"]-1 r.back() end end
- if z < 0 then z=z*-1 for i=1, z do r.up() loc["z"]=loc["z"]+1 end elseif z>0 then for i=1,z do loc["z"]=loc["z"]-1 r.down() end end r.turnLeft()
- end
- function menu()
- term.clear() helps() for i=1,5 do print(b[1]) print('║ ' .. b[i+1] ..' ║') print(b[7]) end pal(men) p2=getxy()
- if p2==208 then men=men+1 if men>5 then men=5 end
- elseif p2==200 then men=men-1 if men<1 then men=1 end
- elseif p2==28 then
- if men==1 then term.clear() shell.execute('sorter')
- elseif men==2 then term.clear() addChest()
- elseif men==3 then term.clear() chestList()
- elseif men==4 then term.clear() delFile()
- elseif men==5 then term.clear() os.exit() end
- end
- end
- getxy() while true do menu() end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement