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

[Lua] Simple request, (turtle.drop) for a mob grinder.

Started by Stormcrown, 06 April 2013 - 10:04 AM
Stormcrown #1
Posted 06 April 2013 - 12:04 PM
So, I am trying to set up a very simple melee turtle witch grinder.

I have 8 melee turtles with relays underneath them.


while true do
turtle.attack()
sleep(.1)
turtle.suck()
turtle.dropDown()
end

This is working, but it only drops the first item, and the witches drop items faster than that and the turtles quickly overflow.

I've messed with it a bit and can't figure out how to get the turtles to drop all of the items in their inventory.

Really new at this. I apologize if this board is for more complex issues, I figured I would ask here and get the most efficient way of doing things, rather than spend hours trying to find the proper commands.
Engineer #2
Posted 06 April 2013 - 12:11 PM
You want to use a for-loop:

for i = 1, 16 -- Set it to the amount of inventory space
   turtle.select(i)
   turtle.drop()
end

If you have further questions about this, please ask them!
Stormcrown #3
Posted 06 April 2013 - 12:18 PM
So for it to drop all inventory spaces (1-16)

the code would be…


while true do
turtle.attack()
sleep(.1)
turtle.suck()
for i = 1, 16
   turtle.select(i)
   turtle.drop()
end
end

Yes?

I thought of having them be XP melee turtles, and put an ender chest with books to their left and behind, and have the pneumatic tubes sort the enchanted books below. Picture. Would this be horribly difficult?

Is there a list of functions somewhere? I don't know what the command for enchant is, and the wiki doesn't seem to like me searching randomly for it.
slango20 #4
Posted 06 April 2013 - 12:23 PM
You want to use a for-loop:

for i = 1, 16 -- Set it to the amount of inventory space
   turtle.select(i)
   turtle.drop()
end

If you have further questions about this, please ask them!
I know that works, but as an alternative, a while loop:

local X = 0
while X < 16 do
turtle.select(X)
turtle.dropDown()
X = X + 1
end
just add that in the existing loop
EDIT: the dude above me posted as I was typing, and yes, it would be difficult, the function is turtle.enchant(X) with X being the level, will set the code now:

local Slot = 0
E = peripheral.wrap("right")
local X = 30 --you can change this
while true do
if E.getLevels() => X do
turtle.enchant(X)
else
turtle.attack()
end
while Slot < 16 do
turtle.select(X)
turtle.dropDown()
Slot = Slot + 1
end
end
Note: didn't test, may not work
Stormcrown #5
Posted 06 April 2013 - 12:24 PM
I seem to be failing with adding this.

How exactly would the end-result look?
QuantumGrav #6
Posted 06 April 2013 - 12:39 PM
Something kinda nice about the 'turtle.attack' function is that it automatically sucks up the items from whatever it kills, so you don't need the command 'turtle.suck'. Also, the command 'turtle.drop()' drops whatever the turtle is holding in front of it, not down which is what your setup needs. Change that to 'turtle.dropDown()'.

Minus the automatic enchanting (I don't have the experience with MiscPeripherals to do that), the code would look like:

while true do
   turtle.attack()
   for i=1,16 do
	 turtle.select(i)
	 turtle.dropDown()
   end
end
This would work, but it's highly inefficient. You could optimize it by changing '16' in the for loop for however many distinct items these 'witches' drop. For instance, if you were making this for skeletons, you would change that line to 'for i=1,2' do'. Skeletons drop two items, bones and arrows. If you were making it for creepers that only drop one item, gunpowder, you would change the code to:

turtle.select(1)
while true do
  turtle.attack()
  turtle.dropDown()
end

I haven't personally tested either of those codes, but I think they will work. If not, let me know, and I'll see if I can fix it!
Hope that helps!
Stormcrown #7
Posted 06 April 2013 - 12:43 PM
Thank you everyone, very helpful. And nice tip about the distinct items.

Just getting into coding, but I'm more of a head first type of learner….lol. And I really want to get this witch grinder working as I need the gunpowder.
slango20 #8
Posted 07 April 2013 - 01:57 PM
Thank you everyone, very helpful. And nice tip about the distinct items.

Just getting into coding, but I'm more of a head first type of learner….lol. And I really want to get this witch grinder working as I need the gunpowder.
my code above is a full program, try that, it will auto enchant as well, but you have to figure out how to get the items to the turtles