Adding/Replacing The Win Condition Other Than Launching the first Rocket
Adding/Replacing The Win Condition Other Than Launching the first Rocket
Hi
Is there a way to add or replace the winning condition in Factorio other than just the vanilla's win condition?
and if so would the Prototype "rocket-silo" be the main target for the Lua codes or something else?
Thanks in advance.
Is there a way to add or replace the winning condition in Factorio other than just the vanilla's win condition?
and if so would the Prototype "rocket-silo" be the main target for the Lua codes or something else?
Thanks in advance.
Re: Adding/Replacing The Win Condition Other Than Launching the first Rocket
Code: Select all
/c
game.set_game_state {
game_finished = true,
player_won = true,
can_continue = true,
victorious_force = game.forces.player,
}
Re: Adding/Replacing The Win Condition Other Than Launching the first Rocket
So this code isn't bound to any prototype?good to know and thanks for the helpDaveMcW wrote: ↑Mon Mar 22, 2021 8:07 pmCode: Select all
/c game.set_game_state { game_finished = true, player_won = true, can_continue = true, victorious_force = game.forces.player, }
Re: Adding/Replacing The Win Condition Other Than Launching the first Rocket
Code: Select all
/c
game.set_game_state {
game_finished = true,
player_won = true,
can_continue = true,
victorious_force = game.forces.player,
}
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
Additionally: can i control the entity count for victory condition ?can i add a timer for that event to happen, 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.
Re: Adding/Replacing The Win Condition Other Than Launching the first Rocket
That didn't answer any of my questions let alone set an example, the pervious answer had the same coding too.
what i don't know is where to put these type of codes that begin /c?
and i quote"
set_game_state{game_finished=…, player_won=…, next_level=…, can_continue=…, victorious_force=…}
Set scenario state.
Parameters
Table with the following fields:
game_finished :: boolean
player_won :: boolean
next_level :: string
can_continue :: boolean
victorious_force :: ForceSpecification"
which will be
Code: Select all
/c
game.set_game_state {
game_finished = true,
player_won = true,
can_continue = true,
victorious_force = game.forces.player,
}
an example or a mod if you will that used the same process of making what i'm after will be nice.
Last edited by Suf on Sat Mar 27, 2021 2:59 pm, edited 1 time in total.
Re: Adding/Replacing The Win Condition Other Than Launching the first Rocket
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?Suf wrote: ↑Sat Mar 27, 2021 12:44 pmTyping it as this results in errorCode: Select all
/c game.set_game_state { game_finished = true, player_won = true, can_continue = true, victorious_force = game.forces.player, }
Use that in control.lua: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
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)
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" }
})
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:can i add a timer for that event to happen,
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)
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
Re: Adding/Replacing The Win Condition Other Than Launching the first Rocket
I really appreciate the detailed answer,now i know how to deal with these type of codes; thanks againPi-C wrote: ↑Sat Mar 27, 2021 2:58 pmTyping 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?Suf wrote: ↑Sat Mar 27, 2021 12:44 pmTyping it as this results in errorCode: Select all
/c game.set_game_state { game_finished = true, player_won = true, can_continue = true, victorious_force = game.forces.player, }
Use that in control.lua: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 workYou can also use filters: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)
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" } })
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:can i add a timer for that event to happen,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)
Re: Adding/Replacing The Win Condition Other Than Launching the first Rocket
You're welcome! But I just noticed a copy/paste error:
Code: Select all
script.on_event(id, defines.events.on_built_entity, function(event)
Code: Select all
script.on_event(defines.events.on_built_entity, function(event)
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
Re: Adding/Replacing The Win Condition Other Than Launching the first Rocket
i tried the code in control.lua ;it worked and it showed the victory screen as well.Pi-C wrote: ↑Sat Mar 27, 2021 3:25 pmYou're welcome! But I just noticed a copy/paste error:should beCode: Select all
script.on_event(id, defines.events.on_built_entity, function(event)
Code: Select all
script.on_event(defines.events.on_built_entity, function(event)
Re: Adding/Replacing The Win Condition Other Than Launching the first Rocket
That works fine in console when I tried, but only once. Possibly the game won't show the victory screen if the map has already been won. Calling set_game_state with game_finished = false doesn't seem to reset it.Pi-C wrote: ↑Sat Mar 27, 2021 2:58 pmTyping 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?Suf wrote: ↑Sat Mar 27, 2021 12:44 pmTyping it as this results in errorCode: Select all
/c game.set_game_state { game_finished = true, player_won = true, can_continue = true, victorious_force = game.forces.player, }
Re: Adding/Replacing The Win Condition Other Than Launching the first Rocket
Turns out I made a stupid mistake. I was already wondering why I hadn't been asked to activate console commands by entering the command a second time. Well, "\c" is just a meaningless string, "/c" is the one I should have used!
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!