Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Tank Builder
- -- Fenthis
- -- Slot 1 = Frame
- -- Slot 2 = Sides
- args = { ... }
- forward = tonumber(args[1])
- right = tonumber(args[2])
- up = tonumber(args[3])
- if not (forward and right and up) then
- print("Usage: maketank forward right up")
- print(" Slot 1: Base and Frame")
- print(" Slot 2: Sides and Top")
- print(" The space must be clear, plus, one extra level above the tank.")
- error("Invalid usage.")
- end
- if not (forward > 2 and right > 2 and up > 2) then
- error("Minimum dimensions are 3x3x3.")
- end
- if (forward > 12 and right > 12 and up > 12) then
- error("Maximum dimensions are 12x12x12.")
- end
- glass = ((right-2)*(up-2)*2) + ((forward-2)*(up-2)*2) + ((forward-2) * (right-2))
- frame = (up * 4) + ((forward-2) * 4) + ((right-2) * 4) + ((forward-2) * (right-2))
- print("Required blocks:")
- print("Base + Frame (slot 1): " .. frame)
- print("Sides + Top (slot 2): " .. glass)
- print("Estimated fuel use: " .. glass + frame + right + 2)
- print("")
- print("Press Q to quit, or any other key to start.")
- e, c = os.pullEvent("char")
- if c == "Q" or c == "q" then
- return
- end
- if not act then
- os.loadAPI("act")
- if not act then
- print("act api required.")
- exit()
- end
- end
- function do_left_or_right(dir)
- if dir then
- turtle.turnLeft()
- else
- turtle.turnRight()
- end
- end
- function is_odd(n)
- return ((n % 2) == 1)
- end
- function try_n(times)
- for i = 1, times do
- act.try()
- end
- end
- function do_to_or_botton(top)
- turtle.up()
- for r = 1,right do
- for x = 1,forward do
- -- Frame or side
- if (not top) or r == 1 or r == right or
- x == 1 or x == forward then
- act.select(1)
- else
- act.select(2)
- end
- act.placeDown()
- if x ~= forward then
- act.try()
- end
- end
- if r ~= right then
- do_left_or_right(not is_odd(r))
- act.try()
- do_left_or_right(not is_odd(r))
- end
- end
- -- Movve to opisit of starting corner
- if not is_odd(right) then
- turtle.turnLeft()
- turtle.turnLeft()
- try_n(forward - 1)
- end
- -- Turn around
- turtle.turnLeft()
- turtle.turnLeft()
- end
- function do_wall(length)
- for i = 1, length do
- if i == 1 or i == length then
- act.select(1)
- else
- act.select(2)
- end
- act.placeDown()
- if i ~= length then
- act.try()
- end
- end
- turtle.turnRight()
- end
- function do_walls()
- for level = 1, (up - 2) do
- turtle.up()
- do_wall(forward)
- do_wall(right)
- do_wall(forward)
- do_wall(right)
- end
- end
- do_to_or_botton(false)
- do_walls()
- do_to_or_botton(true)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement