Not a member of Pastebin yet?
                        Sign Up,
                        it unlocks many cool features!                    
                - if not turtle then
 - printError("This is a turtle program")
 - return
 - end
 - local w, h = term.getSize()
 - local junk = true
 - local junkside = "top"
 - local lootchest = "bottom"
 - if fs.exists( "melee_turtle" ) then
 - local file = fs.open( "melee_turtle", "r" )
 - local content = textutils.unserialize( file.readAll() )
 - file.close()
 - junk = content.junk
 - junkside = content.junkside
 - lootchest = content.lootchest
 - end
 - local popupSides = function()
 - term.setCursorPos( w - 14, 1 )
 - term.write( "+" )
 - for i = 1, 6 do
 - term.setCursorPos( w - 14, i + 1 )
 - term.write( "|" )
 - end
 - term.setCursorPos( w - 14, 8 )
 - term.write( "+" .. string.rep( "-", 13 ) .. "+" )
 - for k, v in pairs( rs.getSides() ) do
 - term.setCursorPos( w - 13 , k + 1 )
 - term.write( "[" .. k .. "] = " .. v )
 - end
 - local event, char = nil
 - repeat
 - event, char = os.pullEvent("char")
 - until char:find("[1-6]")
 - term.setCursorPos( w - 14, 1 )
 - term.write( "-" )
 - for i = 1, 6 do
 - term.setCursorPos( w - 14, i + 1 )
 - term.write( string.rep( " ", 14 ) .. "|" )
 - end
 - term.setCursorPos( w - 14, 8 )
 - term.write( string.rep( " ", 14 ) .. "|" )
 - return char
 - end
 - local screenManagement = function()
 - while true do
 - term.setCursorPos( 1, 1 )
 - term.write( "+" .. string.rep("-", w - 2) .. "+" )
 - term.setCursorPos( 1, h )
 - term.write( "+" .. string.rep("-", w - 2) .. "+" )
 - for i = 1, h - 2 do
 - term.setCursorPos( 1, i + 1 )
 - term.write( "|" .. string.rep(" ", w - 2) .. "|" )
 - end
 - term.setCursorPos( 2, 2 )
 - term.write( "[j] = " .. ( junk and "Enable junkloot" or "Disable junkloot" ) )
 - if junk then
 - term.setCursorPos( 2, 3 )
 - term.write( "[k] = Current junk side: " .. junkside )
 - end
 - term.setCursorPos( 2, junk and 4 or 3 )
 - term.write( "[c] = Current loot chest: ".. lootchest )
 - term.setCursorPos( 2, junk and 5 or 4 )
 - print( "\n[s] = Save settings" )
 - local _, c = os.pullEvent("char")
 - if c == "j" then
 - junk = not junk
 - elseif c == "k" then
 - junkside = rs.getSides()[tonumber(popupSides())]
 - elseif c == "c" then
 - lootchest = rs.getSides()[tonumber(popupSides())]
 - elseif c == "s" then
 - local file = fs.open( "melee_turtle", "w" )
 - file.write( textutils.serialize({ junk = junk; lootchest = lootchest; junkside = junkside;}))
 - file.close()
 - end
 - end
 - end
 - local fight = function()
 - local turn = function( s, x )
 - if s == "right" then
 - if x then
 - turtle.turnRight()
 - else
 - turtle.turnLeft()
 - end
 - elseif s == "left" then
 - if x then
 - turtle.turnLeft()
 - else
 - turtle.turnRight()
 - end
 - elseif s == "back" then
 - turtle.turnRight()
 - turtle.turnRight()
 - end
 - end
 - local drop = function( s )
 - if s == "top" then
 - turtle.dropUp()
 - elseif s == "down" then
 - turtle.dropDown()
 - else
 - turtle.drop()
 - end
 - end
 - while true do
 - turtle.attack()
 - if turtle.getItemCount( 16 ) > 0 then
 - if junk then
 - turn( junkside )
 - for i = 1, 16 do
 - turtle.select(i)
 - if turtle.compareTo( 1 ) then
 - drop( junkside )
 - end
 - end
 - turn( junkside, true )
 - end
 - turn( lootchest )
 - for i = 1, 16 do
 - turtle.select( i )
 - drop( lootchest )
 - end
 - turn( lootchest, true )
 - end
 - end
 - end
 - parallel.waitForAny( fight, screenManagement )
 
Advertisement
 
                    Add Comment                
                
                        Please, Sign In to add comment