Last active
September 17, 2025 03:25
-
-
Save glektarssza/0fde16f978ebca191b836a3dfe195b3d to your computer and use it in GitHub Desktop.
Factorio - Warp Drive Machine Helper Scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Some constants | |
| local re = "${(%w+)}" | |
| local color_fmt = "[color=${c}]${v}[/color]" | |
| local player = game.player | |
| local printing_entity = player | |
| --- @type PrintSettings | |
| local print_settings = { | |
| sound = defines.print_sound.never, | |
| skip = defines.print_skip.never, | |
| game_state = false, | |
| volume_modifier = 0 | |
| } | |
| -- Some local stuff | |
| local force = player ~= nil and player.force or game.forces["player"] | |
| local surface = player ~= nil and player.physical_surface or nil | |
| local current_planet = remote.call("WDM", "get_ship_planet_info", force.name) | |
| local previous_planet = remote.call("WDM", "get_ship_previous_planet_info", force.name) | |
| -- Some helpers | |
| --- Format a message to display to the player. | |
| --- comment | |
| --- @param message string The formatting string. | |
| --- @param data table<string, unknown> The data to inject into the message. | |
| --- @param colors? table<string, unknown> The colors to format each | |
| --- [data](lua://data) field with. | |
| --- @return string message A string message that can be sent to the player. | |
| local function format_message(message, data, colors) | |
| local local_colors = colors ~= nil and colors or { | |
| default = "#ffffff" | |
| } | |
| if local_colors["default"] == nil then | |
| local_colors["default"] = "#ffffff" | |
| end | |
| local m = string.gsub(message, re, function(data_key) | |
| local r = string.gsub(color_fmt, re, function(color_fmt_key) | |
| if color_fmt_key == "v" and data[data_key] ~= nil then | |
| if type(data[data_key]) == "function" then | |
| local _, pcall_r = pcall(data[data_key]) | |
| return tostring(pcall_r) | |
| else | |
| return tostring(data[data_key]) | |
| end | |
| elseif color_fmt_key == "c" and (local_colors[data_key] ~= nil or local_colors["default"] ~= nil) then | |
| return local_colors[data_key] or local_colors["default"] | |
| end | |
| return nil | |
| end) | |
| if r == color_fmt then | |
| return nil | |
| end | |
| return r | |
| end) | |
| return m | |
| end | |
| --- Format a message to display to the player. | |
| --- comment | |
| --- @param message string The formatting string. | |
| --- @param data table<string, unknown> The data to inject into the message. | |
| --- @param colors? table<string, unknown> The colors to format each | |
| --- [data](lua://data) field with. | |
| --- @param print_settings PrintSettings The settings to print with. | |
| local function print_message(printer, message, data, colors, print_settings) | |
| if player == nil then | |
| error("Could not find the player!") | |
| end | |
| printer.print(format_message(message, data, colors), print_settings) | |
| end | |
| -- Check the global settings | |
| print_message( | |
| printing_entity, | |
| "[color=#af87ff]Is ${param} globally enabled? ${value}[/color]", | |
| { | |
| param = "enemy evolution", | |
| value = game.map_settings.enemy_evolution.enabled | |
| }, | |
| { | |
| param = "#87d7ff", | |
| value = "#ffaf00" | |
| }, | |
| print_settings) | |
| print_message( | |
| printing_entity, | |
| "[color=#af87ff]Is ${param} globally enabled? ${value}[/color]", | |
| { | |
| param = "enemy expansion", | |
| value = game.map_settings.enemy_expansion.enabled | |
| }, | |
| { | |
| param = "#87d7ff", | |
| value = "#ffaf00" | |
| }, | |
| print_settings) | |
| print_message( | |
| printing_entity, | |
| "[color=#af87ff]Is ${param} globally enabled? ${value}[/color]", | |
| { | |
| param = "pollution", | |
| value = game.map_settings.pollution.enabled | |
| }, | |
| { | |
| param = "#87d7ff", | |
| value = "#ffaf00" | |
| }, | |
| print_settings) | |
| print_message( | |
| printing_entity, | |
| "[color=#af87ff]Is ${param} globally enabled? ${value}[/color]", | |
| { | |
| param = "peaceful mode", | |
| value = game.default_map_gen_settings.peaceful_mode | |
| }, | |
| { | |
| param = "#87d7ff", | |
| value = "#ffaf00" | |
| }, | |
| print_settings) | |
| print_message( | |
| printing_entity, | |
| "[color=#af87ff]Is ${param} globally enabled? ${value}[/color]", | |
| { | |
| param = "no enemies mode", | |
| value = game.default_map_gen_settings.no_enemies_mode | |
| }, | |
| { | |
| param = "#87d7ff", | |
| value = "#ffaf00" | |
| }, | |
| print_settings) | |
| -- Check the current surface settings | |
| if current_planet ~= nil then | |
| print_message( | |
| printing_entity, | |
| "[color=#af87ff]Current planet name: ${name}[/color]", | |
| { | |
| name = function() | |
| if current_planet ~= nil and current_planet.name ~= nil then | |
| return tostring(current_planet.name) | |
| else | |
| return "unknown" | |
| end | |
| end | |
| }, | |
| { | |
| name = "#ffaf00" | |
| }, | |
| print_settings) | |
| print_message( | |
| printing_entity, | |
| "[color=#af87ff]Is ${param} enabled on current surface? ${value}[/color]", | |
| { | |
| param = "peaceful mode", | |
| value = function() | |
| if surface ~= nil then | |
| return tostring(surface.peaceful_mode) | |
| else | |
| return "unknown" | |
| end | |
| end | |
| }, | |
| { | |
| param = "#87d7ff", | |
| value = "#ffaf00" | |
| }, | |
| print_settings) | |
| print_message( | |
| printing_entity, | |
| "[color=#af87ff]Is ${param} enabled on current surface map generation settings? ${value}[/color]", | |
| { | |
| param = "peaceful mode", | |
| value = function() | |
| if surface ~= nil and surface.map_gen_settings ~= nil and surface.map_gen_settings.peaceful_mode ~= nil then | |
| return tostring(surface.map_gen_settings.peaceful_mode) | |
| else | |
| return "unknown" | |
| end | |
| end | |
| }, | |
| { | |
| param = "#87d7ff", | |
| value = "#ffaf00" | |
| }, | |
| print_settings) | |
| print_message( | |
| printing_entity, | |
| "[color=#af87ff]Is ${param} enabled on current surface? ${value}[/color]", | |
| { | |
| param = "no enemies mode", | |
| value = function() | |
| if surface ~= nil then | |
| return tostring(surface.no_enemies_mode) | |
| else | |
| return "unknown" | |
| end | |
| end | |
| }, | |
| { | |
| param = "#87d7ff", | |
| value = "#ffaf00" | |
| }, | |
| print_settings) | |
| print_message( | |
| printing_entity, | |
| "[color=#af87ff]Is ${param} enabled on current surface map generation settings? ${value}[/color]", | |
| { | |
| param = "no enemies mode", | |
| value = function() | |
| if surface ~= nil and surface.map_gen_settings ~= nil and surface.map_gen_settings.no_enemies_mode ~= nil then | |
| return tostring(surface.map_gen_settings.no_enemies_mode) | |
| else | |
| return "unknown" | |
| end | |
| end | |
| }, | |
| { | |
| param = "#87d7ff", | |
| value = "#ffaf00" | |
| }, | |
| print_settings) | |
| end | |
| -- Check the last planet settings | |
| if previous_planet ~= nil and (previous_planet.planet_number ~= nil or previous_planet.base_planet ~= nil) and current_planet ~= nil and (current_planet.planet_number ~= nil or current_planet.planet_number ~= nil) and ((previous_planet.planet_number ~= nil and current_planet.planet_number ~= nil and previous_planet.planet_number ~= current_planet.planet_number) or (previous_planet.base_planet ~= nil and current_planet.base_planet ~= nil and previous_planet.base_planet ~= current_planet.base_planet) or previous_planet.base_planet ~= nil and current_planet.base_planet == nil or previous_planet.base_planet == nil and current_planet.base_planet ~= nil) then | |
| print_message( | |
| printing_entity, | |
| "[color=#af87ff]Previous planet name: ${name}[/color]", | |
| { | |
| name = function() | |
| if previous_planet ~= nil and previous_planet.name ~= nil then | |
| return tostring(previous_planet.name) | |
| else | |
| return "unknown" | |
| end | |
| end | |
| }, | |
| { | |
| name = "#ffaf00" | |
| }, | |
| print_settings) | |
| print_message( | |
| printing_entity, | |
| "[color=#af87ff]Is ${param} enabled on previous planet? ${value}[/color]", | |
| { | |
| param = "peaceful mode", | |
| value = function() | |
| if previous_planet ~= nil and previous_planet.mgs ~= nil and previous_planet.mgs.peaceful_mode ~= nil then | |
| return tostring(previous_planet.mgs.peaceful_mode) | |
| elseif previous_planet ~= nil and previous_planet ~= nil and previous_planet.peaceful_mode ~= nil then | |
| return tostring(previous_planet.peaceful_mode) | |
| end | |
| return "unknown" | |
| end | |
| }, | |
| { | |
| param = "#87d7ff", | |
| value = "#ffaf00" | |
| }, | |
| print_settings) | |
| print_message( | |
| printing_entity, | |
| "[color=#af87ff]Is ${param} enabled on previous surface? ${value}[/color]", | |
| { | |
| param = "no enemies mode", | |
| value = function() | |
| if previous_planet ~= nil and previous_planet.mgs ~= nil and previous_planet.mgs.no_enemies_mode ~= nil then | |
| return tostring(previous_planet.mgs.no_enemies_mode) | |
| elseif previous_planet ~= nil and previous_planet ~= nil and previous_planet.no_enemies_mode ~= nil then | |
| return tostring(previous_planet.no_enemies_mode) | |
| end | |
| return "unknown" | |
| end | |
| }, | |
| { | |
| param = "#87d7ff", | |
| value = "#ffaf00" | |
| }, | |
| print_settings) | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Some constants | |
| local re = "${(%w+)}" | |
| local color_fmt = "[color=${c}]${v}[/color]" | |
| local player = game.player | |
| local printing_entity = player | |
| --- @type PrintSettings | |
| local print_settings = { | |
| sound = defines.print_sound.never, | |
| skip = defines.print_skip.never, | |
| game_state = false, | |
| volume_modifier = 0 | |
| } | |
| -- Some local stuff | |
| local force = player ~= nil and player.force or game.forces["player"] | |
| local surface = player ~= nil and player.physical_surface or nil | |
| local current_planet = remote.call("WDM", "get_ship_planet_info", force.name) | |
| local previous_planet = remote.call("WDM", "get_ship_previous_planet_info", force.name) | |
| --- Format a message to display to the player. | |
| --- comment | |
| --- @param message string The formatting string. | |
| --- @param data table<string, unknown> The data to inject into the message. | |
| --- @param colors? table<string, unknown> The colors to format each | |
| --- [data](lua://data) field with. | |
| --- @return string message A string message that can be sent to the player. | |
| local function format_message(message, data, colors) | |
| local local_colors = colors ~= nil and colors or { | |
| default = "#ffffff" | |
| } | |
| if local_colors["default"] == nil then | |
| local_colors["default"] = "#ffffff" | |
| end | |
| local m = string.gsub(message, re, function(data_key) | |
| local r = string.gsub(color_fmt, re, function(color_fmt_key) | |
| if color_fmt_key == "v" and data[data_key] ~= nil then | |
| if type(data[data_key]) == "function" then | |
| local _, pcall_r = pcall(data[data_key]) | |
| return tostring(pcall_r) | |
| else | |
| return tostring(data[data_key]) | |
| end | |
| elseif color_fmt_key == "c" and (local_colors[data_key] ~= nil or local_colors["default"] ~= nil) then | |
| return local_colors[data_key] or local_colors["default"] | |
| end | |
| return nil | |
| end) | |
| if r == color_fmt then | |
| return nil | |
| end | |
| return r | |
| end) | |
| return m | |
| end | |
| --- Format a message to display to the player. | |
| --- comment | |
| --- @param message string The formatting string. | |
| --- @param data table<string, unknown> The data to inject into the message. | |
| --- @param colors? table<string, unknown> The colors to format each | |
| --- [data](lua://data) field with. | |
| --- @param print_settings PrintSettings The settings to print with. | |
| local function print_message(printer, message, data, colors, print_settings) | |
| if player == nil then | |
| error("Could not find the player!") | |
| end | |
| printer.print(format_message(message, data, colors), print_settings) | |
| end | |
| -- Desired new values | |
| local enemy_evolution = true | |
| local enemy_expansion = false | |
| local pollution = false | |
| local peaceful_mode = true | |
| local no_enemies_mode = false | |
| -- Change the global settings | |
| game.map_settings.enemy_evolution.enabled = enemy_evolution | |
| print_message( | |
| printing_entity, | |
| "[color=#af87ff]${param} globally enabled is now \"${value}\"[/color]", | |
| { | |
| param = "Enemy evolution", | |
| value = game.map_settings.enemy_evolution.enabled | |
| }, | |
| { | |
| param = "#87d7ff", | |
| value = "#ffaf00" | |
| }, | |
| print_settings) | |
| game.map_settings.enemy_expansion.enabled = enemy_expansion | |
| print_message( | |
| printing_entity, | |
| "[color=#af87ff]${param} globally enabled is now \"${value}\"[/color]", | |
| { | |
| param = "Enemy expansion", | |
| value = game.map_settings.enemy_expansion.enabled | |
| }, | |
| { | |
| param = "#87d7ff", | |
| value = "#ffaf00" | |
| }, | |
| print_settings) | |
| game.map_settings.pollution.enabled = pollution | |
| for _, s in pairs(game.surfaces) do | |
| s.clear_pollution() | |
| end | |
| print_message( | |
| printing_entity, | |
| "[color=#af87ff]${param} globally enabled is now \"${value}\"[/color]", | |
| { | |
| param = "Pollution", | |
| value = game.map_settings.pollution.enabled | |
| }, | |
| { | |
| param = "#87d7ff", | |
| value = "#ffaf00" | |
| }, | |
| print_settings) | |
| game.default_map_gen_settings.peaceful_mode = peaceful_mode | |
| print_message( | |
| printing_entity, | |
| "[color=#af87ff]${param} globally enabled is now \"${value}\"[/color]", | |
| { | |
| param = "Peaceful mode", | |
| value = game.default_map_gen_settings.peaceful_mode | |
| }, | |
| { | |
| param = "#87d7ff", | |
| value = "#ffaf00" | |
| }, | |
| print_settings) | |
| print_message( | |
| printing_entity, | |
| "[color=#af87ff]${param} globally enabled is now \"${value}\"[/color]", | |
| { | |
| param = "No enemies mode", | |
| value = game.default_map_gen_settings.no_enemies_mode | |
| }, | |
| { | |
| param = "#87d7ff", | |
| value = "#ffaf00" | |
| }, | |
| print_settings) | |
| -- Update the current surface settings | |
| print_message( | |
| printing_entity, | |
| "[color=#af87ff]Current planet name: ${name}[/color]", | |
| { | |
| name = current_planet ~= nil and current_planet.name ~= nil and current_planet.name or "unknown" | |
| }, | |
| { | |
| name = "#ffaf00" | |
| }, | |
| print_settings) | |
| if surface ~= nil then | |
| surface.peaceful_mode = peaceful_mode | |
| print_message( | |
| printing_entity, | |
| "[color=#af87ff]${param} enabled on current surface is now \"${value}\"[/color]", | |
| { | |
| param = "Peaceful mode", | |
| value = function() | |
| if surface ~= nil and surface.peaceful_mode ~= nil then | |
| return tostring(surface.peaceful_mode) | |
| else | |
| return "unknown" | |
| end | |
| end | |
| }, | |
| { | |
| param = "#87d7ff", | |
| value = "#ffaf00" | |
| }, | |
| print_settings) | |
| surface.map_gen_settings.peaceful_mode = peaceful_mode | |
| if surface.planet ~= nil then | |
| surface.planet.prototype.map_gen_settings.peaceful_mode = peaceful_mode | |
| end | |
| print_message( | |
| printing_entity, | |
| "[color=#af87ff]Is ${param} enabled on current surface map generation settings is now \"${value}\"[/color]", | |
| { | |
| param = "peaceful mode", | |
| value = function() | |
| if surface ~= nil and surface.map_gen_settings.peaceful_mode ~= nil then | |
| return tostring(surface.map_gen_settings.peaceful_mode) | |
| else | |
| return "unknown" | |
| end | |
| end | |
| }, | |
| { | |
| param = "#87d7ff", | |
| value = "#ffaf00" | |
| }, | |
| print_settings) | |
| surface.no_enemies_mode = no_enemies_mode | |
| print_message( | |
| printing_entity, | |
| "[color=#af87ff]${param} enabled on current surface is now \"${value}\"[/color]", | |
| { | |
| param = "No enemies mode", | |
| value = function() | |
| if surface ~= nil and surface.no_enemies_mode ~= nil then | |
| return tostring(surface.no_enemies_mode) | |
| else | |
| return "unknown" | |
| end | |
| end | |
| }, | |
| { | |
| param = "#87d7ff", | |
| value = "#ffaf00" | |
| }, | |
| print_settings) | |
| surface.map_gen_settings.no_enemies_mode = no_enemies_mode | |
| if surface.planet ~= nil then | |
| surface.planet.prototype.map_gen_settings.no_enemies_mode = no_enemies_mode | |
| end | |
| print_message( | |
| printing_entity, | |
| "[color=#af87ff]${param} enabled on current surface map generation settings is now \"${value}\"[/color]", | |
| { | |
| param = "No enemies mode", | |
| value = function() | |
| if surface ~= nil and surface.map_gen_settings ~= nil and surface.map_gen_settings.no_enemies_mode ~= nil then | |
| return tostring(surface.map_gen_settings.no_enemies_mode) | |
| else | |
| return "unknown" | |
| end | |
| end | |
| }, | |
| { | |
| param = "#87d7ff", | |
| value = "#ffaf00" | |
| }, | |
| print_settings) | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment