Page 1 of 1

[Solved] How to insert an ammo to specific slot?

Posted: Thu Mar 07, 2019 9:13 pm
by Schallfalke
How to insert an ammo to specific slot?
For example, I want something like if I put the submachine gun at gun slot 2, a stack of piercing bullets will be inserted to ammo slot 2. How can I do that?

Using LuaInventory::insert() does not work as desired, because it will always try to insert to slot 1 first.

Re: How to insert an ammo to specific slot?

Posted: Fri Mar 08, 2019 5:00 am
by DaveMcW

Code: Select all

local inventory = player.get_inventory(defines.inventory.player_ammo)
inventory[2].set_stack({name="piercing-rounds-magazine", count=200})

Re: [Solved] How to insert an ammo to specific slot?

Posted: Fri Mar 08, 2019 7:58 am
by Schallfalke
You have my big thanks again! :D
The solution works like charm.