View difference between Paste ID: KPFSAkjB and CpmzLYpM
SHOW: | | - or go back to the newest paste.
1
    rednet.open("right")
2
    local func
3
    local params
4
    local funcTable
5
    local tArgs = {...}
6
     
7
    function cleanup()
8
       for i = 1,12 do
9
          turtle.select(i)
10
          turtle.dropDown()
11
       end
12
    end
13
     
14
    function place()
15
       turtle.select(16)
16
       turtle.place()
17
       turtle.down()
18
       turtle.select(15)
19
       turtle.place()
20
       turtle.select(14)
21
       turtle.placeDown()
22
    end
23
	
24
    function placePower()
25
       turtle.select(1)
26
       turtle.place()
27
       turtle.down()
28
       turtle.select(2)
29
       turtle.place()
30
       turtle.attack()
31
    end
32
	
33
    function removePower()
34
       turtle.select(2)
35
       turtle.dig()
36
       turtle.up()
37
       turtle.select(1)
38
       turtle.dig()
39
       turtle.forward()
40
    end
41
     
42
    function remove()
43
       turtle.select(14)
44
       turtle.digDown()
45
       turtle.select(15)
46
       turtle.dig()
47
       turtle.up()
48
       turtle.select(16)
49
       turtle.dig()
50
    end
51
     
52
    function fuel()
53
       turtle.select(13)
54
       turtle.placeUp()
55
       turtle.select(1)
56
       turtle.suckUp()
57
       turtle.dropUp(turtle.getItemCount(1) - 4)
58
       turtle.refuel()
59
       turtle.select(13)
60
       turtle.digUp()
61-
    function fuelBoss(powerStation)
61+
62
     
63
    function fuelBoss(powerStations)
64
      local numTurtles = 0
65
      for x,y in pairs(powerStations) do
66-
      turtle.dropUp(doMath(powerStation))
66+
        if type(y) ~= "table" then
67
          numTurtles=numTurtles+1
68
        end
69
        if type(y) == "table" then
70-
      for x,y in pairs(powerStation) do
70+
71-
        if (type(y) ~= "table") and (y ~= nil) then
71+
            numTurtles=numTurtles+1
72
          end
73
        end
74
      end
75-
	else
75+
76
      turtle.placeUp()
77-
	    turtle.forward()
77+
78
      turtle.suckUp()
79-
            turtle.forward(z+1)
79+
      turtle.dropUp(turtle.getItemCount(1)-numTurtles*4)
80
      turtle.select(13)
81
      turtle.digUp()
82
      turtle.up()
83-
	    turtle.forward(z+1)
83+
84
      for x,y in pairs(powerStations) do
85-
	  end
85+
        if x==1 and y==1 then
86
	  turtle.turnRight()
87
	  turtle.drop(4)
88
	  turtle.turnLeft()
89
        else
90-
    function doMath(tbl)
90+
91-
      y = table.getn(tbl) + table.getn(tbl[2])
91+
            turtle.forward()
92-
      if tbl[2] ~= nil then
92+
93-
        y=y-1
93+
            goForward(z+1)
94
	    turtle.turnRight()
95-
      y=4*y
95+
96-
      return y
96+
97
	    goForward(z+1)
98
	    turtle.turnRight()
99
            turtle.back()
100
          end
101
        end
102
      end
103
      turtle.down()
104
    end
105-
    function checkStationFuel(id)
105+
106
    function goForward(x)
107-
        rednet.send("true", id)
107+
      for i = 1,x do
108-
      else
108+
        turtle.forward()
109-
        rednet.send("false", id)
109+
110
    end
111
	 
112
    function checkFuel()
113
       if turtle.getFuelLevel() < 600 then
114
          fuel()
115
       end
116
    end
117
	
118
    function checkStationFuel(fromID)
119-
    function cycle()
119+
120
        rednet.send(fromID, "true")
121-
       sleep(25)
121+
122
    end
123
124
    function eatFuel()
125
      turtle.select(3)
126
      turtle.refuel()
127
      turtle.select(1)
128
    end
129
	
130
    function cycle(time)
131
       place()
132
       if time ~= nil then
133
          time = tonumber(time)
134
          sleep(time)
135
       else
136
          sleep(25)
137
       end
138
       while turtle.getItemCount(1) > 0 do
139
          cleanup()
140
          sleep(2)
141
       end
142
       remove()
143
       checkFuel()
144
       turtle.forward()
145
    end
146-
       func = loadstring(msg)
146+
147-
       setfenv(func, getfenv())
147+
148-
       func(id)
148+
149
    end
150
     
151
    function chunkLoad()
152
       turtle.select(16)
153
       turtle.digUp()
154
       checkFuel()
155
       turtle.select(16)
156
       turtle.forward()
157
       turtle.placeUp()
158
    end
159
160
    function explode(div,str) -- credit: http://richard.warburton.it
161
      if (div=='') then return false end
162
      local pos,arr = 0,{}
163
      -- for each divider found
164
      for st,sp in function() return string.find(str,div,pos,true) end do
165
        table.insert(arr,string.sub(str,pos,st-1)) -- Attach chars left of current divider
166
        pos = sp + 1 -- Jump past current divider
167
      end
168
      table.insert(arr,string.sub(str,pos)) -- Attach chars right of last divider
169
      return arr
170
    end
171
     
172
    while true do
173
       local id,msg,dist = rednet.receive()
174
       local j,v = string.gsub(msg, "_", "_")
175
       if v == 1 then
176
          funcTable = explode("_", msg)
177
          func = loadstring(funcTable[1].."(...)")
178
          params = loadstring("return "..funcTable[2])()
179
          setfenv(func, getfenv())
180
          func(params)
181
       else
182
         func = loadstring(msg.."(...)")
183
         setfenv(func, getfenv())
184
         func(params)
185
       end
186
       rednet.send(id,"Done")
187
    end