[MOD 0.11.x] canInsert() that returns a count
Posted: Wed Aug 20, 2014 9:09 am
This isn't so much a mod its self as it is a function for modders to use. It's a function that takes an entity, a table of inventory indexes and a item stack and returns a table with the ["count"] that can be inserted and the count of slots ["slots"] that will get used by inserting that many of the stack.
Example usage:
For a more complex usage example see my mod "Faster Spilling" -> here
Current version: 1.1.0
Example usage:
Code: Select all
local result = canInsert(game.player, {[1] = 2}, {name = "iron-ore", count = 5000})
-- "2" for player inventory index 2 (the main inventory)
if result["count"] > 0 then
game.player.print("Inserting: " .. result["count"] .. " iron-ore using: " .. result["slots"] .. " empty slots.")
game.player.insert({name = "iron-ore", count = result["count"]})
end
Current version: 1.1.0
code
File download: