This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Vilsol's profile picture

Vilsol's Programs! [HouseBuilder][FMS][DoubleQuarry]

Started by Vilsol, 12 May 2012 - 09:29 AM
Vilsol #1
Posted 12 May 2012 - 11:29 AM
Hello everyone!

On this topic you will see some ComputerCraft codes that i have made…

The HouseBuilder:
SpoilerScreenshots:
Spoiler


Code:
Spoiler
slot = 1

function f()
turtle.forward()
end

function cl()
shell.run("clear")
end

function b()
turtle.place()
end

function bd()
turtle.placeDown()
end

function bu()
turtle.placeUp()
end

function s(place)
turtle.select(place)
slot = slot+1
end

function u()
turtle.up()
end

function d()
turtle.down()
end

function r()
turtle.turnRight()
turtle.forward()
turtle.turnLeft()
end

function l()
turtle.turnLeft()
turtle.forward()
turtle.turnRight()
end

function c()
count = turtle.getItemCount(slot)
if count == 0 then
if slot < 9 then
newslot = slot+1
s(newslot)
end
end
end

function co()
return turtle.getItemCount()
end

function df()
turtle.dig()
end

function dd()
turtle.digDown()
end

cl()
print "House Builder - Made by Vilsol"
print ""
repeat
write "How wide do you want the house? (Max: 14): "
width = tonumber(read())
if width > 14 then
cl()
print "Too wide!"
print ""
end
until width < 15

cl()

repeat
write "How deep you want the house?	(Max: 14): "
deep = tonumber(read())
if deep > 14 then
cl()
print "Too deep!"
print ""
end
until deep < 15

cl()

repeat
write "How high you want the house?	(Max: 3): "
high = tonumber(read())
if high > 3 then
cl()
print "Too high!"
print ""
end
until high < 4

cl()

repeat
write "Do you want your house above	ground? (y/n): "
lev = read()
if lev == "y" then
lev = true
levt = true
elseif lev == "n" then
lev = false
levt = true
else
levt = false
cl()
print "Choose y OR n!"
print ""
end

until levt == true

total = ((width * deep * 2) + (((width-1) * 2 * high) + (deep-1) * 2 * high))

s(1)
s1 = turtle.getItemCount(1)
s2 = turtle.getItemCount(2)
s3 = turtle.getItemCount(3)
s4 = turtle.getItemCount(4)
s5 = turtle.getItemCount(5)
s6 = turtle.getItemCount(6)
s7 = turtle.getItemCount(7)
s8 = turtle.getItemCount(8)
s9 = turtle.getItemCount(9)

totalblocks = s1+s2+s3+s4+s5+s6+s7+s8+s9

print ("Theese settings will use " .. total .. " blocks!")
print ("You have provided " .. totalblocks .. " blocks!")
if totalblocks >= total then
print "That is enough!"
else

repeat
print "That is not enough!"
needed = total - totalblocks
print ("I need " .. needed .. " more blocks!")
print "Write anything to check!"
check = read()
if check then

s(1)
s1 = turtle.getItemCount(1)
s2 = turtle.getItemCount(2)
s3 = turtle.getItemCount(3)
s4 = turtle.getItemCount(4)
s5 = turtle.getItemCount(5)
s6 = turtle.getItemCount(6)
s7 = turtle.getItemCount(7)
s8 = turtle.getItemCount(8)
s9 = turtle.getItemCount(9)

totalblocks = s1+s2+s3+s4+s5+s6+s7+s8+s9

if totalblocks >= total then
print "That is enough!"
ok = true
end

end

until ok == true

end

print "Press any key to start building!"
os.pullEvent("key")

if lev == true then
turtle.turnRight()
u()
turn = "left"
for de = 1,deep do
c()
bd()

for wi = 2,width do
c()
f()
bd()
end

if turn == "left" then
turtle.turnLeft()
f()
turtle.turnLeft()
turn = "right"
else
turtle.turnRight()
f()
turtle.turnRight()
turn = "left"
end

end

else

turtle.turnRight()
turn = "left"
for de = 1,deep do
c()
dd()
bd()

for wi = 2,width do
c()
f()
dd()
bd()
end

if turn == "left" then
turtle.turnLeft()
f()
turtle.turnLeft()
turn = "right"
else
turtle.turnRight()
f()
turtle.turnRight()
turn = "left"
end

end

end

if turn == "left" then
turtle.turnRight()
turn = "right"
else
turtle.turnLeft()
turn = "left"
end

for upe = 1,high+1 do
u()
end

