Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local bChan = 555
- local rChan = 999
- local modem = peripheral.wrap("right")
- local wrap = "right"
- if modem == nil then
- modem = peripheral.wrap("left")
- wrap = "left"
- end
- if modem == nil then
- modem = peripheral.wrap("back")
- wrap = "back"
- end
- modem.open(rChan)
- modem.open(bChan)
- local id=os.getComputerID()
- modem.open(id)
- local tBuffer = {}
- local index = 0
- local tArgs = { ... }
- local run = 'false'
- local function pairsByKeys (t, f)
- local a = {}
- for n in pairs(t) do table.insert(a, n) end
- table.sort(a, f)
- local i = 0 -- iterator variable
- local iter = function () -- iterator function
- i = i + 1
- if a[i] == nil then return nil
- else return a[i], t[a[i]]
- end
- end
- return iter
- end
- local function fnPullCMD(aTable,nIndex)
- if aTable[nIndex] then
- return aTable[nIndex]
- else
- return ''
- end
- end
- local function myClear(sData)
- term.clear()
- term.setCursorPos(1,1)
- if sData and #sData > 0 then
- term.write(sData)
- end
- local nx,ny = term.getSize()
- term.setCursorPos(nx-7,1)
- term.write('CPU: ' .. id)
- term.setCursorPos(1,2)
- term.setCursorBlink(true)
- end
- myClear(' ')
- local sString = ''
- local tFuel = {}
- while true do
- local tAble = {os.pullEvent()}
- if #tAble > 0 then
- if tAble[1] == "modem_message" and tAble[3] ~= rChan then
- local tProg = textutils.unserialize(tAble[5])
- if tProg and #tProg > 0 then
- if tProg[1] == "fuel" and not pocket then
- local data = turtle.getFuelLevel()
- os.queueEvent('modem_message',wrap,rChan,id,data)
- modem.transmit(rChan,id,data)
- else
- local x,y = term.getCursorPos()
- term.setCursorPos(1,13)
- term.clearLine()
- term.setCursorPos(1,3)
- if #tArgs == 0 then
- run = tostring(shell.run(unpack(tProg)))
- end
- modem.transmit(rChan,id,run)
- os.queueEvent('modem_message',wrap,rChan,id,run)
- end
- end
- end
- if tAble[1] == "key" then
- if sString == '' then
- term.setCursorPos(1,2)
- end
- local key = keys.getName(tAble[2])
- if key == "enter" then
- --myClear(sString)
- if sString and #sString > 0 then
- table.insert(tBuffer,1,sString)
- end
- term.setCursorPos(1,2)
- tString = {}
- tFuel = {}
- if sString == 'exit' then
- return
- end
- for w in string.gmatch(sString,'%w+')do
- table.insert(tString,w)
- end
- sString = ''
- modem.transmit(bChan ,id,textutils.serialize(tString))
- os.queueEvent('modem_message',wrap,bChan ,id,textutils.serialize(tString))
- elseif key == "backspace" then
- sString = string.sub(sString,1,string.len(sString)-1)
- local x,y = term.getCursorPos()
- if x > 1 then
- term.setCursorPos(x-1,y)
- term.write(" ")
- term.setCursorPos(x-1,y)
- end
- elseif tAble[2] == 200 and not pocket then
- turtle.forward()
- elseif tAble[2] == 208 and not pocket then
- turtle.back()
- elseif tAble[2] == 203 and not pocket then
- turtle.turnLeft()
- elseif tAble[2] == 205 and not pocket then
- turtle.turnRight()
- elseif tAble[2] == 199 and not pocket then
- turtle.up()
- elseif tAble[2] ==207 and not pocket then
- turtle.down()
- elseif tAble[2] == 210 then
- if index < #tBuffer then
- index = index + 1
- else
- index = 0
- end
- sString = fnPullCMD(tBuffer,index)
- term.setCursorPos(1,2)
- term.clearLine()
- if sString and #sString > 0 then
- term.write(sString)
- end
- end
- elseif tAble[1] == "char" then
- sString = sString .. tAble[2]
- term.write(tAble[2])
- elseif tAble[3] == rChan then
- tFuel[tAble[4]] = tAble[5]
- myClear(tBuffer[1])
- term.setCursorPos(1,3)
- for k,v in pairsByKeys(tFuel) do
- term.write(k .. ' ' .. v)
- local x,y = term.getCursorPos()
- if x <14 then
- term.setCursorPos(15,y)
- else
- term.setCursorPos(1,y+1)
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment