Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Turtle Tracking
- -- ----------------------------------------------------------
- -- Which turtles are alive?
- -- ----------------------------------------------------------
- -- Initialise important values:
- local turtles = {
- ["BBCrafter1"] = {["timer"] = os.startTimer(300), ["strike"] = 1},
- ["BBFarmer1"] = {["timer"] = os.startTimer(300), ["strike"] = 1},
- ["BBChopper1"] = {["timer"] = os.startTimer(300), ["strike"] = 1},
- ["BBChopper2"] = {["timer"] = os.startTimer(300), ["strike"] = 1},
- ["BBChopper3"] = {["timer"] = os.startTimer(300), ["strike"] = 1}}
- local bgs = {colours.green,colours.orange,colours.red,colours.grey}
- local mon, myEvent = peripheral.wrap("left")
- local function monPrint(someText)
- mon.write(someText)
- local monX,monY = mon.getCursorPos()
- mon.setCursorPos(1,monY+1)
- end
- mon.setTextScale(1.5)
- rednet.open("top")
- term.clear()
- term.setCursorPos(1,1)
- print("I'm a turtle server.")
- print("")
- print("My goal is to keep track of which turtles are active.")
- os.startTimer(0)
- while true do
- myEvent = {os.pullEvent()}
- if myEvent[1] == "rednet_message" and type(myEvent[3]) == "table" and myEvent[3][1] == "Hello TurtleServer" then
- turtles[myEvent[3][2]].id = myEvent[2]
- turtles[myEvent[3][2]].timer = os.startTimer(300)
- turtles[myEvent[3][2]].strike = 1
- os.startTimer(0)
- elseif myEvent[1] == "timer" then
- mon.setBackgroundColor(colours.black)
- mon.clear()
- mon.setCursorPos(1,1)
- monPrint("Alive Turtles")
- monPrint("=============")
- monPrint("")
- for aTurtle,data in pairs(turtles) do
- if data.timer == myEvent[2] then
- if data.id then rednet.send(data.id,"Hey, you still there?") end
- data.strike = data.strike + 1
- if data.strike > 4 then
- data.strike = 4
- if aTurtle:sub(1,9) == "BBChopper" and turtles["BBCrafter1"].id then rednet.send(turtles["BBCrafter1"].id,{"We need a new turtle.",aTurtle}) end
- data.timer = os.startTimer(1800)
- else
- data.timer = os.startTimer(300)
- end
- end
- mon.setBackgroundColor(bgs[data.strike])
- monPrint(aTurtle)
- monPrint("")
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement