In other languages: Deutsch 日本語 한국어 Русский 中文

Console: Difference between revisions

From Official Factorio Wiki
Jump to navigation Jump to search
No edit summary
Line 33: Line 33:
== Enable Loader ==
== Enable Loader ==
  /c game.player.force.recipes["loader"].enabled = true
  /c game.player.force.recipes["loader"].enabled = true
/c game.player.force.recipes["fast-loader"].enabled = true
/c game.player.force.recipes["express-loader"].enabled = true


== Zoom beyond normal bounds ==
== Zoom beyond normal bounds ==

Revision as of 12:51, 20 July 2016

Console Overview

The Factorio console is the built in interface for executing Lua commands within Factorio. It works similarly to any command line interface or the JavaScript console for your browser.

You can essentially fire any command here, just as you would from a Lua program - Factorio Mods are merely Lua commands. Therefore you don't necessarily need "cheats" per-se, as the console allows you full access to the game's internals. You only need a familiarity with the commands and types, as shown in the below examples and the Modding section.

Using the console

Opening the console

With default key bindings, the console is opened with the '/' or '~' keys. Like most others, this key binding may be customized within the Options Menu->Keyboard>"Toggle Lua console".

Inputting commands

The console is also the chat window in multiplayer. You need to type '/c' in front of your commands, otherwise it is just a chat message! The console has an inbuilt history. You can use the "cursor-up"-key to repeat or quickly edit and re-issue previous commands.

The game ignores newlines when pasting "scriptlets" in the console. This means they can be written in a human readable form in an editor and copy/pasted into the console, making understanding and editing a bit easier.

On the other hand, if you want to type several commands in one line you just need to put ';' (semicolon) between the commands - see examples below.

Example"cheat" commands

Information for additional commands may be found in the modding-section

Use it as calculator

(see Inputting Commands: you can repeat a prior command with the "cursor up"-key!)

/c game.player.print(1234 * 5678)

Mine faster

/c game.player.force.manual_mining_speed_modifier=1000

Craft faster

/c game.player.force.manual_crafting_speed_modifier=1000

Enable Loader

/c game.player.force.recipes["loader"].enabled = true
/c game.player.force.recipes["fast-loader"].enabled = true
/c game.player.force.recipes["express-loader"].enabled = true

Zoom beyond normal bounds

/c game.player.zoom = 0.1

Use print() instead of game.local_player.print()

Use print() instead of game.local_player.print() (forums)

/c print = function(text) game.player.print(text) end

Check water level in a pipe

Check water level in a pipe (forums) Hold cursor over the target pipe and execute:

/c game.player.print(game.player.selected.fluidbox[1].amount)

Inventory Manipulation

Refill resources (refill oil, iron etc.)

While holding the cursor over a resource in-game

/c game.player.selected.amount=7500

Add 100 iron plates to your inventory

/c game.player.insert{name="iron-plate", count=100}

World Manipulation

Turn off night

/c game.surfaces[1].always_day=true

Add new resource patch

This creates a new 5x5 patch of resources, centered on the player character. For resources other than stone, just change "stone" to "iron-ore", "copper-ore", or "coal"

/c local surface = game.player.surface;
for y=-2,2 do
 for x=-2,2 do
  surface.create_entity({name="stone", amount=5000, position={game.player.position.x+x, game.player.position.y+y}})
 end
end

Destroy rocks in sandbox-mode

Destroy rocks in sandbox-mode (forums) - you don't have a player here, so you can't destroy anything.

 /c for _,entity in pairs(game.player.surface.find_entities_filtered{
       area={{game.player.position.x-32, game.player.position.y-32},
           {game.player.position.x+32, game.player.position.y+32}},
           name="stone-rock"})
 do
   entity.destroy()
 end

you need to center the rock in your vision range


Generate a section of the world and explore it at the same time

Generate a section of the world and explore it at the same time (forums)

/c game.player.force.chart(game.player.surface,{lefttop = {x = -1024, y = -1024}, rightbottom = {x = 1024, y = 1024}})

Simply change the bounding box to the size you want and it will generate the map and explore it in that area. Keep In mind that command is telling Factorio to generate 64*64 (4096) chunks so it's going to take a while before all the background entity generation (trees, resources, biters) are placed in the world.

Enemy/Evolution

Check how far the biters have evolved

/c game.player.print(game.evolution_factor)

Disable time-based evolution & increases pollution-based evolution

/c game.map_settings.enemy_evolution.time_factor = 0
/c game.map_settings.enemy_evolution.pollution_factor = game.map_settings.enemy_evolution.pollution_factor * 2

