Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local args = {...}
- function split (inputstr, sep)
- if sep == nil then
- sep = "%s"
- end
- local t={}
- for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
- table.insert(t, str)
- end
- return t
- end
- local commands = {}
- commands["w"] = function()
- return turtle.forward()
- end
- commands["up"] = function()
- return turtle.up()
- end
- commands["down"] = function()
- return turtle.down()
- end
- commands["a"] = function()
- return turtle.turnLeft()
- end
- commands["d"] = function()
- return turtle.turnRight()
- end
- commands["dig"] = function()
- return turtle.dig()
- end
- commands["digup"] = function()
- return turtle.digUp()
- end
- commands["digdown"] = function()
- return turtle.digDown()
- end
- commands["place"] = function()
- return turtle.place()
- end
- commands["placeup"] = function()
- return turtle.placeUp()
- end
- commands["placedown"] = function()
- return turtle.placeDown()
- end
- commands["refuel"] = function()
- turtle.refuel()
- return "Fuel: " .. turtle.getFuelLevel()
- end
- local cnum = 1
- commands["nextslot"] = function()
- cnum = cnum + 1
- if turtle.select(cnum) then
- if turtle.getItemDetail(turtle.getSelectedSlot()) == nil then
- return "Empty Slot " .. turtle.getSelectedSlot()
- end
- return turtle.getItemDetail(turtle.getSelectedSlot()).name .. ": " .. turtle.getSelectedSlot()
- end
- end
- commands["prevslot"] = function()
- cnum = cnum - 1
- if turtle.select(cnum) then
- if turtle.getItemDetail(turtle.getSelectedSlot()) == nil then
- return "Empty Slot " .. turtle.getSelectedSlot()
- end
- return turtle.getItemDetail(turtle.getSelectedSlot()).name .. ": " .. turtle.getSelectedSlot()
- end
- end
- local side = args[1]
- if side == nil then
- side = "left"
- end
- rednet.open(side)
- while true do
- senderID, message, distance = rednet.receive()
- local cmds = split(message, " ")
- for i,v in pairs(cmds) do
- local toExec = commands[v]
- if toExec then
- local rmsg = toExec()
- rednet.send(senderID, rmsg)
- else
- rednet.send(senderID, "Invalid command!")
- end
- end
- end
- rednet.close(side)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement