Posted 31 May 2014 - 07:45 PM
Do you need a turtle that can build platforms? Great!
How about one that can place torches or glowstone? Excellent!
What about one that doesn't get stuck when mobs try to pin it down? No problem!
Want it to stop and request more torches or inventory when it's out? Got it covered!
Also want it to stick to the build parameters and not wander about aimlessly? We got that too!
Need it to handle falling blocks like sand and gravel? Already got your back!
You heard right! I have created for your turtle pleasure the program 'Platform II' which based off of Zach Dyers 'Easy Platform Builder'. I greatly enhanced his version with all of the above features.
Instructions:
Place turtle in lower left of area to be built. The turtle will advance and begin building after you've supplied it with materials and issued the command: platform <length> <width> [torch_interval].
Note: make sure you have fueled the turtle first.
'platform' with no arguments will give you the program help. The torch_interval argument is not required, but if it is present any item in slot 16 will be treated like a torch and placed down when the interval is met.
Fuel is not required but if the turtle runs out it will look in slot 15 for fuel.
Pastebin: M0i8fDU5 -LINK-
TurlteScripts.com: market get gjdi4a platform y -INFO LINK-
Demonstration Video:
[media]http://youtu.be/9tnlm330QwI[/media]
If you can think of way to optimize my code to make it better while keeping it newbie friendly let me know. I'm open to suggestions and feature requests. Feel free to give credit where credit is due when basing your code off of my code.
Thanks and Happy Turtling!
How about one that can place torches or glowstone? Excellent!
What about one that doesn't get stuck when mobs try to pin it down? No problem!
Want it to stop and request more torches or inventory when it's out? Got it covered!
Also want it to stick to the build parameters and not wander about aimlessly? We got that too!
Need it to handle falling blocks like sand and gravel? Already got your back!
You heard right! I have created for your turtle pleasure the program 'Platform II' which based off of Zach Dyers 'Easy Platform Builder'. I greatly enhanced his version with all of the above features.
Instructions:
Place turtle in lower left of area to be built. The turtle will advance and begin building after you've supplied it with materials and issued the command: platform <length> <width> [torch_interval].
Note: make sure you have fueled the turtle first.
'platform' with no arguments will give you the program help. The torch_interval argument is not required, but if it is present any item in slot 16 will be treated like a torch and placed down when the interval is met.
Fuel is not required but if the turtle runs out it will look in slot 15 for fuel.
Pastebin: M0i8fDU5 -LINK-
TurlteScripts.com: market get gjdi4a platform y -INFO LINK-
Demonstration Video:
[media]http://youtu.be/9tnlm330QwI[/media]
Spoiler
--[[
Credit to Zach Dyer for the original program that I based this on
'Easy Platform Builder'.
Current version: 2.0
Pastebin: M0i8fDU5
Changelog:
5/20/2014 - added torch placing, block detection
5/31/2014 - added mob attacking, better block detection,
inventory requests when empty, resume on keypress.
--]]
local tArgs = {...}
local length = tonumber(tArgs[1])
local width = tonumber(tArgs[2])
local torch_interval = tonumber(tArgs[3])
if torch_interval == nil then
torch_interval = 0
end
local turnRight = true
local slot = 1
local interval = 0
function pauseAnyKey()
-- if event == "key" and p1 == keys.q then
while true do
local event, p1,p2,p3 = os.pullEvent()
if event == "key" then
return p1
end
sleep(0.5)
end
end
-- Kudos to BlockSmith on ComputerCraft.info forums for the suggestion!
function refuel(dim1,dim2)
dim1 = dim1 or 1
dim2 = dim2 or 1
fuelReq = dim1 * dim2
turtle.select(15)
while (turtle.getFuelLevel() < fuelReq) do
--inform the user that the turtle is out of fuel
print("Waiting for fuel in slot 15...")
print("Press any key to continue.")
pauseAnyKey()
-- use all of the fuel in slot 15
turtle.refuel()
-- then go back and check the level again
end
-- select the active slot
turtle.select(slot)
end
function flip()
turtle.turnRight()
turtle.turnRight()
end
function digDetect()
while turtle.detect() do
turtle.dig()
end
end
function psycho()
turtle.attack()
turtle.attackUp()
turtle.attackDown()
turtle.turnLeft()
turtle.attack()
turtle.turnRight()
turtle.turnRight()
turtle.attack()
turtle.turnLeft()
end
function digDetectUp()
while turtle.detectUp() do
turtle.digUp()
end
end
function tryForward()
while not turtle.forward() do
psycho() --turtle.attack()
turtle.dig()
end
end
function tryPlaceDown(mode)
mode = mode or "ignore me"
while not turtle.placeDown() do
if mode == "dig" then
turtle.digDown()
end
--turtle.attackDown()
psycho()
turtle.attack()
end
end
function findInventory()
for i=slot,14 do
if turtle.getItemCount(i) > 0 then
return i
end
end
for i=1,slot-1 do
if turtle.getItemCount(i) > 0 then
return i
end
end
return -1
end
function torchPlacer()
turtle.select(16)
if turtle.getItemCount(16) == 0 then
print("I need more torches!")
print("Put more torches in slot 16 and press any key to make me resume!")
pauseAnyKey()
end
digDetectUp()
turtle.up()
flip()
digDetect()
flip()
turtle.back()
tryPlaceDown()
--turtle.placeDown()
tryForward()
turtle.down()
end
if width == nil then
print("1. Place turtle facing direction of said platform on left side.")
print("2. Load turtle with materials for the platform. If placing torches, add light source blocks to slot 16.")
print("3. Type 'platform <length> <width> [torch_interval]'")
return
end
turtle.select(slot)
-- set the initial fuel load
refuel(length,width)
tryForward()
for j = 1, width, 1 do
for i = 1, length, 1 do
if turtle.getItemCount(slot) == 0 then
x = findInventory()
while x == -1 do
if x == -1 then
print("I ran out of materials!")
print("Put mats in slots 1 to 14 then")
print("press any key to continue.")
pauseAnyKey()
x = findInventory()
end
end
slot = x
end
turtle.select(slot)
tryPlaceDown("dig")
if i < length then
digDetect()
tryForward()
end
if torch_interval > 0 then
interval = interval + 1
if interval == torch_interval then
interval = 0
torchPlacer()
end
end
end
if j < width then
if turnRight == true then
turtle.turnRight()
digDetect()
tryForward()
turtle.turnRight()
turnRight = false
else
turtle.turnLeft()
digDetect()
tryForward()
turtle.turnLeft()
turnRight = true
end
end
refuel(5) -- cursory check for fuel
end
If you can think of way to optimize my code to make it better while keeping it newbie friendly let me know. I'm open to suggestions and feature requests. Feel free to give credit where credit is due when basing your code off of my code.
Thanks and Happy Turtling!
Edited on 31 May 2014 - 07:38 PM