Thanks to prg's help I could finish my script.
In case anyone else wonders how to set the goal condition for a custom (finite) map to "exterminate all aliens,worms and spawners" then create or edit control.lua in your scenario folder and add the following:
NOTE: Maybe this can be solved better, but my Lua knowledge is quite limited at this point. So hints, suggestions, corrections welcome ;3
Code: Select all
require "defines"
script.on_event(defines.events.on_tick, function(event)
if (game.forces.enemy.get_entity_count("small-biter") == 0
and game.forces.enemy.get_entity_count("medium-biter") == 0
and game.forces.enemy.get_entity_count("big-biter") == 0
and game.forces.enemy.get_entity_count("behemoth-biter") == 0
and game.forces.enemy.get_entity_count("small-spitter") == 0
and game.forces.enemy.get_entity_count("medium-spitter") == 0
and game.forces.enemy.get_entity_count("big-spitter") == 0
and game.forces.enemy.get_entity_count("behemoth-spitter") == 0
and game.forces.enemy.get_entity_count("small-worm-turret") == 0
and game.forces.enemy.get_entity_count("medium-worm-turret") == 0
and game.forces.enemy.get_entity_count("big-worm-turret") == 0
and game.forces.enemy.get_entity_count("biter-spawner") == 0
and game.forces.enemy.get_entity_count("spitter-spawner") == 0)
then
game.set_game_state{game_finished = true, player_won = true}
end
end)
Code: Select all
/c radius = 500;
p = game.player.position;
for _,type in pairs{"unit", "unit-spawner", "turret"} do;
enemies = game.get_surface(1).find_entities_filtered{area={{p.x-radius,p.y-radius},{p.x+radius,p.y+radius}}, type=type, force=game.forces.enemy};
for _,enemy in pairs(enemies) do enemy.destroy(); end;
end;
Original post:
Hi, dont know if this is the right section to post this, so: sorry if it is not.
I built a small challenge scenario map, for which I want the goal to be the extermination of the aliens. Though I have trouble with scripting this correctly.
In the wiki there is
but that does not seem to work when entering it on the ingame console/control.lua script.
I thought to have some script like:
script.on_event(defines.events.on_tick, function(event)
if game.forces.enemy.get_entity_count("small-biter") == 0 then
game.set_game_state{gamefinished = true, playerwon = true}
end
end)
Either it does not work at all, or the game crashes with a stacktrace that does not reveal anything useful.
Any hints/help would be much appreciated. It could be made into a generic script that could work with any scenario map....
Thanks in advance! :3