So I gave worms the ability to launch units at you.
I did this by adding a a create entity to the projectile:
Code: Select all
{
type = "create-entity",
trigger_created_entity = "true",
entity_name = "unit-cluster"
},
The entity that gets created,"unit-cluster", is a biter with 1 life and a negative life re-gen of -2, so it will die.
Using "defines.events.on_entity_died" I then spawn units when "unit-cluster" dies.
Code: Select all
if (event.entity.name == "unit-cluster") then
SpawnLaunchedUnits(event.entity)
end
Was just wondering if anyone saw any issue doing this?
Thanks.
Control Code
Code: Select all
script.on_event({defines.events.on_entity_died,defines.events.on_robot_pre_mined,defines.events.on_preplayer_mined_item,},function(event) On_Remove(event) end)
---------------------------------------------
function On_Remove(event)
---- Unit Launcher
if global.tick < event.tick then
if game.evolution_factor > 0.995 then
global.evoFactorFloor = 10
else
global.evoFactorFloor = math.floor(game.evolution_factor * 10)
end
global.tick = global.tick + 1800
end
if (event.entity.name == "unit-cluster") then
SpawnLaunchedUnits(event.entity)
end
end
---------------------------------------------
-- 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
enemy.surface.create_entity({name = subEnemyName, position = subEnemyPosition, force = game.forces.enemy})
end
end
end
Unit Cluster Code
Code: Select all
data:extend(
{
{
type = "unit",
name = "unit-cluster",
icon = "__base__/graphics/icons/creeper.png",
flags = {"placeable-player", "placeable-enemy", "placeable-off-grid", "breaths-air"},
max_health = 1,
order = "b-b-a",
subgroup="enemies",
healing_per_tick = -2,
collision_box = {{-0.2, -0.2}, {0.2, 0.2}},
selection_box = {{-0.4, -0.7}, {0.7, 0.4}},
attack_parameters =
{
type = "projectile",
range = 0.05,
cooldown = 300,
ammo_category = "melee",
ammo_type = make_unit_melee_ammo_type(0),
sound = make_biter_roars(0),
animation = biterattackanimation(unit_cluster_scale, unit_cluster_tint1, unit_cluster_tint2)
},
vision_distance = 1,
movement_speed = 0.00002,
distance_per_frame = 0.1,
pollution_to_join_attack = 200000,
distraction_cooldown = 300,
corpse = "unit-cluster-corpse",
dying_explosion = "blood-explosion-small",
dying_sound = make_biter_dying_sounds(0),
working_sound = make_biter_calls(0),
run_animation = biterrunanimation(unit_cluster_scale, unit_cluster_tint1, unit_cluster_tint2)
},
{
type = "corpse",
name = "unit-cluster-corpse",
icon = "__base__/graphics/icons/small-biter-corpse.png",
selection_box = {{-0.8, -0.8}, {0.8, 0.8}},
selectable_in_game = false,
subgroup="corpses",
order = "c[corpse]-a[biter]-a[small]",
flags = {"placeable-neutral", "placeable-off-grid", "building-direction-8-way", "not-repairable", "not-on-map"},
dying_speed = 1,
time_before_removed = 1,
final_render_layer = "corpse",
animation = biterdieanimation(unit_cluster_scale, unit_cluster_tint1, unit_cluster_tint2)
},
Projectile Code
Code: Select all
{
type = "projectile",
name = "Infected-Projectile-Worm",
flags = {"not-on-map"},
acceleration = 0.05,
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",
trigger_created_entity = "true",
entity_name = "unit-cluster"
},
{
type = "create-entity",
entity_name = "Infected-Poison-Cloud"
},
{
type = "damage",
damage = {amount = 10*NE_Difficulty, type = "explosion"}
},
{
type = "damage",
damage = {amount = 20*NE_Difficulty, type = "poison"}
}
}
}
},
animation =
{
filename = "__Natural_Evolution_Enemies__/graphics/entity/acid-projectile-yellow.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
},