MudkipTheEpic

GS Host Killer

Jun 3rd, 2013
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.63 KB | None | 0 0
  1. local brk=false
  2. local modem=peripheral.wrap("right")
  3. modem.closeAll()
  4. modem.open(65534)
  5. local function checkIfThereAreAnyLeft()
  6.     local e,s,c,r,m,d
  7.     modem.transmit(65534,65534,"PING")
  8.     local id=os.startTimer(2)
  9.     repeat
  10.          e,s,c,r,m,d=os.pullEventRaw()
  11.     until (e=="modem_message" and c==65534) or (e=="timer" and s==id)
  12.     if e=="timer" then return false end
  13.     return true
  14. end
  15. while true do
  16. if not checkIfThereAreAnyLeft() then print("Killed all GPS servers in range.") return end
  17. local modem=peripheral.wrap("right")
  18. modem.closeAll()
  19. modem.open(65534)
  20. local distanceT={}
  21. local coordsTable, coords=nil,nil
  22. local function getData()
  23. modem.transmit(65534,65534,"PING")
  24. local eventData
  25. repeat
  26.   eventData={os.pullEventRaw("modem_message")}
  27.   if eventData[5]==coords or coords==nil then return eventData end
  28.   --print("test")
  29. until eventData[1]=="terminate"
  30. return error("Terminated")
  31. end
  32. local function getCloser(func)
  33.     while true do
  34.         if turtle.detect() then turtle.dig() end
  35.         if turtle.detectUp() then turtle.digUp() end
  36.         if turtle.detectDown() then turtle.digDown() end
  37.         func()
  38.         local nDat=getData()
  39.         if nDat[6]>distanceT[#distanceT] or nDat[6]==1 then break
  40.         else
  41.             table.insert(distanceT,nDat[6])
  42.         end
  43.     end
  44. end
  45. local eventData=getData()
  46. coords=eventData[5]
  47. table.insert(distanceT,eventData[6])
  48. turtle.up()
  49. local nData=getData()
  50. table.insert(distanceT,nData[6])
  51. if distanceT[#distanceT-1]>distanceT[#distanceT] then
  52. --This means its higher
  53.     getCloser(turtle.up)
  54.     turtle.down()
  55.     turtle.dig()
  56. else
  57.     --Lower
  58.     getCloser(turtle.down)
  59.     turtle.up()
  60.     turtle.dig()
  61. end
  62. local eventData=getData()
  63. table.insert(distanceT,eventData[6])
  64. turtle.forward()
  65. local nData=getData()
  66. table.insert(distanceT,nData[6])
  67. if distanceT[#distanceT-1]>distanceT[#distanceT] then
  68.     --Keep going forward
  69.     getCloser(turtle.forward)
  70.     turtle.back()
  71. else
  72.     --Moonwalk
  73.     turtle.turnRight()
  74.     turtle.turnRight()
  75.     getCloser(turtle.forward)
  76.     turtle.back()
  77.     turtle.turnRight()
  78.     turtle.turnRight()
  79. end
  80. --Turn right and do (almost) the same thing
  81. turtle.turnRight()
  82.  
  83. local eventData=getData()
  84. table.insert(distanceT,eventData[6])
  85. turtle.forward()
  86. local nData=getData()
  87. table.insert(distanceT,nData[6])
  88. if distanceT[#distanceT-1]>distanceT[#distanceT] then
  89.     --Keep going forward
  90.     getCloser(turtle.forward)
  91. else
  92.     --Moonwalk
  93.     turtle.turnRight()
  94.     turtle.turnRight()
  95.     getCloser(turtle.forward)
  96. end
  97.  
  98. --We should be right in front of the host.
  99. peripheral.call("front","shutdown")
  100. if brk then turtle.dig() end
  101.  
  102. print("Killed a GPS host!")
  103. print("Coords: ",coords)
  104. print("Tries: ",#distanceT)
  105. print("Original Distance: ",distanceT[1])
  106. end
Advertisement
Add Comment
Please, Sign In to add comment