f()

if turn == "left" then
turtle.turnRight()
else
turtle.turnLeft()
end

for de = 1,deep do
c()
bd()

for wi = 2,width do
c()
f()
bd()
end

if turn == "left" then
turtle.turnLeft()
f()
turtle.turnLeft()
turn = "right"
else
turtle.turnRight()
f()
turtle.turnRight()
turn = "left"
end

end

if turn == "left" then
turtle.turnRight()
turn = "right"
else
turtle.turnLeft()
turn = "left"
end

d()

w = "down"

for ww = 1,width do

if w == "down" then
for wh = 1,high do
d()
b()
end
r()
w = "up"
else
for wh = 1,high do
b()
u()
end
r()
w = "down"
end

end

wall = "side"

for walls = 1,3 do

if wall == "side" then
size = deep
wall = "back"
else
size = width
wall = "side"
end

f()
f()
turtle.turnLeft()

for ww = 1,size-1 do

if w == "down" then
for wh = 1,high do
d()
b()
end
r()
w = "up"
else
for wh = 1,high do
b()
u()
end
r()
w = "down"
end

end

end

if math.fmod(width, 2) == 0 then
  even = true
else
  even = false
end

if even == true then
go = width/2
for fow = 1,go do
f()
end
turtle.turnLeft()
df()
u()
df()
r()
df()
d()
df()
else
go = math.ceil(width/2)
for fow = 1,go do
f()
end
turtle.turnLeft()
df()
u()
df()
end

d()
d()
turtle.turnRight()
f()
turtle.turnRight()

FMS (FileMaganementSystem)
SpoilerScreenshots:
Spoiler



Code:
SpoilerClient:
Spoiler
serverid = 25

shell.run("clear")
print "FMS - Made by Vilsol"
print "Download - 1"
print "Upload   - 2"
write "Choose command: "
type = tonumber(read())
if type == 1 then
x = "d"
rednet.send(serverid, x)
sleep(1)
write "Enter file name: "
file = io.read()
rednet.send(serverid, file)
id, text, dist = rednet.receive()
o = fs.open(file, "w")
o.write(text)
o.close()
print "File saved!"
sleep(2)
elseif type == 2 then
x = "g"
rednet.send(serverid, x)
sleep(1)
write "Enter file name: "
file = io.read()
rednet.send(serverid, file)
o = fs.open(file, "r")
f = o.readAll()
rednet.send(serverid, f)
o.close()
print "File sent!"
end

Server:
Spoilerstartup:
Spoiler
print "Waiting for command..."
id, type, dist = rednet.receive()
if type == "g" then
print "Receiving file!"
shell.run("g")
elseif type == "d" then
print "Sending file!"
shell.run("d")
end
d:
Spoiler
enderId, file, distance = rednet.receive()
sleep(1)
file = fs.open(file, "r")
text = file.readAll()
rednet.send(enderId, text)
file.close()
shell.run("startup")
g:
Spoiler
enderId, proname, distance = rednet.receive()
enderId, text, distance = rednet.receive()
file = fs.open(proname, "w")
file.write(text)
file.close()
log = fs.open("disk/log", "w")
log.writeLine(proname)
log.close()
print ("Saved " .. proname .. " from " .. enderId)
shell.run("startup")

The DoubleQuarry Digger
Spoilerpastebin get YLPAeL1g doublequarry

-- Made By Vilsol
-- DoubleQuarry Digger
-- Digs 2 blocks at a time
-- Digs double the depth amount

local args = { ... }

if not args[1] or not args[2] or not args[3] then
		print "Command:"
		print "doublequarry X Y Depth"
		error()
end

if not tonumber(args[1]) then
		print "X must be a number!"
else
		x = tonumber(args[1])
end
if not tonumber(args[2]) then
		print "Y must be a number!"
else
		y = tonumber(args[2])
end
if not tonumber(args[3]) then
		print "Depth must be a number!"
else
		d = tonumber(args[3])
end

if(turtle.getItemCount(13) == 0)then
		print "No EnderChest!"
		print "Put an EnderChest in the slot 13 and re-run the program!"
		error()
end

turn = "right"

totaldig = 0

function reFuel()
		fuel = turtle.getFuelLevel()
		if fuel < 100 then
				turtle.select(16)
				turtle.refuel()
				turtle.select(1)
		end
		fuel = turtle.getFuelLevel()
		if fuel < 100 then
				print "No Fuel!"
				print "Put Fuel in slot 16 and re-run the program!"
				error()
		end
end

