Page 1 of 1

Allow "ammo" as ItemPrototypeFilter

Posted: Thu Jun 27, 2024 1:00 pm
by Pi-C
We already can use

Code: Select all

fuel_items = game.get_filtered_item_prototypes({ {filter = "fuel"} })
to get a list of all items with a fuel_value. Could we get a similar filter "ammo", please? This would make it possible to simply use

Code: Select all

ammo_items = game.get_filtered_item_prototypes({ {filter = "ammo"} })
instead of

Code: Select all

local ammo_items = {}
for i_name, i_proto in pairs(game.item_prototypes) do
  ammo_type = i_proto.get_ammo_type()
  ammo_items[i_name] = ammo_type and ammo_type.category and i_proto
end

Re: Allow "ammo" as ItemPrototypeFilter

Posted: Thu Jun 27, 2024 1:39 pm
by Bilka
Use this:

Code: Select all

game.get_filtered_item_prototypes({{filter = "type", type = "ammo"}})
Something like filter = "tool" returns everything that is a tool prototype, including its children like repair-tool. Using the "type" filter and an item prototype type (like "ammo") returns only prototypes with that exact type.

Re: Allow "ammo" as ItemPrototypeFilter

Posted: Thu Jun 27, 2024 2:26 pm
by Pi-C
Bilka wrote:
Thu Jun 27, 2024 1:39 pm
Use this:

Code: Select all

game.get_filtered_item_prototypes({{filter = "type", type = "ammo"}})
Thanks! That should have been a nobrainer as I've used the 'type' filter before. But I've somehow forgotten that 'ammo' is regarded as an item with just another type … Sorry for the noise! :oops: