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

Console: Difference between revisions

From Official Factorio Wiki
Jump to navigation Jump to search
(Removed stub template. Reworked the intro paragraph.)
Line 87: Line 87:
  /c game.local_player.print(game.evolution_factor)
  /c game.local_player.print(game.evolution_factor)


=== Disable evolution & increases pollution evolution ===
=== Disable time-based evolution & increases pollution-based evolution ===
[http://www.factorioforums.com/forum/viewtopic.php?f=34&t=10159 Disable evolution, increases pollution evolution instead] (forums)
  /c game.map_settings.enemy_evolution.time_factor = 0
  /c game.mapsettings.enemy_evolution.time_factor = 0.000008 * 0
  /c game.map_settings.enemy_evolution.pollution_factor = game.map_settings.enemy_evolution.pollution_factor * 2
  /c game.mapsettings.enemy_evolution.pollution_factor = 0.00003 * 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 ===
=== Kill all biters on the "enemy" force ===

Revision as of 03:42, 15 June 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.local_player.print(1234 * 5678)

Mine faster

/c game.local_player.force.manual_mining_speed_modifier=1000

Craft faster

/c game.local_player.force.manual_crafting_speed_modifier=1000

Zoom beyond normal bounds

/c game.local_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.local_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.local_player.print(game.local_player.selected.get_liquid().amount)

Inventory Manipulation

Refill resources (refill oil, iron etc.)

While holding the cursor over a resource in-game

/c game.local_player.selected.amount=7500

Add 100 iron plates to your inventory

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

World Manipulation

Turn off night

/c game.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.local_player.surface;
for y=-2,2 do
 for x=-2,2 do
  surface.create_entity({name="stone", amount=5000, position={game.local_player.position.x+x, game.local_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.local_player.surface.find_entities_filtered{
       area={{game.local_player.position.x-32, game.local_player.position.y-32},
           {game.local_player.position.x+32, game.local_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.local_player.force.chart(game.local_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.local_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.local_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.local_player.character = game.local_player.surface.create_entity{name="player", position = {0,0}, force = game.forces.player}

Change Player color

Player color (forums)

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

Research

Enable faster research

/c game.local_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.local_player.force.technologies['electric-energy-distribution-1'].researched=true
/c game.local_player.force.technologies['steel-processing'].researched=true

Finish research immediately

/c for name,technology in pairs(game.local_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.local_player.print(game.local_player.force.get_entitycount("logistic-robot"))
/c game.local_player.print(game.local_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.local_player.color = {g=1,b=1,r=1,a=.9}

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

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

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