[Done] How to prevent unit damage

Place to get help with not working mods / modding interface.
Post Reply
TheSAguy
Smart Inserter
Smart Inserter
Posts: 1247
Joined: Mon Jan 13, 2014 6:17 pm

[Done] How to prevent unit damage

Post by TheSAguy » Wed May 23, 2018 7:05 pm

Hi,

In my mod Natural Evolution Enemies, I have the worms launch units at the player.

The problem I have is that the created units are being damaged by the worms own attack.
As can be seen from below image, the 4 units around me is damaged by the worms attack.
Image

On low evolution factor the created units are instantly killed.
I thought that the same force would not hurt itself, is that not the case?

Not sure what code to give here. Mod it attached.
This is the unit creation code:

Code: Select all

---------------------------------------------
-- Spawn Launched Units
function SpawnLaunchedUnits(enemy)
	local subEnemyName = subEnemyNameTable[enemy.name]
	if not subEnemyName then
		return
	end
	if subEnemyNameTable[enemy.name][global.evoFactorFloor] then
		subEnemyName = subEnemyNameTable[enemy.name][global.evoFactorFloor]
	end
	local number = subEnemyNumberTable[enemy.name][global.evoFactorFloor]
	for i = 1, number do
		local subEnemyPosition = enemy.surface.find_non_colliding_position(subEnemyName, enemy.position, 2, 0.5)
		if subEnemyPosition then
			local create_unit = enemy.surface.create_entity({name = subEnemyName, position = subEnemyPosition, force = game.forces.enemy})
		end
	end
end

This is the Worms attack code. (Same Force)

Code: Select all

 --- Mutated WORM Projectile
  {
    type = "projectile",
    name = "Mutated-Projectile-Worm",
    flags = {"not-on-map"},
    acceleration = 0.005,
    action =
    {
      type = "direct",
      action_delivery =
      {
        type = "instant",
        target_effects =
        {
          {
            type = "play-sound",
            sound =
            {
              {
                filename = "__base__/sound/creatures/projectile-acid-burn-1.ogg",
                volume = 0.8
              },
              {
                filename = "__base__/sound/creatures/projectile-acid-burn-2.ogg",
                volume = 0.8
              },
              {
                filename = "__base__/sound/creatures/projectile-acid-burn-long-1.ogg",
                volume = 0.8
              },
              {
                filename = "__base__/sound/creatures/projectile-acid-burn-long-2.ogg",
                volume = 0.8
              }
            }
          },
		  {
			type = "create-entity",
			entity_name = "unit-cluster",
			trigger_created_entity = "true"
          },
		  {
			type = "create-sticker",
			sticker = "slowdown-sticker"
          },
          {
            type = "create-entity",
            entity_name = "acid-splash-purple"
          },
          {
            type = "nested-result",
            action =
            {
              type = "area",
              radius = 2,
              action_delivery =
              {
                type = "instant",
                target_effects =
                {
                  {
					type = "damage",
					damage = {amount = 10*NE_Enemies.Settings.NE_Difficulty, type = "explosion", force = "enemy" }
				  },
				  {
                    type = "damage",
                    damage = {amount = 20*NE_Enemies.Settings.NE_Difficulty, type = "acid", force = "enemy"}
                  },
                }
              }
            }
          }
        }
      }
    },
    animation =
    {
      filename = "__Natural_Evolution_Enemies__/graphics/entity/acid-projectile-red.png",
      line_length = 5,
      width = 16,
      height = 18,
      frame_count = 33,
      priority = "high"
    },
    shadow =
    {
      filename = "__base__/graphics/entity/acid-projectile-purple/acid-projectile-purple-shadow.png",
      line_length = 5,
      width = 28,
      height = 16,
      frame_count = 33,
      priority = "high",
      shift = {-0.09, 0.395}
    },
    rotatable = false
  },
Any thoughts on how to spawn the units and not have them hurt/die from the worms attack?

