Goal conditions for custom scenario (kill all aliens) SOLVED

Place to get help with not working mods / modding interface.
plush
Manual Inserter
Manual Inserter
Posts: 2
Joined: Thu Oct 22, 2015 11:10 am
Contact:

Goal conditions for custom scenario (kill all aliens) SOLVED

Post by plush »

*EDIT*
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)
For testing this command for killing all enemies was useful (other commands found were outdated):

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;
*/EDIT*

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 game.set_game_state{gamefinished = true, playerwon = true}

but that does not seem to work when entering it on the ingame console/control.lua script.

I thought to have some script like:
require "defines"

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
Last edited by plush on Thu Oct 22, 2015 11:26 pm, edited 1 time in total.
User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: Goal conditions for custom scenario (kill all aliens)

Post by prg »

Needs more underscores.

Code: Select all

game.set_game_state{game_finished = true, player_won = true}
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!
plush
Manual Inserter
Manual Inserter
Posts: 2
Joined: Thu Oct 22, 2015 11:10 am
Contact:

Re: Goal conditions for custom scenario (kill all aliens)

Post by plush »

Thanks! Works like charm ^_^
Post Reply

Return to “Modding help”