Modify an Entity by event

Place to get help with not working mods / modding interface.
Post Reply
User avatar
Yokmp
Inserter
Inserter
Posts: 26
Joined: Tue Aug 23, 2016 10:30 am
Contact:

Modify an Entity by event

Post by Yokmp »

Hi,
i try to modify the Cargo-Wagons inventory Size by researching a technology.
But i can't figure out the nothing type effect_description usage.
1 - How do i get the Locales to work?
technology.lua:

Code: Select all

data:extend(
  {
    {
      type = "technology",
      name = "cargo-wagon-inventory-1",
-- and so on
      effects =
      {
        {
          type = "nothing",
          effect_description = "cargo-wagon-decription",
        },
      },
-- unit, time, etc
})
Now my main Problems:
2 - How do i check if the currently researched Tech is the right one?
3 - How can i change the Cargo Wagons inventory_size for every alredy placed Cargowagons and also for the ones in my Inventory or a Chest.
Do i also have to change the entity itself so a new one built will get changhed too?

As far as i know i have to do this in control.lua:

Code: Select all

script.on_event(
  {
    defines.events.on_research_finished
  },
  function()

        wagon = game.get_entity_by_tag("cargo-wagon")
        wagon.inventory_size = 50

  end
)

Bilka
Factorio Staff
Factorio Staff
Posts: 3133
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Modify an Entity by event

Post by Bilka »

Yokmp wrote:
Sat Dec 15, 2018 1:30 am
1 - How do i get the Locales to work?
You give a localized string as the description. How those work is described here https://lua-api.factorio.com/latest/Con ... isedString and more in depth here: https://wiki.factorio.com/Tutorial:Localisation
Yokmp wrote:
Sat Dec 15, 2018 1:30 am
2 - How do i check if the currently researched Tech is the right one?
https://lua-api.factorio.com/latest/eve ... h_finished gives you the research that was finished as a LuaTechnology. You can use that to check which research finished.
3 - How can i change the Cargo Wagons inventory_size for every alredy placed Cargowagons and also for the ones in my Inventory or a Chest.
Do i also have to change the entity itself so a new one built will get changhed too?
You will have to replace the already built entities with new ones of a higher inventory size. There are multiple ways to handle the player placing old entities with a lower inventory size, I personally would simply replace the entity in the on built event.
Yokmp wrote:
Sat Dec 15, 2018 1:30 am
wagon = game.get_entity_by_tag("cargo-wagon")
This does not do what you think it does. It gets 1 entity with the tag cargo wagon on the map. In a vanilla game, no entities have tags. If you want to get all entities of the type cargo wagon on the map, you will have to perform an entity search: https://lua-api.factorio.com/latest/Lua ... s_filtered
Yokmp wrote:
Sat Dec 15, 2018 1:30 am
wagon.inventory_size = 50
This property doesn't exist, and if it would, it wouldn't be writable.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

Post Reply

Return to “Modding help”