Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Movement Keys
- kForward = "w"
- kLeft = "a"
- kBack = "s"
- kRight = "d"
- kUp = "space"
- kDown = "leftShift"
- kQuit = "q"
- kMine = "r"
- -- Maximum distance to move/mine in one command
- maxDistance = 50
- -- Cable colors
- -- Must be defined as colors.colorName
- -- See - http://computercraft.info/wiki/Colors_%28API%29 for color names
- up = colors.green
- down = colors.lightBlue
- left = colors.lightGray
- right = colors.orange
- forward = colors.white
- backward = colors.purple
- -- Cable Sides
- aSide = "bottom"
- bSide = "top"
- power = "back"
- -- Timer Settings (in seconds)
- chargeTime = .5
- mineTime = 8
- moveTime = .25
- -- Dont Change anything after this!
- w,h = term.getSize()
- manMine = false
- rs.setOutput(power,manMine)
- function center(s)
- _,y = term.getCursorPos()
- x = math.floor( (w/2) - (string.len(s)/2) )
- term.setCursorPos(x,y)
- print(s)
- end
- function header()
- term.clear()
- term.setCursorPos(1,1)
- center("####################")
- center("# Funky Locomotion #")
- center("# Control Panel #")
- center("####################")
- print("")
- end
- function dotdot(str,amt)
- header()
- term.write(str)
- if amt>=1 then
- for i=1,math.ceil(amt) do
- term.write(".")
- sleep(1)
- end
- else
- term.write(".")
- sleep(amt)
- end
- end
- function move(direction,doMine)
- print("Preparing to Move")
- sleep(1)
- if doMine then
- rs.setOutput(power,true)
- rs.setBundledOutput(aSide,direction)
- dotdot("Moving Part A",moveTime)
- rs.setBundledOutput(aSide,0)
- dotdot("Mine Cycle A",mineTime)
- rs.setBundledOutput(bSide,direction)
- dotdot("Moving Part B",moveTime)
- rs.setBundledOutput(bSide,0)
- dotdot("Mine Cycle B",mineTime)
- print("\nMining Complete.")
- rs.setOutput(power,false)
- else
- rs.setBundledOutput(aSide,direction)
- dotdot("Moving Part A",moveTime)
- rs.setBundledOutput(aSide,0)
- dotdot("Charge Cycle",chargeTime)
- rs.setBundledOutput(bSide,direction)
- dotdot("Moving Part B",moveTime)
- rs.setBundledOutput(bSide,0)
- end
- print("\nMove Complete")
- sleep(1)
- end
- function instructions()
- header()
- if manual then
- center("Manual Override Mode")
- center("--------------------")
- print(kForward .. " - forward")
- print(kLeft .. " - left")
- print(kBack .. " - back")
- print(kRight .. " - right")
- print(kUp .. " - up")
- print(kDown .. " - down")
- print(kQuit .. " - quit manual override")
- print(kMine .. " - Toggle Mining Power")
- print("\n\nMining Power - " .. tostring(manMine))
- else
- print("Commands - ")
- print(" move direction amount")
- print(" mine direction amount")
- print(" manualoverride")
- print(" exit")
- print("\nValid Names: forward backward up down left right")
- print("\nEnter Command")
- end
- end
- function manualoverride()
- doloop = true
- while doloop do
- instructions()
- e,p1,p2,p3 = os.pullEvent()
- if e == "key" then
- key = keys.getName(p1)
- if key == kForward and not p2 then
- move(forward)
- elseif key == kBack and not p2 then
- move(backward)
- elseif key == kLeft and not p2 then
- move(left)
- elseif key == kRight and not p2 then
- move(right)
- elseif key == kUp and not p2 then
- move(up)
- elseif key == kDown and not p2 then
- move(down)
- elseif key == kMine and not p2 then
- if manMine then
- manMine = false
- else
- manMine = true
- end
- rs.setOutput(power,manMine)
- elseif key == kQuit then
- doloop = false
- print("Ending Program.")
- sleep(1)
- end
- end
- end
- end
- function checkDirection(dir)
- if dir then
- dir = string.lower(dir)
- print("Checking " .. dir )
- if dir == "forward" or dir == "backward" or dir == "left" or dir == "right" or dir == "up" or dir == "down" then
- print("Match Found for direction")
- return true
- else
- print(dir .. " is not a valid direction")
- end
- else
- print("Please enter a valid direction")
- end
- end
- function checkDirectionAmount(n)
- if n then
- num = tonumber(n)
- if num then
- if num >= 1 and num <= maxDistance then
- return true
- else
- print("Distance must be between 1 and " .. tostring(maxDistance))
- end
- end
- else
- print("Distance Number is required")
- end
- end
- function convertDirection(dir)
- if dir == "forward" then
- return forward
- elseif dir == "backward" then
- return backward
- elseif dir == "left" then
- return left
- elseif dir == "right" then
- return right
- elseif dir == "up" then
- return up
- elseif dir == "down" then
- return down
- end
- end
- manual = false
- runController = true
- while runController do
- instructions()
- cmd_temp = io.read()
- args = {}
- for arg in cmd_temp:gmatch("%w+") do
- table.insert(args, arg)
- end
- if args[1] then
- cmd = string.lower(args[1])
- if cmd == "move" or cmd == "mine" then
- if checkDirection(args[2]) then
- if checkDirectionAmount(args[3]) then
- for i=1,math.floor(tonumber(args[3])) do
- if cmd == "mine" then
- move(convertDirection(string.lower(args[2])),true)
- else
- move(convertDirection(string.lower(args[2])))
- end
- end
- end
- end
- sleep(1)
- elseif string.lower(args[1]) == "manualoverride" or string.lower(args[1]) == "man" then
- manual = true
- manualoverride()
- manual = false
- elseif string.lower(args[1]) == "exit" then
- runController = false
- else
- print("Unknown Command")
- sleep(1)
- end
- else
- print("No Command Entered")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment