View difference between Paste ID: P2WK5w2E and YmmnaqXP
SHOW: | | - or go back to the newest paste.
1-
-- This is eniallator's Control program's plugin template.
1+
local version = "3.0"
2-
-- Link to Control program: http://pastebin.com/ss0BX2mM
2+
3-
-- This file goes into the folder that you have specified in the pluginFolder variable in the Control program.
3+
function move(direction)
4-
--
4+
  if direction == "up" then
5-
-- ================================================================================
5+
6-
--
6+
    while turtle.up() == false do
7-
-- The key you have given your function that you have given in the function table is how you are going to call your function in the remote computer's command line. For example inputting "testFunc arg1 arg2" would call the function testfunc from the functionTable and in the function argument it would then pass the following arguments: ({"arg1","arg2"},*ID of remote computer thats connected*,*protocol thats being used*).
7+
      turtle.digUp()
8-
--
8+
      turtle.attackUp()
9-
-- DISCLAIMER: this acts as the same as the way you would create your function in the control program before, just the status, helpTable and functionTable tables can be accessed from here. I have also made it so that plugin's functions have priority over the control program's functions e.g you can rewrite the default functions from a plugin.
9+
    end
10
11-
status = {*insert your function name here* = 1}
11+
  elseif direction == "forward" then
12-
-- Just add more keys/values the same way as the first one is laid out
12+
13
    while turtle.forward() == false do
14-
helpTable = {*insert your function name here* = "*insert your function's help here*"}
14+
      turtle.dig()
15-
-- Just add more keys/values the same way as the first one is laid out
15+
      turtle.attack()
16
    end
17-
functionTable = {*insert your function name here* = function(userInput, connectedComputerID, protocol) *insert what your function does here* end}
17+
18-
-- Just add more keys/values the same way as the first one is laid out
18+
  elseif direction == "down" then
19
20
    while turtle.down() == false do
21
      turtle.digDown()
22
      turtle.attackDown()
23
    end
24
  end
25
end
26
-- Force move up/forward/down with this function
27
28
status = {move = 1,cube = 1}
29
30
helpTable = {move = "move in any direction", cube = "mine out a cuboid in dimension arguments"}
31
32
functionTable = {
33
34
	move = function(item,connectID,mProt)
35
36
    moveBlocks = tonumber(item[2])
37
38
    if moveBlocks == nil then
39
      moveBlocks = 0
40
    end
41
42
    if not tonumber(moveBlocks) then
43
      rednet.send(connectID, "Expected number as 3rd argument. Instead Received: " .. item[2], mProt)
44
    else
45
46
      function mover(direction)
47
        while moveBlocks > 0 do
48
          move(direction)
49
          moveBlocks = moveBlocks - 1
50
        end
51
      end
52
53
      if item[1] == "up" or item[1] == "down" or item[1] == "forward" or item[1] == "right" or item[1] == "left" or item[1] == "back" then
54
        if moveBlocks > 1 then
55
          rednet.send(connectID, "Moving " .. item[1] .. " " .. item[2] .. " blocks!", mProt)
56
        elseif moveBlocks == 1 then
57
          rednet.send(connectID, "Moving " .. item[1] .. " 1 block", mProt)
58
        else
59
          rednet.send(connectID, "Moving " .. item[1], mProt)
60
        end
61
62
        if item[1] == "right" then
63
          turtle.turnRight()
64
          item[1] = "forward"
65
66
        elseif item[1] == "left" then
67
          turtle.turnLeft()
68
          item[1] = "forward"
69
70
        elseif item[1] == "back" then
71
          for i=1,2 do turtle.turnRight() end
72
          item[1] = "forward"
73
        end
74
75
        mover(item[1])
76
77
      else
78
        rednet.send(connectID, 'List of possible directions: "up", "down", "right", "left", "forward", "back" ', mProt)
79
80
      end
81
    end
82
  end,
83
84
  cube = function(item,connectID,mProt)
85
86
    if item[1] ~= nil and item[2] ~= nil and item[3] ~= nil and tonumber(item[1]) and tonumber(item[2]) and tonumber(item[3]) and tonumber(item[1]) > 0 and tonumber(item[2]) > 0 and tonumber(item[3]) > 0 then
87
88
      for i=1,3 do
89
        item[i] = tonumber(item[i])
90
      end
91
92
      rednet.send(connectID, "Mining out a " .. item[1] .. " x " .. item[2] .. " x " .. item[3] .. " cuboid", mProt)
93
      local xDist = item[1]
94
      local yDist = item[2]
95
      local zDist = item[3]
96
      local i = 0
97
      local levelsMined = 0
98
99
      function checkBreak()
100
        if yDist - levelsMined > 1 then
101
102
          turtle.digUp()
103
        end
104
105
        if yDist - levelsMined > 2 then
106
107
          turtle.digDown()
108
        end
109
      end
110
111
      function line()
112
        for k=1,xDist-1 do
113
114
          move("forward")
115
          checkBreak()
116
        end
117
      end
118
119
      function nextLine(direction)
120
        direction()
121
        move("forward")
122
        checkBreak()
123
        direction()
124
      end
125
126
      function layer(level)
127
128
        if yDist - levelsMined > 2 then
129
130
          move("up")
131
        end
132
133
        checkBreak()
134
        line()
135
136
        if zDist%2 == 1 then
137
138
          level = 0
139
        end
140
141
        for j=1,zDist-1 do
142
          if (level+j)%2 == 1 then
143
144
            nextLine(turtle.turnRight)
145
          else
146
147
            nextLine(turtle.turnLeft)
148
          end
149
150
          line()
151
        end
152
153
        if yDist - levelsMined > 2 then
154
155
          levelsMined = levelsMined + 3
156
157
        elseif yDist - levelsMined > 1 then
158
159
          levelsMined = levelsMined + 2
160
        else
161
162
          levelsMined = levelsMined + 1
163
        end
164
      end
165
166
      move("forward")
167
      layer(0)
168
      local level = 0
169
170
      while yDist - levelsMined > 0 do
171
172
        for l=1,2 do move("up") end
173
        for l=1,2 do turtle.turnRight() end
174
175
        level = level + 1
176
        layer(level)
177
      end
178
179
      local rightTurns = 2
180
181
      if level%2 == 0 then
182
        if zDist%2 == 1 then
183
184
          for i=1,2 do turtle.turnRight() end
185
          for i=1,xDist-1 do move("forward") end
186
        end
187
188
        turtle.turnRight()
189
        for i=1,zDist-1 do move("forward") end
190
        rightTurns = 1
191
      end
192
193
      local yOffset = 2
194
195
      if yDist % 3 == 1 then yOffset = 1 end
196
197
      for i=1,yDist-yOffset do move("down") end
198
      for i=1,rightTurns do turtle.turnRight() end
199
    else
200
201
      rednet.send(connectID, "Invalid dimensions, use 3 numbers bigger than 0", mProt)
202
    end
203
  end
204
}