[Solved] How to attack ALL enemies around turret within a circular area?

Place to get help with not working mods / modding interface.
Post Reply
Schallfalke
Fast Inserter
Fast Inserter
Posts: 162
Joined: Sun Oct 28, 2018 7:57 am
Contact:

[Solved] How to attack ALL enemies around turret within a circular area?

Post by Schallfalke »

Hi all,

I want to make a turret, which attack ALL enemies units within the circular area around them (like the highlighted area of a turret BUT not anything outside it).
My code is as follows (which attack things outside the area), what should be changed?

Code: Select all

    attack_parameters =
    {
      type = "projectile",
      ammo_category = "electric",
      cooldown = 10,
      projectile_center = {0, 0},
      projectile_creation_distance = 0.6,
      range = 16,
      sound =
      {
         filename = "__base__/sound/fight/pulse.ogg",
         volume = 0.4
      },
      ammo_type =
      {
        type = "projectile",
        category = "electric",
        energy_consumption = "200kJ",
        speed = 1,
        action =
        {
          {
            type = "area",
            radius = 16,
            force = "enemy",
            action_delivery =
            {
             {
               type = "instant",
               target_effects =
               {
                {
                  type = "create-sticker",
                  sticker = "stun-sticker"
                },
               }
             },
            }
          }
        }
      }
    },
Last edited by Schallfalke on Mon Jan 21, 2019 3:38 pm, edited 1 time in total.

Schallfalke
Fast Inserter
Fast Inserter
Posts: 162
Joined: Sun Oct 28, 2018 7:57 am
Contact:

Re: How to attack ALL enemies around turret within a circular area?

Post by Schallfalke »

I have drawn a picture to illustrate what I desired, against what is done by the code above.
Simply to say, I want the attacked area fixed, no matter where the turret is targeting.
TurretArea.png
TurretArea.png (81.93 KiB) Viewed 1047 times

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5150
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: How to attack ALL enemies around turret within a circular area?

Post by Klonan »

You need to do the area trigger as a source_effect,

Code: Select all


attack_parameters =
{
  type = "projectile",
  ammo_category = "electric",
  cooldown = 10,
  projectile_center = {0, 0},
  projectile_creation_distance = 0.6,
  range = 16,
  sound =
  {
     filename = "__base__/sound/fight/pulse.ogg",
     volume = 0.4
  },
  ammo_type =
  {
    type = "projectile",
    category = "electric",
    energy_consumption = "200kJ",
    speed = 1,
    action =
    {
      {
        type = "instant",
        source_effects =
        {
          {
            type = "nested-result",
            affects_target = true,
            action =
            {
              type = "area",
              radius = 6,
              force = "enemy",
              action_delivery =
              {
                type = "instant",
                target_effects =
                {
                  {
                    type = "damage",
                    damage = { amount = 250, type = "explosion"}
                  },
                  {
                    type = "create-sticker",
                    sticker = "stun-sticker"
                  }
                }
              }
            }
          },
        }
      }
    }
  }
},
Just like the landmine:
https://github.com/wube/factorio-data/b ... .lua#L5426

Schallfalke
Fast Inserter
Fast Inserter
Posts: 162
Joined: Sun Oct 28, 2018 7:57 am
Contact:

Re: How to attack ALL enemies around turret within a circular area?

Post by Schallfalke »

Thank you! Haven't thought about the land mines. :lol:
There are two missing lines in order to work. I post the working code here, in case someone have the same query in the future.

Code: Select all

attack_parameters =
{
  type = "projectile",
  ammo_category = "electric",
  cooldown = 10,
  projectile_center = {0, 0},
  projectile_creation_distance = 0.6,
  range = 16,
  sound =
  {
     filename = "__base__/sound/fight/pulse.ogg",
     volume = 0.4
  },
  ammo_type =
  {
    type = "projectile",
    category = "electric",
    energy_consumption = "200kJ",
    speed = 1,
    action =
    {
      type = "direct",
      action_delivery =
      {
        type = "instant",
        source_effects =
        {
          {
            type = "nested-result",
            affects_target = true,
            action =
            {
              type = "area",
              radius = 16,
              force = "enemy",
              action_delivery =
              {
                type = "instant",
                target_effects =
                {
                  {
                    type = "create-sticker",
                    sticker = "stun-sticker"
                  }
                }
              }
            }
          },
        }
      }
    }
  }
},

Post Reply

Return to “Modding help”