Thanks.
Attachments
Natural_Evolution_Enemies_8.1.4.zip
Mod
(210.39 KiB) Downloaded 5 times
Last edited by TheSAguy on Wed May 23, 2018 11:33 pm, edited 1 time in total.

Veden
Fast Inserter
Fast Inserter
Posts: 189
Joined: Wed Jul 13, 2016 3:54 pm

Re: How to prevent unit damage

Post by Veden » Wed May 23, 2018 8:27 pm

TheSAguy wrote:{
              type = "area",
              radius = 2,
              action_delivery =
              {
                type = "instant",
                target_effects =
                {
                  {
               type = "damage",
               damage = {amount = 10*NE_Enemies.Settings.NE_Difficulty, type = "explosion", force = "enemy" }
              }
should be something along

Code: Select all

{
              type = "area",
              radius = 2,
              force = "enemy",
              action_delivery =
              {
                type = "instant",
                target_effects =
                {
                  {
               type = "damage",
               damage = {amount = 10*NE_Enemies.Settings.NE_Difficulty, type = "explosion", force = "enemy" }
              }
http://lua-api.factorio.com/latest/Concepts.html

TriggerItem
Table with the following fields:
type :: string: One of "direct", "area", "line", "cluster"
action_delivery :: array of TriggerDelivery (optional)
source_effects :: array of TriggerEffectItem
entity_flags :: EntityPrototypeFlags (optional): The trigger will only affect entities that contain any of these flags.
collision_mask :: CollisionMask: The trigger will only affect entities that would collide with given collision mask.
force :: string: One of "all", "enemy", "ally". If "enemy", the trigger will only affect entities whose force is different from the attacker's and for which there is no cease-fire set. "ally" is the opposite of "enemy".
repeat_count :: uint

TheSAguy
Smart Inserter
Smart Inserter
Posts: 1247
Joined: Mon Jan 13, 2014 6:17 pm

Re: [Done] How to prevent unit damage

Post by TheSAguy » Wed May 23, 2018 11:33 pm

Ah, got it. Thanks Veden!

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 5912
Joined: Fri May 09, 2014 1:01 pm

Re: [Done] How to prevent unit damage

Post by bobingabout » Thu May 24, 2018 8:17 am

you could also just set the resistances of the units of whatever damage type the turret is shooting to a 100% resistance.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.

TheSAguy
Smart Inserter
Smart Inserter
Posts: 1247
Joined: Mon Jan 13, 2014 6:17 pm

Re: [Done] How to prevent unit damage

Post by TheSAguy » Thu May 24, 2018 5:03 pm

bobingabout wrote:you could also just set the resistances of the units of whatever damage type the turret is shooting to a 100% resistance.
True, but let's say the worm did poison damage and I set poison damage resistance to 100%, what happens when you throw a poison capsule at the biter, he eats it and then you for a snack...

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 5912
Joined: Fri May 09, 2014 1:01 pm

Re: [Done] How to prevent unit damage

Post by bobingabout » Fri May 25, 2018 8:07 am

TheSAguy wrote:
bobingabout wrote:you could also just set the resistances of the units of whatever damage type the turret is shooting to a 100% resistance.
True, but let's say the worm did poison damage and I set poison damage resistance to 100%, what happens when you throw a poison capsule at the biter, he eats it and then you for a snack...
I didn't say it was the best solution, just that it's an option.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.

TheSAguy
Smart Inserter
Smart Inserter
Posts: 1247
Joined: Mon Jan 13, 2014 6:17 pm

Re: [Done] How to prevent unit damage

Post by TheSAguy » Thu Jun 21, 2018 7:39 pm

Hmm,
I was wondering if there is a way to prevent the fire attack created by the spitters, killing themselves? (I don't want to give the units 100% fire resistances )
Image

As you can see from the above action... they die when they walk in the fire they created.
I added "force = "enemy"" to just about every spot I could, but this still happens. Here is the code:
(I got rid of some if the smoke and sound stuff to make it a little easier to read)

Code: Select all



-- Stream Spitters
function Spitter_Attack_Stream(data)
  return
  {
    type = "stream",
	force = "enemy",
    ammo_category = "flamethrower",
    cooldown = data.cooldown,
    range = data.range,
    projectile_creation_distance = 1.9,
    damage_modifier = data.damage_modifier or 1.0,
    warmup = 15,
	min_range = 6,
    turn_range = 1.0 / 3.0,
	fire_penalty = 15,	
	gun_barrel_length = 2 * data.scale,
	gun_center_shift = {
	    north = {0, -0.65 * data.scale},
	    east = {0, 0},
	    south = {0, 0},
	    west = {0, 0}
	},
    ammo_type =
	    {
        category = "flamethrower",
        action =
		    {
			type = "direct",
			force = "enemy",
			action_delivery =
			    {
				type = "stream",
				force = "enemy",
				stream = "ne-fire-stream",
				duration = 160,
			    }
		    }
	    },
      cyclic_sound = {}

    animation = ne_spitter_attack_animation(data.scale, data.tint),
  }
end



data:extend(
{
---Fire Stream
  {
    type = "stream",
    name = "ne-fire-stream",
	force = "enemy",
    flags = {"not-on-map"},
    stream_light = {intensity = 1, size = 4},
    ground_light = {intensity = 0.8, size = 4},

    smoke_sources = {},

    action =
    {
      {
        type = "direct",
		force = "enemy",
        action_delivery =
        {
          type = "instant",
		  force = "enemy",
          target_effects =
          {
            {
              type = "create-fire",
			  force = "enemy",
              entity_name = "ne-fire-flame-2"
            }
          }
        }
      },
      {
        type = "area",
		force = "enemy",
        radius = 2.5,
        action_delivery =
        {
          type = "instant",
		  force = "enemy",
          target_effects =
          {
            {
              type = "create-sticker",
			  force = "enemy",
              sticker = "ne-fire-sticker-2"
            },
            {
              type = "damage",
			  force = "enemy",
              damage = { amount = 3, type = "fire", force = "enemy" },
              apply_damage_to_trees = true
            }
          }
        }
      }
    },

    spine_animation =
    {},

    shadow =
    {  },

    particle ={}
  },
}
)


local my_new_fire_flame = util.table.deepcopy(data.raw["fire"]["fire-flame"])
my_new_fire_flame.name = "ne-fire-flame-2"
my_new_fire_flame.force = "enemy"
my_new_fire_flame.damage_per_tick = {amount = 5 / 60, type = "fire", force = "enemy"}
my_new_fire_flame.initial_lifetime = 20
my_new_fire_flame.maximum_lifetime = 300
my_new_fire_flame.burnt_patch_lifetime = 200
my_new_fire_flame.emissions_per_tick = 0
my_new_fire_flame.lifetime_increase_by = 50
my_new_fire_flame.smoke = {}


data:extend({my_new_fire_flame})


local my_new_fire_sticker = util.table.deepcopy(data.raw["sticker"]["fire-sticker"])
my_new_fire_sticker.name = "ne-fire-sticker-2"
my_new_fire_sticker.force = "enemy"
my_new_fire_sticker.duration_in_ticks = 15 * 60
my_new_fire_sticker.target_movement_modifier = 0.8
my_new_fire_sticker.damage_per_tick = { amount = 80 / 60, type = "fire",force = "enemy" }
my_new_fire_sticker.spread_fire_entity = "fire-flame-on-tree"
my_new_fire_sticker.fire_spread_cooldown = 30
my_new_fire_sticker.fire_spread_radius = 0.75
	

data:extend({my_new_fire_sticker})




Thanks.

orzelek
Smart Inserter
Smart Inserter
Posts: 3258
Joined: Fri Apr 03, 2015 10:20 am

Re: [Done] How to prevent unit damage

Post by orzelek » Sat Jun 23, 2018 8:19 am

I'm not sure if fire fields can be made selective - I'm guessing that they have no associated force - it's just a burning fire.
I think you might want to add some special "biter fire" damage type and then make biters resistant to it.

Post Reply

Return to “Modding help”