Posted 28 November 2012 - 09:44 PM
Turtle Lamp Maker
version 1.1
This program makes lamps for you!
Why would you need that?
So you won't need to keep repeating the same style of lamp over and over again. :D/>
What's new in version 1.1:
- New style of lamp: redstone lamp
Features so far:
TwoThree styles of lamp to choose from!- A GUI to select style of lamps
Some screenshots:
Opening GUI:
Glowstone lamp stuff:
Village-style lamp stuff:
Code :
Spoiler
– Lights Script by milkywave1 –
–rednet.open("right")
–Functions
local sIndex = 1
local side = 1
– This function is by Wraithbone –
function vertMenu()
local tableofItems = {"Make village-style lamps", "Make glowstone lamps", "Make redstone lamps"}
local selection = "";
while (selection == "") do
term.clear();
local xMax, yMax = term.getSize();
local y = math.floor(yMax/2) + math.floor(#tableofItems/2);
y = y - #tableofItems;
if y<1 then y = 1 end;
if #tableofItems > yMax then
print "ERROR: List does not fit on screen, reduce number of items in table";
return "";
end
for i = 1, #tableofItems do
if string.len(tableofItems) >= xMax then
term.clear();
term.setCursorPos(1,1);
print (("ERROR: List item # "..i).." is too long please reduce");
return "";
end
local x = math.floor(xMax/2) - math.floor(string.len(tableofItems)/2);
if i == sIndex then x = x-1 end;
term.setCursorPos(x,y);
if i == sIndex then term.write("[") end;
term.write(tableofItems);
if i == sIndex then term.write("]") end;
y = y+1;
end
local r,s = os.pullEvent("key");
if s == 208 then sIndex = sIndex +1 end;
if s == 200 then sIndex = sIndex -1 end;
if sIndex > #tableofItems then sIndex = 1 end;
if sIndex < 1 then sIndex = #tableofItems end;
if s == 28 then
term.clear();
term.setCursorPos(1,1);
return tableofItems[sIndex]
end
end
end
function vertMenu2()
print("Select direction in which the lamp will bend to :")
local tableofItems = {"Left", "Right", "Forward", "Back"}
local selection = "";
while (selection == "") do
term.clear();
local xMax, yMax = term.getSize();
local y = math.floor(yMax/2) + math.floor(#tableofItems/2);
y = y - #tableofItems;
if y<1 then y = 1 end;
if #tableofItems > yMax then
print "ERROR: List does not fit on screen, reduce number of items in table";
return "";
end
for i = 1, #tableofItems do
if string.len(tableofItems) >= xMax then
term.clear();
term.setCursorPos(1,1);
print (("ERROR: List item # "..i).." is too long please reduce");
return "";
end
local x = math.floor(xMax/2) - math.floor(string.len(tableofItems)/2);
if i == side then x = x-1 end;
term.setCursorPos(x,y);
if i == side then term.write("[") end;
term.write(tableofItems);
if i == side then term.write("]") end;
y = y+1;
end
local r,s = os.pullEvent("key");
if s == 208 then side = side +1 end;
if s == 200 then side = side -1 end;
if side > #tableofItems then side = 1 end;
if side < 1 then side = #tableofItems end;
if s == 28 then
term.clear();
term.setCursorPos(1,1);
return tableofItems[side]
end
end
end
function shiftLeft()
turtle.turnLeft()
turtle.forward()
turtle.turnRight()
end
function fuel()
turtle.select(4)
turtle.refuel()
end
function checkFuel()
fl = turtle.getFuelLevel()
fuel()
if fl < 1 then
print("Need fuel! Put coal in slot 4!")
end
end
function forward(num)
for i = 1,num do
turtle.forward()
end
end
function shiftRight()
turtle.turnRight()
turtle.forward()
turtle.turnLeft()
end
function makeLamp()
if sIndex == 1 then – Village-style lamp
turtle.select(1)
turtle.place()
turtle.up()
turtle.place()
turtle.up()
turtle.place()
turtle.up()
turtle.select(2)
turtle.place()
turtle.back()
turtle.select(3)
turtle.place()
shiftLeft()
turtle.forward()
turtle.place()
turtle.up()
turtle.forward()
turtle.forward()
turtle.down()
turtle.turnRight()
turtle.place()
turtle.up()
turtle.forward()
turtle.forward()
turtle.down()
turtle.turnRight()
turtle.place()
turtle.down()
turtle.down()
turtle.down()
turtle.turnRight()
turtle.forward()
turtle.turnRight()
elseif sIndex == 2 then – Glowstone Lamp
turtle.select(1)
turtle.place()
turtle.up()
turtle.place()
turtle.up()
turtle.place()
turtle.up()
turtle.place()
turtle.up()
turtle.place()
if side == 2 then –Right
shiftRight()
turtle.place()
turtle.down()
turtle.select(2)
turtle.place()
turtle.down()
turtle.down()
turtle.down()
forward(2)
shiftLeft()
elseif side == 1 then –Left
shiftLeft()
turtle.place()
turtle.down()
turtle.select(2)
turtle.place()
turtle.down()
turtle.down()
turtle.down()
forward(2)
shiftRight()
elseif side == 3 then –Forward
turtle.up()
forward(2)
turtle.down()
turtle.turnRight()
turtle.turnRight()
turtle.back()
turtle.place()
turtle.down()
turtle.select(2)
turtle.place()
turtle.down()
turtle.down()
turtle.down()
turtle.forward()
turtle.turnRight()
turtle.turnRight()
elseif side == 4 then – back
turtle.down()
turtle.placeUp()
turtle.down()
turtle.select(2)
turtle.placeUp()
turtle.down()
turtle.down()
shiftLeft()
forward(2)
shiftRight()
end
elseif sIndex == 3 then – Redstone lamp
turtle.select(1)
turtle.place()
turtle.up()
turtle.place()
turtle.up()
turtle.place()
turtle.up()
turtle.select(2)
turtle.place()
turtle.up()
turtle.select(3)
turtle.place()
turtle.down()
turtle.down()
turtle.down()
turtle.down()
shiftRight()
forward(2)
shiftLeft()
end
end
function makeLamp2()
print("Making "..input.. " lamps")
madeLamps = 0
for a = 1,input do
makeLamp()
madeLamps = madeLamps + 1
print("Made "..madeLamps.. " lamps")
–rednet.send(6, madeLamps.." lamps")
for b = 1,input2 do
turtle.forward()
end
end
end
function prompt()
print("Current fuel level: "..fl)
if sIndex == 1 then
print("Place fences in slot 1, black wool in slot 2, torches in slot 3")
elseif sIndex == 2 then
vertMenu2()
print("Place fences in slot 1, glowstone in slot 2")
elseif sIndex == 3 then
print("Place fences in slot 1, redstone lamps in slot 2 , levers in slot 3")
end
write("Number of Lamps:")
input = read()
write("Distance between each lamp:")
input2 = read()
input2 = input2 - 1
end
function reset()
print("Returning…")
turtle.turnLeft()
turtle.forward()
turtle.turnLeft()
input2 = input2 + 1
for z = 1,madeLamps do
forward(input2 + 1)
end
turtle.turnLeft()
turtle.forward()
turtle.turnLeft()
end
function main()
vertMenu()
checkFuel()
prompt()
makeLamp2()
reset()
end
main()
turtle.select(1)
TODO List:
- Code my own GUI :P/>
- More lamp styles
- Rednet support