Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ----------------------------------------------------
- -- Универсальная программа --
- -- для ручного управления роботом c помощью --
- -- OpenPeripheral Glasses! --
- -- проект http://computercraft.ru --
- -- 2015, © xMikhail, WildOne --
- -- ver. 2.0 --
- ----------------------------------------------------
- ------------------------ROBOT-----------------------
- local event = require("event")
- local computer = require('computer')
- local r = require("robot")
- local tunnel = require("component").tunnel
- local rs = require("component").redstone
- local s = require("serialization")
- local sides = require('sides')
- local icontroller = require('component').inventory_controller
- local t = {}
- --===================================--
- -- Monitoring --
- --===================================--
- local val = {}
- val.inv_size = r.inventorySize()
- function getEU()
- return math.floor(computer.energy())
- end
- function freeMEM()
- return math.floor(computer.freeMemory()/1024)
- end
- function freeslots()
- local freeslots=0
- for i=1,val.inv_size do
- if r.count(i)==0 then
- freeslots = freeslots + 1
- end
- end
- return freeslots
- end
- rsstatus = "выкл"
- function getEU()
- return math.floor(computer.energy())
- end
- function freeMEM()
- return math.floor(computer.freeMemory()/1024)
- end
- function t.mon()
- val.name = r.name()
- val.level = r.level()
- val.freeslots = freeslots()
- val.MAX_EU = computer.maxEnergy()
- val.TOTAL_MEM = computer.totalMemory()/1024
- val.EU = getEU()
- val.freeMEM = freeMEM()
- val.uptime = math.floor(computer.uptime()/60)
- val.rsstatus = rsstatus
- tunnel.send("2 "..s.serialize(val))
- end
- --===================================--
- -- INVENTORY DATA --
- --===================================--
- inv = {}
- inv.slot = {}
- inv.name = {}
- inv.amount = {}
- function t.inv()
- local frsl = freeslots()
- inv.busyslots = val.inv_size - frsl
- local c = 1
- for i = 1, val.inv_size do
- local amount = r.count(i)
- if amount > 0 then
- r.select(i)
- stack = icontroller.getStackInInternalSlot(i)
- inv.slot[c] = i
- inv.name[c] = stack.label
- inv.amount[c] = amount
- c = c + 1
- end
- end
- c = 1
- i = 1
- tunnel.send("3 "..s.serialize(inv))
- end
- --===================================--
- -- MOVEMENT FUNCTIONS --
- --===================================--
- function t.gf()
- local c = 1
- if act[2]==nil then act[2]=1 end
- for c = 1,act[2] do
- r.forward()
- end
- tunnel.send("1 Я сдвинулся на "..act[2].." блок(ов) вперёд")
- print("Я сдвинулся на "..act[2].." блок(ов) вперёд")
- c = 1
- end
- function t.gfd()
- local dblocks = 0
- if act[2]==nil then act[2]=1 end
- for c = 1,act[2] do
- repeat
- if r.swing() then dblocks = dblocks+1 end
- if r.swingUp() then dblocks = dblocks+1 end
- until r.detect()==false or r.detectUp()==false
- r.forward()
- if r.swingUp() then dblocks = dblocks+1 end
- end
- tunnel.send("1 Я сдвинулся на "..act[2].." блок(ов) вперёд и вскопал "..dblocks.." блок(ов)")
- print("Я сдвинулся на "..act[2].." блок(ов) вперёд и вскопал "..dblocks.." блок(ов)")
- c = 1
- end
- function t.gb()
- local c = 1
- if act[2]==nil then act[2]=1 end
- for c = 1,act[2] do
- r.back()
- end
- tunnel.send("1 Я сдвинулся на "..act[2].." блок(ов) назад")
- print("Я сдвинулся на "..act[2].." блок(ов) назад")
- c = 1
- end
- function t.up()
- local c = 1
- if act[2]==nil then act[2]=1 end
- for c = 1,act[2] do
- r.up()
- end
- tunnel.send("1 Я поднялся на "..act[2].." блок(ов)")
- print("Я поднялся на "..act[2].." блок(ов)")
- c = 1
- end
- function t.upd()
- local dblocks = 0
- local c = 1
- if act[2]==nil then act[2]=1 end
- for c = 1,act[2] do
- repeat
- if r.swingUp() then dblocks = dblocks+1 end
- until r.detectUp()==false
- r.up()
- if r.swingUp() then dblocks = dblocks+1 end
- end
- tunnel.send("1 Я поднялся на "..act[2].." блок(ов) и вскопал "..dblocks.." блок(ов)")
- print("Я поднялся на "..act[2].." блок(ов) и вскопал "..dblocks.." блок(ов)")
- c = 1
- end
- function t.dn()
- local c = 1
- if act[2]==nil then act[2]=1 end
- for c = 1,act[2] do
- r.down()
- end
- tunnel.send("1 Я спустился на "..act[2].." блок(ов)")
- print("Я спустился на "..act[2].." блок(ов)")
- c = 1
- end
- function t.dnd()
- local dblocks = 0
- local c = 1
- if act[2]==nil then act[2]=1 end
- for c = 1,act[2] do
- repeat
- if r.swingDown() then dblocks = dblocks+1 end
- until r.detectDown()==false
- r.down()
- end
- tunnel.send("1 Я спустился на "..act[2].." блок(ов) и вскопал "..dblocks.." блок(ов)")
- print("Я спустился на "..act[2].." блок(ов) и вскопал "..dblocks.." блок(ов)")
- c = 1
- end
- function t.tr()
- r.turnRight()
- tunnel.send("1 Я повернулся направо")
- print("Я повернулся направо")
- end
- function t.tl()
- r.turnLeft()
- tunnel.send("1 Я повернулся налево")
- print("Я повернулся налево")
- end
- function t.ta()
- r.turnAround()
- tunnel.send("1 Я повернулся на 180 градусов")
- print("Я повернулся на 180 градусов")
- end
- --===================================--
- -- USE FUNCTIONS --
- --===================================--
- function t.rs()
- if rsstatus=="выкл" then
- rsstatus="вкл"
- rs.setOutput(sides.front, 15)
- rs.setOutput(sides.bottom, 15)
- rs.setOutput(sides.top, 15)
- tunnel.send("1 Редстоун включен")
- print("Редстоун включен")
- else
- rsstatus="выкл"
- rs.setOutput(sides.front, 0)
- rs.setOutput(sides.bottom, 0)
- rs.setOutput(sides.top, 0)
- tunnel.send("1 Редстоун выключен")
- print("Редстоун выключен")
- end
- end
- function t.use()
- r.use()
- tunnel.send("1 Я щёлкнул правой мыши перед собой")
- print("Я щёлкнул правой мыши перед собой")
- end
- function t.useup()
- r.useUp()
- tunnel.send("1 Я щёлкнул правой мыши над собой")
- print("Я щёлкнул правой мыши над собой")
- end
- function t.usedn()
- r.useDown()
- tunnel.send("1 Я щёлкнул правой мыши под собой")
- print("Я щёлкнул правой мыши под собой")
- end
- --===================================--
- -- INVENTORY FUNCTIONS --
- --===================================--
- function t.drop()
- local amountItems = 0
- act[2] = tonumber(act[2])
- act[3] = tonumber(act[3])
- if act[3] == nil then
- if act[2] == nil then
- for d=1,val.inv_size do
- r.select(d)
- r.drop(r.count())
- end
- tunnel.send("1 Я выбросил все вещи перед собой(или в сундук)")
- print("Я выбросил все вещи перед собой(или в сундук)")
- else
- r.select(act[2])
- r.drop(r.count())
- tunnel.send("1 Я выбросил все вещи из слота "..act[2].." перед собой(или в сундук)")
- print("Я выбросил все вещи из слота "..act[2].." перед собой(или в сундук)")
- end
- else
- r.select(act[2])
- amountItems = r.count()
- r.drop(act[3])
- if act[3] > amountItems then
- tunnel.send("1 Я выбросил "..amountItems.." вещь(-ей) из слота "..act[2].." перед собой(или в сундук)")
- print("Я выбросил "..amountItems.." вещь(-ей) из слота "..act[2].." перед собой(или в сундук)")
- else
- tunnel.send("1 Я выбросил "..act[3].." вещь(-ей) из слота "..act[2].." перед собой(или в сундук)")
- print("Я выбросил "..act[3].." вещь(-ей) из слота "..act[2].." перед собой(или в сундук)")
- end
- end
- amountItems = 0
- r.select(1)
- end
- function t.dropup()
- local amountItems = 0
- act[2] = tonumber(act[2])
- act[3] = tonumber(act[3])
- if act[3] == nil then
- if act[2] == nil then
- for d=1,val.inv_size do
- r.select(d)
- r.dropUp(r.count())
- end
- tunnel.send("1 Я выбросил все вещи вверх(или в сундук)")
- print("Я выбросил все вещи вверх(или в сундук)")
- else
- r.select(act[2])
- r.dropUp(r.count())
- tunnel.send("1 Я выбросил все вещи из слота "..act[2].." вверх(или в сундук)")
- print("Я выбросил все вещи из слота "..act[2].." вверх(или в сундук)")
- end
- else
- r.select(act[2])
- amountItems = r.count()
- r.dropUp(act[3])
- if act[3] > amountItems then
- tunnel.send("1 Я выбросил "..amountItems.." вещь(-ей) из слота "..act[2].." вверх(или в сундук)")
- print("Я выбросил "..amountItems.." вещь(-ей) из слота "..act[2].." вверх(или в сундук)")
- else
- tunnel.send("1 Я выбросил "..act[3].." вещь(-ей) из слота "..act[2].." вверх(или в сундук)")
- print("Я выбросил "..act[3].." вещь(-ей) из слота "..act[2].." вверх(или в сундук)")
- end
- end
- amountItems = 0
- r.select(1)
- end
- function t.dropdn()
- local amountItems = 0
- act[2] = tonumber(act[2])
- act[3] = tonumber(act[3])
- if act[3] == nil then
- if act[2] == nil then
- for d=1,val.inv_size do
- r.select(d)
- r.dropDown(r.count())
- end
- tunnel.send("1 Я выбросил все вещи вниз(или в сундук)")
- print("Я выбросил все вещи вниз(или в сундук)")
- else
- r.select(act[2])
- r.dropDown(r.count())
- tunnel.send("1 Я выбросил все вещи из слота "..act[2].." вниз(или в сундук)")
- print("Я выбросил все вещи из слота "..act[2].." вниз(или в сундук)")
- end
- else
- r.select(act[2])
- amountItems = r.count()
- r.dropDown(act[3])
- if act[3] > amountItems then
- tunnel.send("1 Я выбросил "..amountItems.." вещь(-ей) из слота "..act[2].." вниз(или в сундук)")
- print("Я выбросил "..amountItems.." вещь(-ей) из слота "..act[2].." вниз(или в сундук)")
- else
- tunnel.send("1 Я выбросил "..act[3].." вещь(-ей) из слота "..act[2].." вниз(или в сундук)")
- print("Я выбросил "..act[3].." вещь(-ей) из слота "..act[2].." вниз(или в сундук)")
- end
- end
- amountItems = 0
- r.select(1)
- end
- function t.suck()
- r.select(1)
- while r.suck()==true do
- r.suck()
- end
- tunnel.send("1 Я забрал вещи перед собой(или из сундука)")
- print("Я забрал вещи перед собой(или из сундука)")
- end
- function t.suckup()
- r.select(1)
- while r.suckUp()==true do
- r.suckUp()
- end
- tunnel.send("1 Я забрал вещи над собой(или из сундука)")
- print("Я забрал вещи над собой(или из сундука)")
- end
- function t.suckdn()
- r.select(1)
- while r.suckDown()==true do
- r.suckDown()
- end
- tunnel.send("1 Я забрал вещи под собой(или из сундука)")
- print("Я забрал вещи под собой(или из сундука)")
- end
- function error()
- tunnel.send("1 Ошибка. Неправильная команда")
- print("Ошибка. Неправильная команда")
- end
- if obr then
- if event.ignore("modem_message",obr) then
- print("Слушатель удалён")
- else
- print("Слушатель не удалён")
- end
- end
- function _G.obr(_,_,_,_,_,com,_)
- local i = 1
- act = {}
- for word in string.gmatch(com, "%w+") do
- --print(word)
- act[i] = word
- i = i + 1
- end
- print(act[1])
- print(act[2])
- if t[act[1]] then t[act[1]]()
- else error()
- end
- end
- event.listen("modem_message",obr)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement