local function termClear() term.clear() -- Paint the entire display with the current background colour. term.setCursorPos(1,1) -- Move the cursor to the top left position. end local slot local function check() if turtle.getFuelLevel() < 5 then turtle.select(16) turtle.refuel(1) turtle.select(slot) end end local actionMap = {} local function addActionMapAction(compType, name, act) local actionGroupID = #actionMap + 1 actionMap[actionGroupID] = {} actionMap[actionGroupID].name = name actionMap[actionGroupID].act = act actionMap[actionGroupID].compType = compType end local function getActionByName(name) for i,v in pairs(actionMap) do if v.name == name then return v end end end local function getActionIDByKeybind(key) for i,v in pairs(actionMap) do if v.key == key then return i end end end local function updateActionSendByName(name, func) for i,v in pairs(actionMap) do if v.name == name then actionMap[i].send = func end end end local function getActionNumberByName(id) for i,v in pairs(actionMap) do if v.name == name then return i,v end end end local function registerKeybind(key, actionName) for i,v in pairs(actionMap) do if v.name == actionName then v.key = key; return end end end local function registerAll() addActionMapAction( "Turtle", "Move Forward", function() check(); turtle.forward(); end ) addActionMapAction( "Turtle", "Move Back", function() check(); turtle.back(); end ) addActionMapAction( "Turtle", "Turn Left", function() turtle.turnLeft(); end ) addActionMapAction( "Turtle", "Turn Right", function() turtle.turnRight(); end ) addActionMapAction( "Turtle", "Move Up", function() check(); turtle.up(); end ) addActionMapAction( "Turtle", "Move Down", function() check() turtle.down() end ) addActionMapAction( "Turtle","Exfiltrate", function() turtle.suck(); turtle.dropDown(); turtle.select(slot); end ) addActionMapAction( "Turtle", "Drop All", function() local currentslot = slot slot = 1 while slot < 15 do turtle.select(slot); turtle.dropDown(); slot = slot + 1; end slot = currentslot end ) addActionMapAction( "Turtle", "Dig", function() turtle.select(15) turtle.dig() turtle.select(slot) end ) addActionMapAction( "Turtle", "Place", function() turtle.select(15) turtle.place() turtle.select(slot) end ) end local function ControllerMaster() local run = 1 local function registerAllKeys() registerKeybind(keys.w, "Move Forward") registerKeybind(keys.w, "Move Forward") registerKeybind(keys.a, "Turn Left") registerKeybind(keys.s, "Move Back") registerKeybind(keys.d, "Turn Right") registerKeybind(keys.e, "Move Up") registerKeybind(keys.q, "Move Down") registerKeybind(keys.f, "Exfiltrate") registerKeybind(keys.r, "Dig") registerKeybind(keys.c, "Place") registerKeybind(keys.x, "Drop All") end local function getActionByKeybind(key) for i,v in pairs(actionMap) do if v.key == key then return v end end end local function init() registerAll() registerAllKeys() termClear() rednet.open("back") print("Remote Control Console") print("--------------------------") print("WASD to move.") for i,v in pairs(actionMap) do --print(v.name) if v.key ~= nil then print(string.upper(keys.getName(v.key)) .. " to " .. v.name ..".") end end print("--------------------------") end init() while run == 1 do local event, param1, param2, param3 = os.pullEvent() if event == "key" then local id = getActionIDByKeybind(param1) rednet.broadcast(string.format("%03d", tonumber(id))) end end end local function ControllerSlave() slot = 1 local actions = {} local function register(msg, func) print(test) end local function init() registerAll() rednet.open("right") termClear() print("Remote Control Turtle") print("---------------------------------------") print("Receiver ready. Awaiting to pair") print("Fuel is used from slot 16.") print("---------------------------------------") end init() while true do local event, param1, param2, param3 = os.pullEvent() if event == "rednet_message" then local message = param2 print("gsub:" .. message) if #message == 3 and tonumber(message,10) then local number = tonumber(message,10) print(number .. " : " .. actionMap[number].name) actionMap[number].act() end end end end if turtle then ControllerSlave() else ControllerMaster() end