diff --git a/custom_commands.lua b/custom_commands.lua index ad9dfdb5..2b040c8b 100644 --- a/custom_commands.lua +++ b/custom_commands.lua @@ -624,14 +624,14 @@ 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 + 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 + p.print(string.format('(Admin) %s%s: %s', game.player.name, tag, cmd.parameter), game.player.chat_color) + end end end end @@ -697,10 +697,37 @@ commands.add_command( commands.add_command('a', 'Admin chat. Messages all other admins (Admins only)', admin_chat) local Report = require('report') -commands.add_command('showreports', 'Shows user reports (Admins only)', - function(event) - if game.player and game.player.admin then - Report.show_reports(game.players[event.player_index]) + +local function report(cmd) + local reporting_player = game.player + if reporting_player then + local params = {} + for param in string.gmatch(cmd.parameter, '%S+') do + table.insert(params, param) + end + if #params < 2 then + reporting_player.print('Please enter then name of the offender and the reason for the report.') + return nil + end + local reported_player_name = params[1] or '' + local reported_player = game.players[reported_player_name] + + if not reported_player then + reporting_player.print(reported_player_name .. ' does not exist.') + return nil + end + Report.report(reporting_player, reported_player, string.sub(cmd.parameter, string.len(params[1]) + 2)) + end +end + +commands.add_command('report', ' Reports a user to admins', report) + +commands.add_command( + 'showreports', + 'Shows user reports (Admins only)', + function(event) + if game.player and game.player.admin then + Report.show_reports(game.players[event.player_index]) end end ) diff --git a/report.lua b/report.lua index 2a06d1bb..c4ae63fe 100644 --- a/report.lua +++ b/report.lua @@ -73,7 +73,7 @@ Module.show_reports = function(player) draw_report(report_body, #reports) end -local function report(reporting_player, reported_player, message) +function Module.report(reporting_player, reported_player, message) table.insert(global.reports, {reporting_player_index = reporting_player.index, reported_player_index = reported_player.index, message = message, tick = game.tick}) local notified = false @@ -149,7 +149,7 @@ Module.spawn_reporting_popup = function(player, reported_player) input.style.width = 400 input.style.height = 85 local button_flow = reporting_popup.add {type = "flow"} - submit_button = button_flow.add {type = "button", name = reporting_submit_button_name, caption="Submit"} + local submit_button = button_flow.add {type = "button", name = reporting_submit_button_name, caption="Submit"} button_flow.add {type = "button", name = reporting_cancel_button_name, caption="Cancel"} end @@ -178,7 +178,7 @@ Gui.on_click( local reported_player_index = data["reported_player_index"] Gui.destroy(frame) - report(event.player, game.players[reported_player_index], msg) + Module.report(event.player, game.players[reported_player_index], msg) event.player.print("Sucessfully reported " .. game.players[reported_player_index].name) end