How to tell where a stack of ammo is?

Place to get help with not working mods / modding interface.
Vulcan
Long Handed Inserter
Long Handed Inserter
Posts: 52
Joined: Sat Aug 02, 2014 12:34 pm
Contact:

How to tell where a stack of ammo is?

Post 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
Choumiko
Smart Inserter
Smart Inserter
Posts: 1352
Joined: Fri Mar 21, 2014 10:51 pm
Contact:

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

Post 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))
Vulcan
Long Handed Inserter
Long Handed Inserter
Posts: 52
Joined: Sat Aug 02, 2014 12:34 pm
Contact:

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

Post 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
Post Reply

Return to “Modding help”