How to use a dynamic item value?

Place to get help with not working mods / modding interface.
seomaster99
Burner Inserter
Burner Inserter
Posts: 9
Joined: Tue May 08, 2018 1:53 pm
Contact:

How to use a dynamic item value?

Post by seomaster99 »

I need to read the current number of things in the inventory and use it in my code.

An example is this:
In the player's inventory, a stack of 28 items.

I will call it this:

Code: Select all

local factor = ("item name"). value (how much is in the stack)

And I need to do the following in code:

Code: Select all

mining_speed = 2 * 0.05 * factor,
mining_power = 6 * 0.05 * factor,
The value is dynamic, as it decreases and increases the number of stacks in the inventory, it changes.

Tell me pls - how I can implement this in my code.

Sorry for my English :)
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5207
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: How to use a dynamic item value?

Post by eradicator »

http://lua-api.factorio.com/latest/LuaInventory.html

LuaInventory.get_item_count('itemname')

So in your case

LuaPlayerObject.get_inventory(defines.inventory.player_main).get_item_count('your-item-name')
seomaster99
Burner Inserter
Burner Inserter
Posts: 9
Joined: Tue May 08, 2018 1:53 pm
Contact:

Re: How to use a dynamic item value?

Post by seomaster99 »

Thank you!

/close
Post Reply

Return to “Modding help”