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

Would love someone to write me a script

Started by Deanius, 04 August 2012 - 02:06 AM
Deanius #1
Posted 04 August 2012 - 04:06 AM
i was wondering if it was possible for a code which will enable a turtle to build a 'wall' of designated height and length which works in MULTIPLAYER.
thanks a lot
(p.s. if this is the wrong section i apologise)
BigSHinyToys #2
Posted 04 August 2012 - 06:33 AM
This should make walls for you.
notes after refueling remove excess coal
http://pastebin.com/aWG0juc9
DONT use PASTBIN.GET something is wrong with it and it makes it fail COPY it in
Spoiler

local tArgs = {...}
local iSlot = 1
local bDebug = false
local function printUsage()
    print("Wall <Distance> <hight>")
end
local function refuel()
    local slotSelX,slotSelY = 1,1
    print("use [Up Dwon Left Right] keys to seleft fuel slot")
    print([[Press "r" refuel or "c" to continue]])
    while true do
	    local e,e1,e2,e3 = os.pullEvent()
	    if e == "key" then
		    if e1 == 200 then -- up turtle.select(e1-1)	 local slotSelX = 1  local slotSelY = 1
			    slotSelY = slotSelY -1
			    if slotSelY < 1 then
				    slotSelY = 4
			    end
		    elseif e1 == 208 then -- down
			    slotSelY = slotSelY +1
			    if slotSelY > 4 then
				    slotSelY = 1
			    end
		    elseif e1 == 203 then -- left
			    slotSelX = slotSelX -1
			    if slotSelX < 1 then
				    slotSelX = 4
			    end
		    elseif e1 == 205 then -- right
			    slotSelX = slotSelX +1
			    if slotSelX > 4 then
				    slotSelX = 1
			    end
		    elseif e1 == 19 then -- r
			    turtle.refuel(1)
		    elseif e1 == 46 then -- c
			    break
		    end
	    end
	    turtle.select(slotSelX+(slotSelY*4)-4)
    end
    return
end
local function funtUP()
    while not turtle.up() do
	    if turtle.getFuelLevel() > 1 then
	    sleep(1)
	    else
		    print("Turtle fuel Levle : "..turtle.getFuelLevel())
		    refuel()
	    end
    end
end
local function funtForward()
    while not turtle.forward() do
	    if turtle.getFuelLevel() > 1 then
	    sleep(1)
	    else
		    print("Turtle fuel Levle : "..turtle.getFuelLevel())
		    refuel()
	    end
    end
end
local function checkFor()
    for i = 16,1,-1 do
	    local iTotal = turtle.getItemCount(i)
	    if bDebug then
		    write(tostring(iTotal).." ")
	    end
	    if iTotal > 0 then
		    iSlot = i
		    turtle.select(iSlot)
		    turtle.placeDown()
		    return true
	    end
    end
    return false
end
local function fplace()
    local found = false
    turtle.select(iSlot)
    if turtle.getItemCount(iSlot) > 0 then
	    turtle.placeDown()
	    return true
    else
	    if not checkFor() then
	    print([[No Items in turtle fill turtle and press "c" to continue]])
	    while true do
		    local e,e1 = os.pullEvent("char")
		    if e == "char" and e1 == "c" then
			    if checkFor() then
				    return
			    else
				    print("nNo blocks added")
			    end
		    end
	    end
	    else
		    return
	    end
    end
end
local function buildWall(inputlength,inputhight)
	    funtUP()
	    fplace()
    for p = 1,inputhight do
	    for x = 1,inputlength-1 do
		    funtForward()
		    fplace()
	    end
	    if p ~= inputhight then
	    funtUP()
	    fplace()
	    turtle.turnLeft()
	    turtle.turnLeft()
	    end
    end
end
if #tArgs == 3 then
    if tArgs[3] == "test" then
	    bDebug = true
    end
    table.remove(tArgs,3)
end
if #tArgs ~= 2 then
    printUsage()
else
    local iDistance,iHight = tonumber(tArgs[1]),tonumber(tArgs[2])
    if iDistance == nil or iHight == nil then
	    printUsage()
    else
    print("Turtle fuel Levle : "..turtle.getFuelLevel())
    buildWall(iDistance,iHight)
    print("nFinished wall")
    end
end
zdb #3
Posted 04 August 2012 - 06:39 AM
I'm no expert,
but I've not seen a turtle program work in single player and not SMP. Provided the failure isn't due to misconfigured mods.
Code either works in the Lua interpreter or it doesn't.

Are you asking INALLCAPS because of an isolated problem in SMP?
Or just asking for free code to the widest audience?
BigSHinyToys #4
Posted 04 August 2012 - 06:48 AM
I'm no expert,
but I've not seen a turtle program work in single player and not SMP. Provided the failure isn't due to misconfigured mods.
Code either works in the Lua interpreter or it doesn't.

Are you asking INALLCAPS because of an isolated problem in SMP?
Or just asking for free code to the widest audience?
false conclusion : I am pointing out that trying to auto download in ether SSP or SMP from pastbin will fail due to Pastebin error ("code duplication") This code will work on all CC systems SMP and SSP that have standard BIOS and API's installed.
Pharap #5
Posted 04 August 2012 - 01:16 PM
Here's the basic structure

params = {…}
width = tonumber(params[1]) – width of wall
height = tonumber(params[2]) – height of wall
direction = params[3] –direction is relevant to the way the turtle's facing
if direction == "left" then
turtle.turnLeft()
elseif direction == "right" then
turtle.turnRight()
elseif direction == "back" then
turtle.turnRight()
turtle.turnRight()
end
turtle.
for y = height do
for x = 1, width do
if turtle.detectDown() then
turtle.dig()
end
turtle.placeDown()
turtle.forward()
end
if turtle.detectUp() then
turtle.digUp()
end
turtle.up()
turtle.turnRight()
turtle.turnRight()
end
while not turtle.detectDown() do
turtle.down()
end

That's the basic function, if you want anything more fancy, message me and I'll write an optimised version