1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2024-12-12 10:04:40 +02:00

Add action warnings

This commit is contained in:
Matthew Heguy 2019-01-23 15:27:31 -05:00
parent 54d30216d1
commit 2ce35ada6a
2 changed files with 32 additions and 3 deletions

View File

@ -38,7 +38,7 @@ local function on_player_deconstructed_area(event)
player.remove_item({name = 'deconstruction-planner', count = 1000}) player.remove_item({name = 'deconstruction-planner', count = 1000})
--Make them think they arent noticed --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( player.print(
'Only regulars can mark things for deconstruction, if you want to deconstruct something you may ask an admin to promote you.' 'Only regulars can mark things for deconstruction, if you want to deconstruct something you may ask an admin to promote you.'
) )

View File

@ -3,6 +3,7 @@
-- Dependencies -- Dependencies
local Game = require 'utils.game' local Game = require 'utils.game'
local Color = require 'resources.color_presets' local Color = require 'resources.color_presets'
local Server = require 'features.server'
-- localized functions -- localized functions
local random = math.random local random = math.random
@ -25,10 +26,17 @@ function Module.distance(pos1, pos2)
end end
--- Takes msg and prints it to all players except provided player --- Takes msg and prints it to all players except provided player
function Module.print_except(msg, player) -- @param msg <string> The message to print
-- @param color <table> the color to use for the message
-- @param player <LuaPlayer> 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 for _, p in pairs(game.connected_players) do
if p ~= player then if p ~= player then
p.print(msg) p.print(msg, color)
end end
end end
end end
@ -187,6 +195,27 @@ function Module.set_and_return(tbl, key, value)
return value return value
end end
--- Takes msg and prints it to all players. Also prints to the log and discord
-- @param msg <string> The message to print
-- @param warning_prefix <string> 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 <string> The message to print
-- @param warning_prefix <string> The name of the module/warning
-- @param player <LuaPlayer> 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 -- add utility functions that exist in base factorio/util
require 'util' require 'util'