Page 1 of 1

[Solved] Create New Enemy Force

Posted: Sat Sep 26, 2020 9:23 am
by rookhaven
Hi all,

I would like to create a new enemy force from scratch and haven't found any examples of this yet.

1.) I'm trying to see how they do it in base and a couple mods (BigEnemies for example) but it seems like mods copy existing biters and in base I can't see how they actually implement the force.
2.) In base, biters are of type unit, and the only reference I see to enemies is the subgroup (subgroup="enemies").
3.) I'm also looking through the LuaForce class but I'm not sure how to actually create the new force.

Do I extend data like we do with entities? I don't see a 'Type' field in the LuaForce class, so wasn't sure what to put in the Type if I did it that way.

The overall objective is to create a simple enemy force, add in a couple units, and see if I can make them attack me. Then add in CAPITAL SHIPS WOOT.

Re: Create New Enemy Force

Posted: Sat Sep 26, 2020 10:43 am
by darkfrei

Code: Select all

/c
local force_name = 'enemy-2'
if not game.forces[force_name] then game.create_force(force_name) end
local surface = game.player.surface
local entities = surface.find_entities_filtered {force='enemy', type = 'unit'}
for i, ent in pairs (entities) do
  ent.force = force_name
  rendering.draw_sprite {sprite = "utility/custom_tag_in_map_view", surface = surface, target = ent}
end

Re: Create New Enemy Force

Posted: Sat Sep 26, 2020 5:15 pm
by rookhaven
Sweet, thanks!