How to setup and play in teams with Factorio 0.13+

Find multiplayer games.
Tools/scripts to run a dedicated server.
Post Reply
User avatar
scadl
Manual Inserter
Manual Inserter
Posts: 4
Joined: Mon Jul 18, 2016 12:28 pm
Contact:

How to setup and play in teams with Factorio 0.13+

Post by scadl »

:idea: In this guide I'll try to explain some amazing command combinations, which I discovered when one of my friends asked me how to play in teams on his custom map!

Before you start doing anything, you have to know how to call Factorio in-game console, because it's only place where you will be doing all changes.

Warning, when you are using any Lua based commands, you'll possibly get some errors, even if you not messing with syntax. So, before changing anything, DO A BACKUP of you MAP. Some of changes you'll be doing are really difficult or even impossible to revert!!

To work with console commands, when you creating a Multiplayer server, you have to set "Alow commands" to "True". If you did this, or just playing\testing in single-player, press a "~" on your keyboard. From here you can write messages to other players, commands, or even parts of Lua script. You can check which commands are available for you by writing "/h" command in console, and pressing 'Enter' on you keyboard. Take a look on "/c" and it's description, because everything in this guide will be done with this command. The main goal of this command is allow you to execute parts of Lua scripts (most factorio mods wrote in Lua)

Because all the commands described in this guide, are actually small lua scripts, you have to write them in console, with '/c ' prefix, like this:

Code: Select all

/c game.player.print( game.player.force.name )
Not all described commands will answer with some response. Naturally, you will get response if 'print' keyword exists in command body.

Before doing anything, let's gather some useful info.

To find out in which team you are currently in, do:

Code: Select all

game.player.print( game.player.force.name )
To find out which teams are already existing in game, do:

Code: Select all

for F in pairs(game.forces) do game.player.print(F) end
If you didn't changed anything before, you'll get 3 teams:
  • 'player' -- default team for all new players who joins the game, including you.
  • 'enemy' -- default team for aliens, their hives, bitters, spitters etc.
  • 'neutral' -- empty team by default, but you can join it to build some infrastructure accessible for members of all teams, including currently not existing.
I have to warn you that each team isolated with it's own research progress, not just power and production systems. And each building created by the member of one team are inaccessible by the members of other teams (except 'neutral' built-in team)

So let's prepare some teams for our players.

To create a Team with name 'Team1':

Code: Select all

game.create_force('Team1')
Warning, this new team will be an enemy to all other teams including default 'player', and except 'neutral' team and all their building including turrets.

To remove team 'Team1', merge it with default team 'player':

Code: Select all

game.merge_forces('Team1', 'player')
Notice: Current versions of factorio has the chance that game will crash if there're some members existing in the merged team.

To assign a player with name 'Player1' to the team 'Team1':

Code: Select all

game.players['Player1'].force=game.forces['Team1']
To remove a player with name 'Player1' from the team 'Team1, assign him\her to the default 'player' team:

Code: Select all

game.players['Player1'].force=game.forces['player']
You can make you new team neutral to the over teams including default 'player' team, so your defence will not attack them, and their - you:

Code: Select all

game.forces['player'].set_cease_fire('Team1', true)
game.forces['Team1'].set_cease_fire('player', true)
But this action DOES NOT GRANT you access to their inventories and machines!

In this section we well talk about how to transfer some existing buildings and technologies from one team to another.

Because the transfer mechanics based on region scan, you have to determinate rectangular region in which changes will be made. To do so open the debug console, by pressing 'F4' on your keyboard, switch to the 'allways' tab, and check 'show_detailed_info' checkbox. (I also recommend you to check 'show_tile_grid' to turn on map grid, which allow you more easily understand block and chunks of the map). After checking needed options, press 'F4' again. You'll see some new info at the top left corner of game window. Take a look at the first string 'Cursor'. From first pair of braces you can get the coordinates of your cursor on the map. So, imagine a rectangle, which will cover all buildings required to transfer to another team. Put the cursor on the top left and bottom right corners of that imaginary rectangle, and write down cursor's coordinates (for my example it will be -10 -10 and 10 10, to form 20x20 rectangle)

Now we can scan which entities (players, environment, buildings, machines) are exists in the designated region:

Code: Select all

BS = game.surfaces[1].find_entities({{-10, -10}, {10, 10}}) for BD in pairs( BS ) do game.player.print( BS[BD].name ) end
If this command respond to you with names of required to transfer objects, you can do following to actually transfer them to the 'Team1':

Code: Select all

BS = game.surfaces[1].find_entities({{-10, -10}, {10, 10}}) for BD in pairs( BS ) do BS[BD].force = game.forces['Team1'] end
If you already played some time as a member of the default team 'player' and researched some technologies, and than switched to the specific team like 'Team1', you will lose all of you researches and explored map, because each team isolated with it's own research progress, not just power and production systems. First, I recommend you to finish current research of you old team, if it was 'player' team, do:

Code: Select all

game.forces['player'].research_progress = 1
, than you can list all researched technologies of you old team:

Code: Select all

TR = game.forces['player'].technologies for T in pairs( TR ) do if TR[T].researched then game.player.print(T) end end
. If you're satisfied with result, you can copy all of them to your new team, like 'Team1' with:

Code: Select all

TR = game.forces['player'].technologies for T in pairs( TR ) do if TR[T].researched then game.forces['Team1'].technologies[T].researched=true end end
In this optional section, I will tell about two not really useful but fun commands.

This command will allow you, as admin, to freely give player 'Player1' 10 iron plates:

Code: Select all

game.players['Player1'].insert({name="iron-plate", count=10})
Unfortunately, I can't say where you can get name of all items in a factorio, so I suggest that you can use English name of items, where ' ' (space) replaced with '-' (minus)

This command will allow you spawn 'Assembly machine' building, tier 1, with presetted recipe (assemble 'iron-stick') and bound to your team:

Code: Select all

game.surfaces[1].create_entity{name = "assembling-machine-1", position = {15, 3}, force=game.forces.player, recipe = "iron-stick"}
Take a look on the 'position' parameter. This is coordinates, where you building will be spawned. With this command you can also build on the water tiles.

With this command script you can create some flying text, which will be visible for several seconds to everyone who working near designated coordinates:

Code: Select all

game.surfaces[1].create_entity{name = "flying-text", position = {0, 0}, text="Fly_Text-1"}
To change my text, just replace the sting inside quotes after 'text' parameter, with yours.

That's all for now. If I discover some more, I will update this guide. So, please subscribe ;)

Lead_Hail
Manual Inserter
Manual Inserter
Posts: 3
Joined: Fri Jan 28, 2022 2:55 am
Contact:

Re: How to setup and play in teams with Factorio 0.13+

Post by Lead_Hail »

I know this is old and I'll get yelled at, but what all needs to be done to follow this in the current version?

SoShootMe
Filter Inserter
Filter Inserter
Posts: 476
Joined: Mon Aug 03, 2020 4:16 pm
Contact:

Re: How to setup and play in teams with Factorio 0.13+

Post by SoShootMe »

The short answer is that, at least in general, the original post is still valid.

There is the PvP scenario described in the Wiki but this is only applicable to a new save. Some force-related commands that can be used with an existing save, covering most of the first set of commands in the original post, are also described.

Most of the rest are covered by, or are a variation on things covered by, the Console page in the Wiki.

Post Reply

Return to “Multiplayer / Dedicated Server”