Page 1 of 1

How to tell where a stack of ammo is?

Posted: Mon Apr 18, 2016 5:00 pm
by Vulcan
I am looking for some help on how to tell if a stack of ammo is in an inventory, or in the weapon quickbar, and also if it is in the weapon quickbar what the prototype of the weapon it is attached to is. An example example of what I would like to be able to achieve is that I would like to be able to tell if a stack of shotgun shells is attached to a weapon, and if it is if that weapon is a standard shotgun or a combat shotgun.
I know that the LuaEntity class has the property selected_gun_index (http://lua-api.factorio.com/0.12.29/Lua ... _gun_index), Which allows you to find which gun is currently in use, but I do not know how to access the ammo it is using, or how to extend this idea for any ammo not attached to the weapon currently in use.

Any help would be much appreciated

Re: How to tell where a stack of ammo is?

Posted: Mon Apr 18, 2016 5:21 pm
by Choumiko
use LuaEntitiy.get_inventory(defines.inventory.player_ammo) (defines is a file in Factoriofolder/data/core/lualib)
Use this in the console:

Code: Select all

/c local player = game.local_player
local inv =  player.get_inventory(defines.inventory.player_ammo)
local ammo_name =inv[player.character.selected_gun_index].valid_for_read and inv[player.character.selected_gun_index].name or false
player.print(serpent.line(ammo_name))

Re: How to tell where a stack of ammo is?

Posted: Tue Apr 19, 2016 7:12 pm
by Vulcan
Thanks, defines.inventory does pretty much exactly what I was after.
On a slightly unrelated note, is there any event that is called when a stack of items is manipulated? I really really don't want to have to use defines.events.on_tick