Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --pastebin get UmdpF2ZD probe
- local robot = require("robot")
- local component = require("component")
- local modem = component.modem
- local inv_c = component.inventory_controller
- local nav = component.navigation
- local gen = component.generator
- local geo = component.geolyzer
- local event = require("event")
- local sides = require("sides")
- local serialization = require("serialization")
- local computer = require("computer")
- modem.open(346)
- address = component.get(modem.address)
- rName = robot.name()
- authorization = true
- oresAndBlocks = {}
- analyzes = {}
- userAddresses = {}
- cmps = {}
- result = false
- activatorMain = true
- function robotMoveing()
- for dst,fnc in pairs(moveings) do
- if count == tostring(dst) then
- if count == "up" or count == "down" or count == "forward" or count == "back" then
- for i = 1, count1 do
- fnc()
- end
- else
- fnc()
- rFacing = nav.getFacing()
- if rFacing == 2 then
- rFacing = "North"
- elseif rFacing == 3 then
- rFacing = "South"
- elseif rFacing == 4 then
- rFacing = "West"
- elseif rFacing == 5 then
- rFacing = "East"
- end
- end
- end
- end
- scanAll()
- end
- function rSwing()
- if robot.swing(tonumber(count1)) then
- modem.send(addressUser, 346, "This done")
- else
- modem.send(addressUser, 346, "Wrong instrument")
- end
- end
- function rPlace()
- if robot.place(tonumber(count1)) then
- modem.send(addressUser, 346, "This done")
- else
- modem.send(addressUser, 346, "Can't place this block")
- end
- end
- function rAnalyze()
- os.sleep(0.5)
- nlz = geo.analyze(tonumber(count1))
- modem.send(addressUser, 346, nlz.name.." "..nlz.metadata)
- end
- function rRecieve()
- modem.send(addressUser, 346, serialization.serialize(oresAndBlocks))
- end
- function rUse()
- val, val1 = robot.use(tonumber(count1))
- if val then
- modem.send(addressUser, 346, val1)
- end
- end
- function rInventory()
- slotNumber = tonumber(count2)
- for kSlot,vSlot in pairs(slots) do
- if count1 == tostring(kSlot) then
- itemsInSlot = vSlot(slotNumber)
- end
- end
- if type(itemsInSlot) == "table" then
- modem.send(addressUser, 346, "label="..itemsInSlot.label..", ".."maxSize="..tostring(itemsInSlot.maxSize)..", ".."size="..tostring(itemsInSlot.size))
- elseif itemInSlot == nil then
- modem.send(addressUser, 346, "Slot is empty")
- end
- end
- function rGenerator()
- for kGen,vGen in pairs(generatorFuncs) do
- if count1 == tostring(kGen) then
- genCount = vGen(tonumber(count2))
- end
- end
- modem.send(addressUser, 346, tostring(genCount))
- end
- function rEnergy()
- rNrg = tostring(computer.energy())
- modem.send(addressUser, 346, rNrg)
- end
- function rEquip()
- local val = inv_c.equip()
- modem.send(addressUser, 346, tostring(val))
- end
- generatorFuncs = {
- cnt = gen.count,
- inst = gen.insert,
- rmv = gen.remove}
- slots = {
- internal = inv_c.getStackInInternalSlot,
- chest = inv_c.getStackInSlot,
- rSelect = robot.select}
- moveings = {
- up = robot.up,
- down = robot.down,
- forward = robot.forward,
- back = robot.back,
- left = robot.turnLeft,
- right = robot.turnRight,
- around = robot.turnAround}
- actions = {
- up = robotMoveing,
- down = robotMoveing,
- forward = robotMoveing,
- back = robotMoveing,
- left = robotMoveing,
- right = robotMoveing,
- around = robotMoveing,
- swing = rSwing,
- place = rPlace,
- analyze = rAnalyze,
- recieve = rRecieve,
- use = rUse,
- inventory = rInventory,
- generator = rGenerator,
- energy = rEnergy,
- equip = rEquip}
- file2 = io.open("userAddresses", "r")
- for line in file2:lines() do table.insert(userAddresses, line) end
- --print(userAddresses[#userAddresses])
- file2:close()
- function authorize()
- while authorization do
- local _,addressTo,addressFrom,_,_,message = event.pull(0.1, "modem")
- if message == "Authorize me!" then
- addressUser = addressFrom
- for i = 1, #userAddresses do
- if addressUser == userAddresses[i] then
- result = true
- break
- else
- result = false
- end
- end
- if not result then
- file3 = io.open("userAddresses", "a")
- table.insert(userAddresses, addressUser)
- file3:write("\n"..addressUser)
- file3:close()
- print("true")
- else
- print("false")
- end
- rFacing = nav.getFacing()
- if rFacing == 2 then
- rFacing = "North"
- elseif rFacing == 3 then
- rFacing = "South"
- elseif rFacing == 4 then
- rFacing = "West"
- elseif rFacing == 5 then
- rFacing = "East"
- end
- cmps[1] = robot.inventorySize()
- modem.send(addressUser, 346, "Authorization complete", address, rName, serialization.serialize(cmps), rFacing)
- authorization = false
- print(addressUser)
- end
- end
- end
- file = io.open("oresAndBlocks", "r")
- for line in file:lines() do
- table.insert(oresAndBlocks, line)
- end
- file:close()
- function scanAll()
- --file1 = io.open("oresAndBlocks", "a")
- for i = 0, 5 do
- --if i ~= 2 then
- analyzeOp = geo.analyze(i)
- for k,v in pairs(oresAndBlocks) do
- if analyzeOp.name.." "..analyzeOp.metadata == v then
- result = true
- break
- else
- result = false
- end
- end
- if not result then
- file1 = io.open("oresAndBlocks", "a")
- table.insert(oresAndBlocks, analyzeOp.name.." "..analyzeOp.metadata)
- file1:write("\n"..analyzeOp.name.." "..analyzeOp.metadata)
- file1:close()
- end
- table.insert(analyzes, analyzeOp.name.." "..analyzeOp.metadata)
- --end
- end
- --for i = 1, #analyzes do
- --for l = 1, #oresAndBlocks do
- --if analyzes[i] == oresAndBlocks[l] then
- --result = true
- --end
- --if not result then
- --table.insert(oresAndBlocks, analyzes[i])
- --file1:write("\n"..analyzes[i])
- --end
- --end
- --end
- for i = 1, #analyzes do
- print(analyzes[i])
- end
- print(#oresAndBlocks)
- for i = 1, #oresAndBlocks do
- print(oresAndBlocks[i])
- end
- modem.send(addressUser, 346, serialization.serialize(analyzes), rFacing)
- analyzes = {}
- --file1:close()
- end
- function recieving()
- while activatorMain do
- local _,addressTo,addressFrom,_,_,message,message1,message2,message3 = event.pull(0.1, "modem")
- if message ~= nil then
- if addressFrom == addressUser then
- count = message
- count1 = message1
- count2 = message2
- count3 = message3
- for func,act in pairs(actions) do
- if message == tostring(func) then
- act()
- end
- end
- else
- for i = 1, #userAddresses do
- print(userAddresses[i])
- if addressFrom == userAddresses[i] then
- addressUser = addressFrom
- print(addressUser)
- end
- end
- end
- end
- end
- end
- --scanAll()
- authorize()
- recieving()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement