Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- configuration section --
- turtle = 2044
- rednet.open("back")
- -- common with the pair --
- commands = {}
- commands.move = {}
- commands.place = {}
- commands.interact = {}
- commands.turn = {}
- commands.inventory = {}
- commands.utilities = {}
- commands.inventory.read = {}
- -- inventory commands --
- commands.inventory.select = "select slot"
- commands.inventory.read.slot = "get slot"
- commands.inventory.read.all = "get all items"
- commands.inventory.getSlot = "get slot selected"
- -- move commands --
- commands.move.forward = "move forward"
- commands.move.back = "move back"
- commands.move.up = "go up"
- commands.move.down = "go down"
- -- turn commands --
- commands.turn.left = "turn left"
- commands.turn.right = "turn right"
- -- interact commands --
- commands.interact.dig = "dig front"
- commands.interact.digUp = "dig up"
- commands.interact.digDown = "dig down"
- commands.interact.place = "place front"
- commands.interact.placeUp = "place up"
- commands.interact.placeDown = "place down"
- commands.interact.inspect = "inspect front"
- commands.interact.inspectUp = "inspect up"
- commands.interact.inspectDown = "inspect down"
- commands.interact.suck = "suck items"
- commands.interact.suckUp = "suck from up"
- commands.interact.suckDown = "suck from down"
- commands.interact.drop = "drop items"
- commands.interact.dropUp = "drop items up"
- commands.interact.dropDown = "drop items down"
- -- utilities commands --
- commands.utilities.fuel = "get fuel level"
- commands.utilities.refuel = "refuel from slot"
- -- keys --
- keys = {}
- keys.move = {}
- keys.interact = {}
- keys.turn = {}
- keys.control = {}
- -- move keys --
- keys.move.forward = 17
- keys.move.back = 31
- keys.move.up = 200
- keys.move.down = 208
- -- turn keys --
- keys.turn.left = 30
- keys.turn.right = 32
- -- interact keys --
- keys.interact.place = 75
- keys.interact.placeUp = 71
- keys.interact.placeDown = 79
- keys.interact.dig = 77
- keys.interact.digUp = 73
- keys.interact.digDown = 81
- keys.interact.inspect = 76
- keys.interact.inspectUp = 72
- keys.interact.inspectDown = 80
- -- control keys --
- keys.control.main = 19
- keys.control.fuel = 33
- function termClear()
- term.clear()
- term.setCursorPos(1,1)
- end
- function help()
- print("Help: ")
- print("help, remote, get item")
- print("get inventory, clear")
- commandListener()
- end
- function remote()
- event, key, d = os.pullEvent("key")
- remoteKeyAct(key)
- end
- function remoteKeyAct(key)
- if key == keys.move.forward then
- commandPack = {}
- commandPack.command = commands.move.forward
- msg = textutils.serialise(commandPack)
- rednet.send(turtle, msg)
- elseif key == keys.move.back then
- commandPack = {}
- commandPack.command = commands.move.back
- msg = textutils.serialise(commandPack)
- rednet.send(turtle, msg)
- elseif key == keys.move.up then
- commandPack = {}
- commandPack.command = commands.move.up
- msg = textutils.serialise(commandPack)
- rednet.send(turtle, msg)
- elseif key == keys.move.down then
- commandPack = {}
- commandPack.command = commands.move.down
- msg = textutils.serialise(commandPack)
- rednet.send(turtle, msg)
- elseif key == keys.turn.left then
- commandPack = {}
- commandPack.command = commands.turn.left
- msg = textutils.serialise(commandPack)
- rednet.send(turtle, msg)
- elseif key == keys.turn.right then
- commandPack = {}
- commandPack.command = commands.turn.right
- msg = textutils.serialise(commandPack)
- rednet.send(turtle, msg)
- elseif key == keys.control.main then
- startScreen()
- elseif key == keys.control.fuel then
- commandPack = {}
- commandPack.command = commands.utilities.fuel
- msg = textutils.serialise(commandPack)
- rednet.send(turtle, msg)
- receiveMessage()
- recTab = textutils.unserialise(message)
- print("Fuel Level: "..recTab.fuel)
- elseif key == keys.interact.dig then
- commandPack = {}
- commandPack.command = commands.interact.dig
- msg = textutils.serialise(commandPack)
- rednet.send(turtle, msg)
- elseif key == keys.interact.digUp then
- commandPack = {}
- commandPack.command = commands.interact.digUp
- msg = textutils.serialise(commandPack)
- rednet.send(turtle, msg)
- elseif key == keys.interact.digDown then
- commandPack = {}
- commandPack.command = commands.interact.digDown
- msg = textutils.serialise(commandPack)
- rednet.send(turtle, msg)
- elseif key == keys.interact.place then
- commandPack = {}
- commandPack.command = commands.interact.place
- msg = textutils.serialise(commandPack)
- rednet.send(turtle, msg)
- elseif key == keys.interact.placeUp then
- commandPack = {}
- commandPack.command = commands.interact.placeUp
- msg = textutils.serialise(commandPack)
- rednet.send(turtle, msg)
- elseif key == keys.interact.placeDown then
- commandPack = {}
- commandPack.command = commands.interact.placeDown
- msg = textutils.serialise(commandPack)
- rednet.send(turtle, msg)
- elseif key == keys.interact.inspect then
- commandPack = {}
- commandPack.command = commands.interact.inspect
- msg = textutils.serialise(commandPack)
- rednet.send(turtle, msg)
- receiveMessage()
- recTab = textutils.unserialise(message)
- print("front: "..recTab.name)
- elseif key == keys.interact.inspectUp then
- commandPack = {}
- commandPack.command = commands.interact.inspectUp
- msg = textutils.serialise(commandPack)
- rednet.send(turtle, msg)
- receiveMessage()
- recTab = textutils.unserialise(message)
- print("up: "..recTab.name)
- elseif key == keys.interact.inspectDown then
- commandPack = {}
- commandPack.command = commands.interact.inspectDown
- msg = textutils.serialise(commandPack)
- rednet.send(turtle, msg)
- receiveMessage()
- recTab = textutils.unserialise(message)
- print("down: "..recTab.name)
- end
- remote()
- end
- function getItems()
- termClear()
- commandPack = {}
- commandPack.command = commands.inventory.read.all
- msg = textutils.serialise(commandPack)
- rednet.send(turtle, msg)
- receiveMessage()
- tab = textutils.unserialise(message)
- print("turtle inventory")
- for i=1,16 do
- x = tab[i].name
- y = tab[i].amount
- print(i..": "..y.."x"..x)
- end
- commandListener()
- end
- function getItem()
- termClear()
- print("enter slot")
- slot = read()
- commandPack = {}
- commandPack.command = commands.inventory.read.slot
- commandPack.slot = slot
- msg = textutils.serialise(commandPack)
- rednet.send(turtle, msg)
- receiveMessage()
- recTab = textutils.unserialise(message)
- termClear()
- print(slot..": "..recTab.amount.."x"..recTab.name)
- commandListener()
- end
- function receiveMessage()
- id, msg = rednet.receive()
- if id == turtle then
- message = msg
- else
- receiveMessage()
- end
- end
- function commandListener()
- command = read()
- if command == "remote" then
- termClear()
- remote()
- elseif command == "help" then
- help()
- elseif command == "clear" then
- startScreen()
- elseif command == "select" then
- print("enter the number of slot")
- slot = read()
- commandPack = {}
- commandPack.command = commands.inventory.select
- commandPack.slotNum = slot
- msg = textutils.serialise(commandPack)
- rednet.send(turtle, msg)
- commandListener()
- elseif command == "get item" then
- getItem()
- elseif command == "get inventory" then
- getItems()
- elseif command == "get slot" then
- commandPack = {}
- commandPack.command = commands.inventory.getSlot
- x = textutils.serialise(commandPack)
- rednet.send(turtle, x)
- receiveMessage()
- msg = textutils.unserialise(message)
- print("selected slot: "..msg.slot)
- commandListener()
- elseif command == "suck up" then
- commandPack = {}
- commandPack.command = commands.interact.suckUp
- x = textutils.serialise(commandPack)
- rednet.send(turtle, x)
- elseif command == "suck down" then
- commandPack = {}
- commandPack.command = commands.interact.suckDown
- x = textutils.serialise(commandPack)
- rednet.send(turtle, x)
- elseif command == "suck" then
- commandPack = {}
- commandPack.command = commands.interact.suck
- x = textutils.serialise(commandPack)
- rednet.send(turtle, x)
- elseif command == "drop up" then
- commandPack = {}
- commandPack.command = commands.interact.dropUp
- x = textutils.serialise(commandPack)
- rednet.send(turtle, x)
- elseif command == "drop down" then
- commandPack = {}
- commandPack.command = commands.interact.dropDown
- x = textutils.serialise(commandPack)
- rednet.send(turtle, x)
- elseif command == "drop" then
- commandPack = {}
- commandPack.command = commands.interact.drop
- x = textutils.serialise(commandPack)
- rednet.send(turtle, x)
- end
- end
- function startScreen()
- termClear()
- print("welcome to the controller")
- print("enter your commands")
- commandListener()
- end
- startScreen()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement