Suf wrote: Sat Mar 27, 2021 12:44 pm
Code: Select all
/c
game.set_game_state {
game_finished = true,
player_won = true,
can_continue = true,
victorious_force = game.forces.player,
}
Typing it as this results in error
Typing this as it is doesn't result in an error for me -- but I didn't get the victory screen either. Could it be possible that this only works from a control script?
bounding it to an entity seems to do that error, but what if i wanted the following to happen: if the player built a specific entity it will trigger an event which leads to that winning condition.
an example of how to do that would be nice,because i don't know how this coding process work
Use that in control.lua:
Code: Select all
script.on_event(id, defines.events.on_built_entity, function(event)
local entity = event.created_entity
if entity.name == "stone-furnace" then
game.set_game_state {
game_finished = true,
player_won = true,
can_continue = true,
victorious_force = game.forces.player,
}
end
end)
You can also use filters:
Code: Select all
script.on_event(id, defines.events.on_built_entity, function(event)
game.set_game_state {
game_finished = true,
player_won = true,
can_continue = true,
victorious_force = game.forces.player,
}
end, {
{filter = "type", type = "furnace"},
{filter = "name", name = "stone-furnace", mode = "and" }
})
Additionally: can i control the entity count for victory condition ?
Code: Select all
global = global or {}
global.entity_count = 0
script.on_event(id, defines.events.on_built_entity, function(event)
global.entity_count = global.entity_count + 1
if global.entity_count == 3 then
game.set_game_state {
game_finished = true,
player_won = true,
can_continue = true,
victorious_force = game.forces.player,
}
end
end, {
{filter = "type", type = "furnace"},
{filter = "name", name = "stone-furnace", mode = "and" }
})
can i add a timer for that event to happen,
Check game.tick! 60 ticks are 1 second. Assume you want the player to lose if less than 3 stone furnaces have been built in the first 5 minutes, add the following:
Code: Select all
script.on_event(defines.events.on_tick, function(event)
if event.tick > 5 * 60 * 60 and global.entity_count < 3 then
game.set_game_state {
game_finished = true,
player_won = false,
can_continue = false,
victorious_force = game.forces.player,
}
end
end)
and finally can i add stages for that winning condition as checklist or something of that nature and when the player do all of them it will trigger the winning condition.
Code: Select all
global = global or {}
global.furnaces = 0
global.belts = 0
global.tasks = 0
script.on_event(id, defines.events.on_built_entity, function(event)
local entity = event.created_entity
if entity.name == "stone-furnace" and global.furnaces < 3 then
global.furnaces = global.furnaces + 1
if global.furnaces == 3 then
global.tasks = global.tasks + 1
end
elseif entity.name == "transport-belt" and global.belts < 5 then
global.belts = global.belts + 1
if global.belts == 5 then
global.tasks = global.tasks + 1
end
end
end, {
{filter = "type", type = "furnace"},
{filter = "name", name = "stone-furnace", mode = "and" },
{filter = "type", type = "transport-belt"},
{filter = "name", name = "transport-belt", mode = "and" },
})
script.on_event(defines.events.on_tick, function(event)
if event.tick > 5 * 60 * 60 and global.tasks < 2 then
game.set_game_state {
game_finished = true,
player_won = false,
can_continue = false,
victorious_force = game.forces.player,
}
end
end)