Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Command usage can be shown by simply executing the script without parameters.
- Copyright by Stephan Henrichs, 2012
- Licensed under CC BY-NC-SA 3.0
- More Information: http://creativecommons.org/licenses/by-nc-sa/3.0/
- I'd appreciate to credit me btw :P
- ]]--
- tArgs = {}
- tmpArgs = {...}
- function printUsage()
- print("Usage: platform <length> <width> <height> [<ofset_length> <offset_width> <offset_heigh>]")
- end
- -- Testing args
- function parseArgs()
- local tmp = tmpArgs
- if tmp[1] == nil or tmp[2] == nil or tmp[3] == nil then
- return false
- else
- tArgs['x'] = tonumber(tmp[1])
- tArgs['z'] = tonumber(tmp[2])
- tArgs['y'] = tonumber(tmp[3])
- if tmp[4] ~= nil and (tmp[5] == nil or tmp[6] == nil) then
- return false
- elseif tmp[4] == nil then
- tArgs['ox'] = 0
- tArgs['oz'] = 0
- tArgs['oy'] = 0
- return true
- else
- tArgs['ox'] = tonumber(tmp[4])
- tArgs['oz'] = tonumber(tmp[5])
- tArgs['oy'] = tonumber(tmp[6])
- return true
- end
- end
- end
- function selectFirstUsableSlot()
- for i1 = 1,16 do
- if turtle.getItemCount(i1) > 0 then
- turtle.select(i1)
- return true
- end
- end
- return false
- end
- function go(len)
- for i5=1, len do
- turtle.forward()
- end
- end
- function buildBlock()
- if selectFirstUsableSlot() then
- turtle.placeDown()
- else
- print("Out of Recources")
- --os.exit()
- end
- end
- function buildRow(last)
- for i2 = 1, tArgs['x'] do
- buildBlock()
- if (i2 == tArgs['x']) then else
- turtle.forward()
- end
- end
- end
- local dir = 0
- function turn()
- if dir == 1 then
- turtle.turnLeft()
- turtle.forward()
- turtle.turnLeft()
- dir = 0
- else
- turtle.turnRight()
- turtle.forward()
- turtle.turnRight()
- dir = 1
- end
- end
- function buildLayer()
- for i3 = 1, tArgs['z'] do
- buildRow(i3==tArgs['z'])
- if i3 ~= tArgs['z'] then
- turn()
- end
- end
- dir = 0
- end
- function buildPlat()
- for i4 = 1, tArgs['y'] do
- buildLayer()
- if i4 ~= tArgs['y'] then
- turtle.up()
- end
- if tArgs['z'] % 2 == 1 then
- turtle.turnRight()
- turtle.turnRight()
- go(tArgs['x']-1)
- end
- turtle.turnRight()
- go(tArgs['z']-1)
- turtle.turnRight()
- end
- end
- function goToStart()
- local x = tArgs['ox']
- local y = tArgs['oy']
- local z = tArgs['oz']
- if x < 0 then
- x = x * -1
- turtle.turnLeft()
- turtle.turnLeft()
- go(x)
- turtle.turnLeft()
- turtle.turnLeft()
- else
- go(x)
- end
- if z < 0 then
- z = z * -1
- turtle.turnLeft()
- go(z)
- turtle.turnRight()
- else
- turtle.turnRight()
- go(z)
- turtle.turnLeft()
- end
- if y < 0 then
- for i6 = 1, y * -1 do
- turtle.down()
- end
- else
- for i6 = 1, y do
- turtle.up()
- end
- end
- end
- if parseArgs() then
- goToStart()
- buildPlat()
- else
- printUsage()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement