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

Merge branch 'dev_new_commands' of https://github.com/Valansch/RedMew

This commit is contained in:
grilledham 2018-08-11 12:40:05 +01:00
commit a572b13025
2 changed files with 100 additions and 0 deletions

View File

@ -622,6 +622,52 @@ if not _DEBUG then
end
end
local function admin_chat(cmd)
if not game.player or game.player.admin then --admins AND server
for _,p in pairs(game.players) do
if p.admin then
local tag = ''
if game.player.tag and game.player.tag ~= '' then
tag = ' ' .. game.player.tag
end
p.print(string.format("(Admin) %s%s: %s", game.player.name, tag, cmd.parameter), game.player.chat_color)
end
end
end
end
local function report(cmd)
if game.player then
local params = {}
for param in string.gmatch(cmd.parameter, '%S+') do
table.insert(params, param)
end
if #params < 2 then
game.player.print("Please enter then name of the offender and the reason for the report.")
return nil
end
if not game.players[params[1]] then
game.player.print(params[1] .. " does not exist.")
return nil
end
for _,p in pairs(game.players) do
if p.admin then
Utils.alert(
p,
{
"User Report",
"Offender: " .. params[1],
"Message: " .. string.sub(cmd.parameter, string.len(params[1]) + 2)
}
)
end
end
end
end
commands.add_command('kill', 'Will kill you.', kill)
commands.add_command('tpplayer', '<player> - Teleports you to the player. (Admins only)', teleport_player)
commands.add_command('invoke', '<player> - Teleports the player to you. (Admins only)', invoke)
@ -680,3 +726,5 @@ commands.add_command(
'<player> restores ability for a player to perform actions. (Admins only)',
unjail_player
)
commands.add_command('a', 'Admin chat. Messages all other admins (Admins only)', admin_chat)
commands.add_command('report', '<griefer-name> <message> Reports a user to admins', report)

View File

@ -90,6 +90,58 @@ Module.find_entities_by_last_user =
return entities
end
local Gui = require("utils.gui")
local alert_frame_name = Gui.uid_name()
local alert_close_button_name = Gui.uid_name()
function Module.alert(player, lines)
if type(lines) == string then
lines = {lines}
end
local center = player.gui.center
local alert_frame = center[alert_frame_name]
if alert_frame and alert_frame.valid then
Gui.remove_data_recursivly(alert_frame)
alert_frame.destroy()
end
alert_frame =
center.add {
type = 'frame',
name = alert_frame_name,
direction = 'vertical',
caption = 'Alert'
}
alert_frame.style.maximal_width = 500
player.opened = alert_frame
for _,line in pairs(lines) do
local frame = alert_frame.add {
type = 'label',
caption = line
}
frame.style.single_line = false
end
alert_frame.add {type = 'button', name = alert_close_button_name, caption = 'Close'}
end
Gui.on_custom_close(
alert_frame_name,
function(event)
Gui.remove_data_recursivly(event.element)
event.element.destroy()
end
)
Gui.on_click(
alert_close_button_name,
function(event)
Gui.remove_data_recursivly(event.element)
event.element.parent.destroy()
end
)
Module.ternary = function(c, t, f)
if c then
return t