Page 1 of 1

Created Entity Force Help

Posted: Tue Apr 16, 2019 5:34 pm
by TheSAguy
Hi,

I have a unit launching Spitter. He shoots projectiles that spawn into units.

Everything works fine on the "Enemy" force, but if I convert the unit, via my NE Buildings mod, the spawned units still have "Enemy" as force and as a result attack me and the unit that created them...

The projectile seems to have a force of "Neutral", so I can't set it to that.
This is the code:

In Control, that spawns the units:

Code: Select all

-- Spawn Launched Units 
function SpawnLaunchedUnits(enemy, unit_to_spawn)
	local subEnemyName = subEnemyNameTable[enemy.name]
	
	if not subEnemyName then
		return
	end
	
	if subEnemyNameTable[enemy.name][global.evoFactorFloor] then
		if enemy.name == "ne_green_splash_1" then
			subEnemyName = subEnemyNameTable[enemy.name][global.evoFactorFloor]
		else
			subEnemyName = unit_to_spawn.spawn..subEnemyNameTable[enemy.name][global.evoFactorFloor]
		end
	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
		
			--writeDebug("The ne_green_splash_1 force is: " .. enemy.force.name)
			create_unit = enemy.surface.create_entity({name = subEnemyName, position = subEnemyPosition})
			--writeDebug("The Created Unit's force is: " .. create_unit.force.name)
			--create_unit = enemy.surface.create_entity({name = subEnemyName, position = subEnemyPosition, force = game.forces.enemy})
			create_unit.health = create_unit.health *.95
			Remove_Trees(create_unit)
			
		end
	end
end

The Spitter's Attack parameters:

Code: Select all

-- Spitter Projectile - Non-Honing
function Spitter_Attack_Projectile_NH(data)
  return
  {
    type = "projectile",
    ammo_category = "rocket",
    cooldown = data.cooldown,
    range = data.range,
    projectile_creation_distance = data.projectile_creation_distance,
    ammo_type =
    {
      category = "rocket",
	  clamp_position = true,
	  target_type = "position",
      action =
      {
        type = "direct",
        action_delivery =
        {
          type = "projectile",
          projectile = data.projectile,
          starting_speed = 0.3,
		  max_range = data.range,
        }
      }
    },
	sound = make_spitter_roars(data.roarvolume),
    animation = spitterattackanimation(data.scale, data.tint1, data.tint2),
  }
end


The Projectile:

Code: Select all


--- Unit Unit-Projectiles
  {
    type = "projectile",
    name = "Unit-Projectile",
    flags = {"not-on-map"},
    acceleration = 0.005,
    action =
    {
      type = "direct",
      action_delivery =
      {
        type = "instant",
        target_effects =
        {		  
          {
            type = "create-entity",
			entity_name = "ne_unit_launcher_trigger_1",			
          },
		  {
			type = "damage",
			damage = { amount = 2 , type = "physical"}
		  },
		  {
			type = "create-sticker",
			sticker = "slowdown-sticker"
          },
        }
      }
    },
	animation =
    {
      filename = "__Natural_Evolution_Enemies__/graphics/entity/acid-projectile-green.png",
      line_length = 5,
      width = 16,
      height = 18,
      frame_count = 33,
      priority = "high"
    },
    shadow =
    {
      filename = "__Natural_Evolution_Enemies__/graphics/entity/acid-projectile-purple-shadow.png",
      line_length = 5,
      width = 28,
      height = 16,
      frame_count = 33,
      priority = "high",
      shift = {-0.09, 0.395}
    },
    rotatable = false
  },
The Trigger:

Code: Select all

--- Unit Launcher Smoke that will cause the Trigger
Unit_Launcher_Trigger_1 = table.deepcopy(data.raw["smoke-with-trigger"]["poison-cloud"])
Unit_Launcher_Trigger_1.name = "ne_unit_launcher_trigger_1"
Unit_Launcher_Trigger_1.duration = 60 * 1
Unit_Launcher_Trigger_1.fade_away_duration = 0
Unit_Launcher_Trigger_1.spread_duration = 0
Unit_Launcher_Trigger_1.action = {
	type = "direct",
    action_delivery =
    {
       type = "instant",
        target_effects =
        {
            type = "create-entity",
			entity_name = "ne_green_splash_1",
			trigger_created_entity = true,
        },
      }
    }
Unit_Launcher_Trigger_1.slow_down_factor = 1
Unit_Launcher_Trigger_1.cyclic = true
Unit_Launcher_Trigger_1.color = { r = 0/255, g = 0/255, b = 0/255, a = 0}
Unit_Launcher_Trigger_1.animation =
    { -- No Animations
      filename = "__Natural_Evolution_Enemies__/graphics/entity/empty.png",
      flags = { "compressed" },
      priority = "low",
      width = 32,
      height = 32,
      frame_count = 1,
      animation_speed = 1,
      line_length = 1,
      scale = 1
    }
	
data:extend{Unit_Launcher_Trigger_1}
The Splash:

Code: Select all

--- Green Splash 1 - Units
Green_Splash = table.deepcopy(data.raw["corpse"]["ne-acid-splash-purple"])
Green_Splash.name = "ne_green_splash_1"
Green_Splash.time_before_removed = 60 * 15
Green_Splash.splash =
    {
      {
        filename = "__Natural_Evolution_Enemies__/graphics/entity/splash-1.png",
        line_length = 5,
        width = 199,
        height = 159,
        frame_count = 20,
		tint = {r = 0, g = 1, b = 0, a = 1},
        shift = {0.484375, -0.171875}
      },
      {
        filename = "__Natural_Evolution_Enemies__/graphics/entity/splash-2.png",
        line_length = 5,
        width = 238,
        height = 157,
        frame_count = 20,
		tint = {r = 0, g = 1, b = 0, a = 1},
        shift = {0.8125, -0.15625}
      },
      {
        filename = "__Natural_Evolution_Enemies__/graphics/entity/splash-3.png",
        line_length = 5,
        width = 240,
        height = 162,
        frame_count = 20,
		tint = {r = 0, g = 1, b = 0, a = 1},
        shift = {0.71875, -0.09375}
      },
      {
        filename = "__Natural_Evolution_Enemies__/graphics/entity/splash-4.png",
        line_length = 5,
        width = 241,
        height = 146,
        frame_count = 20,
		tint = {r = 0, g = 1, b = 0, a = 1},
        shift = {0.703125, -0.375}
      }
    }

data:extend{Green_Splash}

So a lot of things happening from the Unit shooting till the final units are spawned and I'm not sure how to get back to the original force to match the created units to that force...

Full mod attached.
Thanks.