Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- serverProtocol="update"
- serverId=0
- print("Starting turtle!")
- posX,posY,posZ=gps.locate()
- function locate()
- posX,posY,poZ=gps.locate()
- end
- for i=1,5 do
- for i=16,1,-1 do
- slot=turtle.getItemDetail(i)
- if slot~=nil then
- if(slot.name=="computercraft:wireless_modem_advanced") then
- print("Equiping modem")
- turtle.select(i)
- turtle.equipLeft()
- break
- end
- if(slot.name=="minecraft:diamond_pickaxe") then
- print("Equiping Pickaxe")
- turtle.select(i)
- turtle.equipRight()
- slot=turtle.getItemDetail(i)
- if slot~=nil then
- if(slot.name=="advancedperipherals:geo_scanner") then
- print("Transfering Geo Scanner!")
- turtle.select(i)
- turtle.transferTo(16,1)
- break
- end
- end
- break
- end
- if(slot.name=="advancedperipherals:geo_scanner" and i~=16) then
- print("Transfering Geo Scanner!")
- turtle.select(i)
- turtle.transferTo(16,1)
- break
- end
- end
- end
- end
- peripheral.find("modem", rednet.open)
- while rednet.lookup(serverProtocol)==nil do
- sleep(1)
- print("Couldn't find main server. Retrying again soon!")
- end
- serverId=rednet.lookup(serverProtocol)
- function runProgram()
- shell.run("mainTurtle.lua")
- end
- lastMessage=os.clock()
- isWaiting=false
- function resetIfIdle()
- sleep(5)
- while isWaiting==false or lastMessage+20<os.clock() do
- sleep(2)
- end
- print("DIDNT RECEIVE CODE, RESENDING")
- end
- function getCode()
- while true do
- lastMessage=os.clock()
- isWaiting=true
- rednet.send(serverId,"mainTurtle.lua",serverProtocol)
- local event, sender, message, protocol = os.pullEvent("rednet_message")
- isWaiting=false
- if protocol ~= nil then
- -- print("Received message from " .. sender .. " with protocol " .. protocol .. " and message " .. tostring(message))
- if protocol==serverProtocol then
- lastMessage=os.clock()
- shell.run("rm mainTurtle.lua")
- write_string_to_file("mainTurtle.lua", message)
- success,err=pcall(runProgram)
- if success==false then
- print(err)
- end
- print("Restarting soon!")
- sleep(10)
- lastMessage=os.clock()
- end
- end
- end
- end
- function write_string_to_file(filename, content)
- local file = assert(io.open(filename, "w")) -- open in write mode (overwrite)
- file:write(content)
- file:close()
- end
- while true do
- parallel.waitForAny(resetIfIdle,getCode)
- sleep(0)
- end
Advertisement
Add Comment
Please, Sign In to add comment