function bringHome()
		turtle.digUp()
		turtle.select(13)
		if not turtle.placeUp() then
				for attacker = 1,50 do
						turtle.attackUp()
				end
		end
		for slots = 1, 12 do
				turtle.select(slots)
				turtle.dropUp()
		end
		turtle.select(13)
		turtle.digUp()
		turtle.select(1)
end

function checkSlot()
		fullness = turtle.getItemCount(12)
		if fullness > 0 then
				bringHome()
		end
end

function digQuarry()
		reFuel()
		bringHome()
		turtle.digDown()
		turtle.down()
		for depth = 1, d do
				checkSlot()
				for width = 1, y do
						checkSlot()
						for height = 2, x do
								checkSlot()
								if turtle.dig() then
										totaldig = totaldig+1
								end
								if turtle.digDown() then
										totaldig = totaldig+1
								end
								if not turtle.forward() then
										reFuel()
										if not turtle.forward() then
												bringHome()
												if not turtle.forward() then
														if not turtle.attack() then
																print "Error"
																error()
														end
														if not turtle.forward() then
																for times = 1,50 do
																		turtle.attack()
																end
																if not turtle.forward() then
																		print "Error"
																		error()
																end
														end
												end
										end
								end
						end
						if width < y then
								if turn == "left" then
										turn = "right"
										turtle.turnLeft()
										if turtle.dig() then
												totaldig = totaldig+1
										end
										if turtle.digDown() then
												totaldig = totaldig+1
										end
										if not turtle.forward() then
												reFuel()
												if not turtle.forward() then
														bringHome()
														if not turtle.forward() then
																if not turtle.attack() then
																		print "Error"
																		error()
																end
																if not turtle.forward() then
																		for times = 1,50 do
																				turtle.attack()
																		end
																		if not turtle.forward() then
																				print "Error"
																				error()
																		end
																end
														end
												end
										end
										turtle.turnLeft()
								else
										turn = "left"
										turtle.turnRight()
										if turtle.dig() then
												totaldig = totaldig+1
										end
										if turtle.digDown() then
												totaldig = totaldig+1
										end
										if not turtle.forward() then
												reFuel()
												if not turtle.forward() then
														bringHome()
														if not turtle.forward() then
																if not turtle.attack() then
																		print "Error"
																		error()
																end
																if not turtle.forward() then
																		for times = 1,50 do
																				turtle.attack()
																		end
																		if not turtle.forward() then
																				print "Error"
																				error()
																		end
																end
														end
												end
										end
										turtle.turnRight()
								end
						end
				end
				if depth < d then
						if turtle.digDown() then
								totaldig = totaldig+1
						end
						if not turtle.down() then
								reFuel()
								if not turtle.down() then
										bringHome()
										if not turtle.down() then
												if not turtle.attack() then
														print "Error"
														error()
												end
												if not turtle.down() then
														for times = 1,50 do
																turtle.attack()
														end
														if not turtle.down() then
																print "Error"
																error()
														end
												end
										end
								end
						end
						if turtle.digDown() then
								totaldig = totaldig+1
						end
						if not turtle.down() then
								reFuel()
								if not turtle.down() then
										bringHome()
										if not turtle.down() then
												if not turtle.attack() then
														print "Error"
														error()
												end
												if not turtle.down() then
														for times = 1,50 do
																turtle.attack()
														end
														if not turtle.down() then
																print "Error"
																error()
														end
												end
										end
								end
						end
						turtle.turnLeft()
						turtle.turnLeft()
				else
						if turtle.digDown() then
								totaldig = totaldig+1
						end
						for goup = 1, d*2 do
								turtle.up()
						end
						bringHome()
				end
		end
end

digQuarry()
Teraminer #2
Posted 12 May 2012 - 12:29 PM
very good job!
Vilsol #3
Posted 12 May 2012 - 02:26 PM
FMS Added!
Vilsol #4
Posted 14 May 2012 - 03:01 PM
I will accept any requests for programs, so ask if you need any custom program!
weaponologist #5
Posted 10 June 2012 - 01:02 AM
is there a way to copy and past this to my console or do i have to type it out by hand?
craton #6
Posted 14 June 2012 - 06:47 PM
you can access the computers on your world through the saves file in appdata .minecraft
D3matt #7
Posted 14 June 2012 - 09:49 PM
is there a way to copy and past this to my console or do i have to type it out by hand?
Pastebin.
Vilsol #8
Posted 19 January 2013 - 03:57 PM
Added DoubleQuarry Code
Started working on a touchscreen menu system.