Adding/Replacing The Win Condition Other Than Launching the first Rocket

Place to get help with not working mods / modding interface.
Post Reply
Suf
Long Handed Inserter
Long Handed Inserter
Posts: 76
Joined: Fri Jul 10, 2020 5:07 am
Contact:

Adding/Replacing The Win Condition Other Than Launching the first Rocket

Post by Suf »

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.

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3700
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Adding/Replacing The Win Condition Other Than Launching the first Rocket

Post by DaveMcW »

Code: Select all

/c
game.set_game_state { 
  game_finished = true,
  player_won = true,
  can_continue = true,
  victorious_force = game.forces.player,
}

Suf
Long Handed Inserter
Long Handed Inserter
Posts: 76
Joined: Fri Jul 10, 2020 5:07 am
Contact:

Re: Adding/Replacing The Win Condition Other Than Launching the first Rocket

Post by Suf »

DaveMcW wrote:
Mon Mar 22, 2021 8:07 pm

Code: Select all

/c
game.set_game_state { 
  game_finished = true,
  player_won = true,
  can_continue = true,
  victorious_force = game.forces.player,
}
So this code isn't bound to any prototype?good to know and thanks for the help :D

Suf
Long Handed Inserter
Long Handed Inserter
Posts: 76
Joined: Fri Jul 10, 2020 5:07 am
Contact:

Re: Adding/Replacing The Win Condition Other Than Launching the first Rocket

Post by Suf »

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
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.


Suf
Long Handed Inserter
Long Handed Inserter
Posts: 76
Joined: Fri Jul 10, 2020 5:07 am
Contact:

Re: Adding/Replacing The Win Condition Other Than Launching the first Rocket

Post by Suf »

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,
}
and as i mentioned that resulted in error because i put it in the entity.lua file because i'm thinking that's how it works based on the example i mentioned in my replay above, if not then how exactly
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.

Pi-C
Smart Inserter
Smart Inserter
Posts: 1645
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Adding/Replacing The Win Condition Other Than Launching the first Rocket

Post by Pi-C »

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)
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

Suf
Long Handed Inserter
Long Handed Inserter
Posts: 76
Joined: Fri Jul 10, 2020 5:07 am
Contact:

Re: Adding/Replacing The Win Condition Other Than Launching the first Rocket

Post by Suf »

Pi-C wrote:
Sat Mar 27, 2021 2:58 pm
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)
I really appreciate the detailed answer,now i know how to deal with these type of codes; thanks again :)

Pi-C
Smart Inserter
Smart Inserter
Posts: 1645
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Adding/Replacing The Win Condition Other Than Launching the first Rocket

Post by Pi-C »

Suf wrote:
Sat Mar 27, 2021 3:15 pm
I really appreciate the detailed answer,now i know how to deal with these type of codes; thanks again :)
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)
should be

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!

Suf
Long Handed Inserter
Long Handed Inserter
Posts: 76
Joined: Fri Jul 10, 2020 5:07 am
Contact:

Re: Adding/Replacing The Win Condition Other Than Launching the first Rocket

Post by Suf »

Pi-C wrote:
Sat Mar 27, 2021 3:25 pm
Suf wrote:
Sat Mar 27, 2021 3:15 pm
I really appreciate the detailed answer,now i know how to deal with these type of codes; thanks again :)
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)
should be

Code: Select all

script.on_event(defines.events.on_built_entity, function(event)
i tried the code in control.lua ;it worked and it showed the victory screen as well.

User avatar
Silari
Filter Inserter
Filter Inserter
Posts: 489
Joined: Sat Jan 27, 2018 10:04 pm
Contact:

Re: Adding/Replacing The Win Condition Other Than Launching the first Rocket

Post by Silari »

Pi-C wrote:
Sat Mar 27, 2021 2:58 pm
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?
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
Smart Inserter
Smart Inserter
Posts: 1645
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Adding/Replacing The Win Condition Other Than Launching the first Rocket

Post by Pi-C »

Silari wrote:
Sat Mar 27, 2021 8:10 pm
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.
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! :oops:
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

Post Reply

Return to “Modding help”