diff --git a/features/nuke_control.lua b/features/nuke_control.lua index 2d95ad9c..a32dfb5d 100644 --- a/features/nuke_control.lua +++ b/features/nuke_control.lua @@ -38,7 +38,7 @@ local function on_player_deconstructed_area(event) player.remove_item({name = 'deconstruction-planner', count = 1000}) --Make them think they arent noticed - Utils.print_except(player.name .. ' tried to deconstruct something, but instead deconstructed themself.', player) + Utils.print_except(player.name .. ' tried to deconstruct something, but instead deconstructed themself.', nil, player) player.print( 'Only regulars can mark things for deconstruction, if you want to deconstruct something you may ask an admin to promote you.' ) diff --git a/utils/core.lua b/utils/core.lua index eaff9f57..0b9cf267 100644 --- a/utils/core.lua +++ b/utils/core.lua @@ -3,6 +3,7 @@ -- Dependencies local Game = require 'utils.game' local Color = require 'resources.color_presets' +local Server = require 'features.server' -- localized functions local random = math.random @@ -25,10 +26,17 @@ function Module.distance(pos1, pos2) end --- Takes msg and prints it to all players except provided player -function Module.print_except(msg, player) +-- @param msg The message to print +-- @param color the color to use for the message +-- @param player the player not to send the message to +function Module.print_except(msg, color, player) + if not color then + color = Color.white + end + for _, p in pairs(game.connected_players) do if p ~= player then - p.print(msg) + p.print(msg, color) end end end @@ -187,6 +195,27 @@ function Module.set_and_return(tbl, key, value) return value end +--- Takes msg and prints it to all players. Also prints to the log and discord +-- @param msg The message to print +-- @param warning_prefix The name of the module/warning +function Module.action_warning(msg, warning_prefix) + game.print(prefix .. msg, Color.yellow) + msg = warning_prefix .. msg + log(msg) + Server.to_discord_bold(msg) +end + +--- Takes msg and prints it to all players except provided player. Also prints to the log and discord +-- @param msg The message to print +-- @param warning_prefix The name of the module/warning +-- @param player the player not to send the message to +function Module.silent_action_warning(msg, warning_prefix, player) + Module.print_except(prefix .. msg, Color.yellow, player) + msg = warning_prefix .. msg + log(msg) + Server.to_discord_bold(msg) +end + -- add utility functions that exist in base factorio/util require 'util'