Access to entity prototype's "action" field

Place to get help with not working mods / modding interface.
User avatar
wasmoo
Burner Inserter
Burner Inserter
Posts: 9
Joined: Mon Apr 27, 2020 11:57 am
Contact:

Access to entity prototype's "action" field

Post by wasmoo »

I'm trying to dynamically determine the "damage-type" of the cursor's item stack. For example, if holding a "poison-capsule", I want to find the damage-type "poison".

However, for poison capsules, the damage isn't done by the thrown attack_parameters, but rather from a smoke-with-trigger that has an `action` that deals poison. I am unable to get access to the `smoke-with-trigger` action.

I'm also having a similar difficulty accessing the `land-mine` action and the `artillery-projectile` action.
User avatar
wasmoo
Burner Inserter
Burner Inserter
Posts: 9
Joined: Mon Apr 27, 2020 11:57 am
Contact:

Re: Access to entity prototype's "action" field

Post by wasmoo »

I was able to create a workaround where I create an `ammo-type` for the action.
However, this had a different problem where the "nested-result" effect had a type of "nil", and I couldn't retrieve the underlying action.
Rseding91
Factorio Staff
Factorio Staff
Posts: 14290
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Access to entity prototype's "action" field

Post by Rseding91 »

All of this is readable from the prototypes already.
If you want to get ahold of me I'm almost always on Discord.
Bilka
Factorio Staff
Factorio Staff
Posts: 3309
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Access to entity prototype's "action" field

Post by Bilka »

To give more info, LuaEntityPrototype::attack_result provides the action of the smoke-with-trigger, landmine and artillery-projectile (and more).
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
User avatar
wasmoo
Burner Inserter
Burner Inserter
Posts: 9
Joined: Mon Apr 27, 2020 11:57 am
Contact:

Re: Access to entity prototype's "action" field

Post by wasmoo »

Thank you. The issue seems to be that the "nested-result" TriggerEffectItem has a type of nil. This code logs the nil type:

Code: Select all

  for _,prototype in pairs({game.entity_prototypes["land-mine"]}) do
    for a_index,trigger_item in pairs(prototype.attack_result or {}) do
      for d_index,trigger_delivery in pairs(trigger_item.action_delivery or {}) do
        for _, effects_key in pairs({"source_effects", "target_effects"}) do
          for e_index, trigger_effect_item in pairs(trigger_delivery[effects_key] or {}) do
            log("game.entity_prototypes[" .. prototype.name .. "]"
              .. ".attack_result[" .. a_index .. "]"
              .. ".action_delivery[" .. d_index .. "]"
              .. "." .. effects_key .. "[" .. e_index .. "].type=" .. serpent.line(trigger_effect_item.type) )
          end
        end
      end
    end
  end
I can access the `action` field, so my original issue is resolved. However, the missing type should be still fixed to avoid future confusion.
User avatar
wasmoo
Burner Inserter
Burner Inserter
Posts: 9
Joined: Mon Apr 27, 2020 11:57 am
Contact:

Re: Access to entity prototype's "action" field

Post by wasmoo »

Seems like there are more nuances with `nested_result`. Sometimes it has an `action` and sometimes it's just an array of TriggerEffectItem.
Post Reply

Return to “Modding help”