The "2" at the end of the last command will double the default pollution factor. You can substitute another number to increase (or decrease) the pollution factor further.

Kill all biters on the "enemy" force

/c game.forces["enemy"].kill_all_units()

Remove all enemies from the map

   /c local surface = game.player.surface
   for c in surface.get_chunks() do
       for key, entity in pairs(surface.find_entities_filtered({area={{c.x * 32, c.y * 32}, {c.x * 32 + 32, c.y * 32 + 32}}, force= "enemy"})) do
           entity.destroy()
       end
   end

Enable peaceful mode

Switching on peaceful mode (forums)

/c game.peaceful_mode = true
/c game.forces["enemy"].kill_all_units()

Player Character

Spawn a player character

Custom Scenario: How to spawn a character at a certain point (instead of being in god-mode (forums)

/c game.player.character = game.player.surface.create_entity{name="player", position = {0,0}, force = game.forces.player}

Change Player color

Player color (forums)

/c game.player.color={r=200,g=50,b=200,a=.9}

Research

Enable faster research

/c game.player.force.laboratory_speed_modifier = 1

1 is normal speed, 2 is double speed 3 is triple etc. I think it goes up to 100.

Enabling specific technologies

Enabling technologies (forums)

/c game.player.force.technologies['electric-energy-distribution-1'].researched=true
/c game.player.force.technologies['steel-processing'].researched=true

Finish research immediately

/c for name,technology in pairs(game.player.force.technologies) do technology.researched=technology.enabled end

Get robot count within network

Where can I see how many Robots are in my network? (forums)

Note that these are no longer needed because the roboport now provides accurate robot counts.

Count all active robots

/c game.player.print(game.player.force.get_entitycount("logistic-robot"))
/c game.player.print(game.player.force.get_entitycount("construction-robot"))

Count all active and inactive robots in the network, but misses the ones flying over gaps in coverage

   /c robots = {};
   roboports = {};
   logistic = 0;
   construction = 0;
   recurse = function(r)
      id = r.position.x .. "," .. r.position.y;
      if (roboports[id] or r.force.name ~= game.player.force.name) then return end;
      roboports[id] = true;
      logistic = logistic + r.getinventory(1).getitemcount("logistic-robot");
      construction = construction + r.getinventory(1).getitemcount("construction-robot");
      ids = {};
      for _, robot in ipairs(game.findentitiesfiltered{area={{r.position.x-50, r.position.y-50}, {r.position.x+50, r.position.y+50}}, name="construction-robot"}) do;
         id = robot.position.x .. "," .. robot.position.y;
         if ((ids[id] or not robots[id]) and robot.force.name == game.player.force.name) then;
            construction = construction + 1;
            ids[id] = true;
            robots[id] = true;
         end;
      end;
      for _, robot in ipairs(game.findentitiesfiltered{area={{r.position.x-50, r.position.y-50}, {r.position.x+50, r.position.y+50}}, name="logistic-robot"}) do;
         id = robot.position.x .. "," .. robot.position.y;
         if ((ids[id] or not robots[id]) and robot.force.name == game.player.force.name) then;
            logistic = logistic + 1;
            ids[id] = true;
            robots[id] = true;
         end;
      end;
      for _, roboport in ipairs(game.findentitiesfiltered{area={{r.position.x-48.5, r.position.y-48.5}, {r.position.x+48.5, r.position.y+48.5}}, name="roboport"}) do;
         recurse(roboport);
      end;
   end;
   p = game.player.character.position;
   roboport = game.findentitiesfiltered{area={{p.x-48.5, p.y-48.5}, {p.x+48.5, p.y+48.5}}, name="roboport"}[1];
   if (roboport) then;
      recurse(roboport);
      game.player.print("Robots in network: Construction:" .. construction .. " Logistic:" .. logistic);
   else;
      game.player.print("Not in range of a roboport.");
   end

See also

Some interesting cheats or useful commands and tips.
# Preface all console commands with /c in .11.0+

# Set player to white
game.player.color = {g=1,b=1,r=1,a=.9}

# remove old player
game.remove_offline_player("username")

# Technology and Recipe unlocking
game.player.force.reset_technologies()
game.player.force.reset_recipes()
game.player.force.enable_all_technologies() # does not research them (see below)
game.player.force.enable_all_recipes()
game.player.force.research_all_technologies()
game.player.force.technologies["technology-name"].researched = true

# cheating
game.player.force.manual_mining_speed_modifier = 200
game.player.force.manual_crafting_speed_modifier = 200
game.speed = 2
game.freeze_day_time()
game.surfaces[1].always_day = true
game.surfaces[1].peaceful_mode = true
game.player.insert{name="item-name", count=1}