[Solved] Create New Enemy Force

Place to get help with not working mods / modding interface.
rookhaven
Inserter
Inserter
Posts: 22
Joined: Sun May 07, 2017 9:21 pm
Contact:

[Solved] Create New Enemy Force

Post 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.
Last edited by rookhaven on Sat Sep 26, 2020 5:16 pm, edited 1 time in total.
User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2905
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Create New Enemy Force

Post 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
rookhaven
Inserter
Inserter
Posts: 22
Joined: Sun May 07, 2017 9:21 pm
Contact:

Re: Create New Enemy Force

Post by rookhaven »

Sweet, thanks!
Post Reply

Return to “Modding help”