Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Extract Item
- Written 2014 ingie -> ing@ingie.com
- Usage: extractItems Name [Qty] [Fuzzy]
- do with it what you will...
- knowledge is free and licences are just beurocracy
- if you want to say who wrote it, that's nice of you...
- ]]--
- -- setup
- local args = { ... }
- local AESide = "left"
- local turtleDirection = "south"
- -- helpers
- local isMatchingItem = function( _itemName, _search, _fuzzy )
- if not _fuzzy then
- return ( _itemName == _search )
- else
- return string.find( string.lower(_itemName) , string.lower(_search) )
- end
- end
- -- functions
- local extractNamedItem = function( _ae, _search, _direction, _qty, _fuzzy )
- local _all = _ae.getAvailableItems()
- local _found = { }
- for _, _v in pairs(_all) do
- if isMatchingItem( _v.name, _search, _fuzzy ) then
- local _ex = _ae.extractItem( { id = _v.id, qty = _qty, dmg = _v.dmg } , _direction )
- if _ex then
- table.insert( _found,_v )
- end
- if not _fuzzy then break end
- end
- end
- return _found
- end
- -- parse arguments
- if #args < 1 or #args > 3 then
- print("Usage: extractItems Name [Qty] [Fuzzy]")
- error()
- end
- local searchName = args[1]
- local qty = ( #args >= 1 and tonumber(args[2]) ) or 1
- local fuzziness = ( #args >= 2 and string.lower(args[3]) == "true" ) or false
- -- do the extraction thing
- local extracted = extractNamedItem( peripheral.wrap(AESide), searchName, turtleDirection, qty, fuzziness )
- if extracted and #extracted > 0 then
- for k,v in ipairs(extracted) do
- print("Extracted : "..tostring(v.name))
- end
- else
- print("Unable to extract item \""..searchName.."\".")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement