I'm trying to get all existing enemy units to attack. I don't care about where they attack, simply that they begin attacking the player or buildings. So far I'm trying this by creating a unit group and adding all units to the unit group and setting their behavior to autonomous, but I've either had errors using the functions or just outright crashing the game.
So far what I've got is this:
EDIT: Word of warning: DON'T DO THIS (Will likely crash the game or your computer)
Code: Select all
local surface = game.surfaces[1]
global.werebiterGroup = surface.create_unit_group({position={0, 0}}) -- Placeholder position, don't think it's important
global.werebiterGroup.set_autonomous()
local enemies = surface.find_enemy_units({0, 0}, 1000) -- Grab all nearby enemies, keep it simple
for _, enemy in pairs(enemies) do
global.werebiterGroup.add_member(enemy)
end