Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- leash for turtle quarry
- local width, height = term.getSize()
- local turtleAmount = 6
- local distance = 300 --needs to be serialized and saved
- local turtleFuel = 211
- rednet.open("back")
- function display()
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1, 1)
- term.setTextColor(colors.lime)
- print("Trtl Leash")
- displayButtons()
- end
- function displayButtons()
- term.setBackgroundColor(colors.lime)
- term.setTextColor(colors.white)
- -- setting distance of the turtle
- term.setCursorPos(width-2, height)
- term.write("-|+")
- term.setCursorPos(width-2, height-1)
- term.write(distance)
- term.setCursorPos(width-3, height-3)
- term.write("coal")
- term.setCursorPos(width-3, height-4)
- term.write(calcFuel())
- term.setCursorPos(width-3, height-6)
- term.setBackgroundColor(colors.red)
- term.write("STOP")
- term.setCursorPos(width-3, height-7)
- term.setBackgroundColor(colors.green)
- term.write("STAR")
- term.setCursorPos(width-3, height-9)
- term.setBackgroundColor(colors.orange)
- term.write("STAT")
- term.setCursorPos(width-3, height-10)
- term.setBackgroundColor(colors.brown)
- term.write("DUMP")
- term.setCursorPos(width-3, height-12)
- term.setBackgroundColor(colors.green)
- term.write("TURN")
- term.setCursorPos(width-3, height-13)
- term.setBackgroundColor(colors.green)
- term.write("DOWN")
- end
- function getinput()
- while true do
- local ev, btn, x, y = os.pullEvent("mouse_click")
- checkStatus(x,y)
- checkStart(x,y)
- checkStop(x,y)
- checkSubDistance(x,y)
- checkAddDistance(x,y)
- checkDump(x,y)
- turn(x,y)
- down(x,y)
- end
- end
- function down(x,y)
- if x >= width-3 and y == height-13 then
- rednet.broadcast(createPacket("down", nil), "lbsm")
- term.setTextColor(colors.white)
- term.setCursorPos(1,2)
- term.write("Going down")
- sleep(1)
- display()
- end
- end
- function turn(x,y)
- if x >= width-3 and y == height-12 then
- rednet.broadcast(createPacket("turn", nil), "lbsm")
- term.setTextColor(colors.white)
- term.setCursorPos(1,2)
- term.write("Turning")
- sleep(1)
- display()
- end
- end
- function createPacket(comm, info)
- return {command=comm,msg=info}
- end
- function checkDump(x,y)
- if x >= width-3 and y == height-10 then
- rednet.broadcast(createPacket("dump", nil), "lbsm")
- end
- end
- function checkStart(x, y)
- if x >= width-3 and y == height-7 then
- rednet.broadcast(createPacket("start", distance),"lbsm")
- term.setTextColor(colors.white)
- term.setCursorPos(1,2)
- term.write("Starting")
- sleep(1)
- display()
- end
- end
- function checkStop(x, y)
- if x >= width-3 and y == height-6 then
- rednet.broadcast(createPacket("stop", nil),"lbsm")
- term.setTextColor(colors.white)
- term.setCursorPos(1,2)
- term.write("Stop")
- sleep(1)
- display()
- end
- end
- function checkStatus(x, y)
- if x >= width-3 and y == height-9 then
- rednet.broadcast(createPacket("status", nil),"lbsm")
- end
- end
- function checkAddDistance(x, y)
- if x == width and y == height then
- distance = distance + 10
- if distance > 999 then distance = 990 end
- display()
- end
- end
- function checkSubDistance(x, y)
- if x == width-2 and y == height then
- distance = distance - 10
- if distance < 1 then distance = 10 end
- display()
- end
- end
- function calcFuel()
- local blockFuelCost = 3
- local fuelCost = blockFuelCost * distance
- return math.ceil(fuelCost / 80) * turtleAmount
- end
- function getMessage()
- local event, id, msg = os.pullEvent("rednet_message")
- display()
- term.setCursorPos(1,2)
- print(textutils.serialize(msg))
- sleep(1)
- end
- display()
- displayButtons()
- while true do
- parallel.waitForAny(getinput, getMessage)
- end
Advertisement
Add Comment
Please, Sign In to add comment