Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- serverProtocol="turtleServer"
- serverId=0
- salt = require("salt")
- 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)
- print("Found the main server! id:",serverId)
- rednet.send(serverId,"startup",serverProtocol)
- currentAction="Starting Up"
- function main()
- currentAction="Idle"
- scanWorld()
- parallel.waitForAny(checkRednet)
- print("Program broke :(")
- end
- function scanWorld()
- turtle.select(16)
- turtle.equipRight()
- geo=peripheral.wrap("right")
- scan=geo.scan(8)
- salt.save(scan,"scan1")
- locate()
- for i,v in ipairs(scan) do
- scan.x=scan.x+posX
- scan.y=scan.y+posX
- scan.z=scan.z+posX
- end
- salt.save(scan,"scan2")
- print(textutils.serialize(scan))
- response={action=currentAction,x=posX,y=posY,z=posZ,fuelLevel=turtle.getFuelLevel()}
- messageBack="worldScan$"..textutils.serialize(response)
- messageBack = messageBack:gsub("\n", "")
- rednet.send(serverId,messageBack,serverProtocol)
- rednet.send(serverId,)
- end
- function splitString(inputstr, sep)
- if sep == nil then
- sep = "%s"
- end
- i=1
- local t = {}
- for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
- t[i]=str
- end
- return t
- end
- function checkRednet()
- while true do
- local event, sender, message, protocol = os.pullEvent("rednet_message")
- if protocol ~= nil then
- --print("Received message from " .. sender .. " with protocol " .. protocol .. " and message " .. tostring(message))
- if protocol==serverProtocol then
- --print("Received message from " .. sender .. " with protocol " .. protocol .. " and message " .. tostring(message))
- if message=="status" then
- posX,posY,posZ=gps.locate()
- response={action=currentAction,x=posX,y=posY,z=posZ,fuelLevel=turtle.getFuelLevel()}
- messageBack="responseStatus$"..textutils.serialize(response)
- messageBack = messageBack:gsub("\n", "")
- rednet.send(serverId,messageBack,serverProtocol)
- elseif message=="rebootAll" then
- shell.run("reboot")
- end
- end
- else
- --print("Received message from " .. sender .. " with message " .. tostring(message))
- end
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment