From a9a755826faeb7dd26be2715a5905f9a26043948 Mon Sep 17 00:00:00 2001 From: Valansch Date: Thu, 9 Aug 2018 00:14:59 +0200 Subject: [PATCH 1/4] implemented adminchat #200 --- custom_commands.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/custom_commands.lua b/custom_commands.lua index 8845c0c9..80d9dfd5 100644 --- a/custom_commands.lua +++ b/custom_commands.lua @@ -622,6 +622,20 @@ 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 + commands.add_command('kill', 'Will kill you.', kill) commands.add_command('tpplayer', ' - Teleports you to the player. (Admins only)', teleport_player) commands.add_command('invoke', ' - Teleports the player to you. (Admins only)', invoke) @@ -680,3 +694,4 @@ commands.add_command( ' 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) From 8c5c9e4bf38fc0258c228a304aaa7067480fbb61 Mon Sep 17 00:00:00 2001 From: Valansch Date: Fri, 10 Aug 2018 14:03:18 +0200 Subject: [PATCH 2/4] Fixed formatting --- custom_commands.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/custom_commands.lua b/custom_commands.lua index 80d9dfd5..71ddaecb 100644 --- a/custom_commands.lua +++ b/custom_commands.lua @@ -628,10 +628,10 @@ local function admin_chat(cmd) if p.admin then local tag = '' if game.player.tag and game.player.tag ~= '' then - tag = ' ' .. game.player.tag + 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 end From eb9b1496179955f7b3a84cdf0acb01043a52c112 Mon Sep 17 00:00:00 2001 From: Maik Wild Date: Fri, 10 Aug 2018 19:10:30 +0200 Subject: [PATCH 3/4] implemented /report --- custom_commands.lua | 37 ++++++++++++++++++++++++++++++-- utils/utils.lua | 52 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 2 deletions(-) diff --git a/custom_commands.lua b/custom_commands.lua index 71ddaecb..c833aba0 100644 --- a/custom_commands.lua +++ b/custom_commands.lua @@ -631,11 +631,43 @@ local function admin_chat(cmd) 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 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 Repiort", + "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', ' - Teleports you to the player. (Admins only)', teleport_player) commands.add_command('invoke', ' - Teleports the player to you. (Admins only)', invoke) @@ -695,3 +727,4 @@ commands.add_command( unjail_player ) commands.add_command('a', 'Admin chat. Messages all other admins (Admins only)', admin_chat) +commands.add_command('report', ' Reports a user to admins', report) diff --git a/utils/utils.lua b/utils/utils.lua index cb4c3152..5c51a4d1 100644 --- a/utils/utils.lua +++ b/utils/utils.lua @@ -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 From dd7def783b207c47fa2084f5a558f152f892c6b0 Mon Sep 17 00:00:00 2001 From: Valansch Date: Sat, 11 Aug 2018 01:28:01 +0200 Subject: [PATCH 4/4] Typo --- custom_commands.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_commands.lua b/custom_commands.lua index c833aba0..1252223b 100644 --- a/custom_commands.lua +++ b/custom_commands.lua @@ -655,7 +655,7 @@ local function report(cmd) Utils.alert( p, { - "User Repiort", + "User Report", "Offender: " .. params[1], "Message: " .. string.sub(cmd.parameter, string.len(params[1]) + 2) }