| 
									
										
										
										
											2018-11-20 05:46:19 -05:00
										 |  |  | local Event = require 'utils.event' | 
					
						
							| 
									
										
										
										
											2019-01-29 22:52:43 -05:00
										 |  |  | local Rank = require 'features.rank_system' | 
					
						
							| 
									
										
										
										
											2018-11-25 20:07:03 -05:00
										 |  |  | local Utils = require 'utils.core' | 
					
						
							| 
									
										
										
										
											2019-02-17 02:28:14 -05:00
										 |  |  | local Task = require 'utils.task' | 
					
						
							|  |  |  | local Token = require 'utils.token' | 
					
						
							| 
									
										
										
										
											2019-02-19 19:38:11 -05:00
										 |  |  | local Global = require 'utils.global' | 
					
						
							| 
									
										
										
										
											2018-11-28 17:56:31 +00:00
										 |  |  | local Server = require 'features.server' | 
					
						
							| 
									
										
										
										
											2019-02-17 02:28:14 -05:00
										 |  |  | local Report = require 'features.report' | 
					
						
							|  |  |  | local Popup = require 'features.gui.popup' | 
					
						
							| 
									
										
										
										
											2019-01-29 22:52:43 -05:00
										 |  |  | local Ranks = require 'resources.ranks' | 
					
						
							| 
									
										
										
										
											2017-07-08 22:24:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-23 23:37:11 -05:00
										 |  |  | local format = string.format | 
					
						
							|  |  |  | local match = string.match | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 13:43:17 +00:00
										 |  |  | -- capsule antigreif player entities threshold. | 
					
						
							|  |  |  | local capsule_bomb_threshold = 8 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-19 19:38:11 -05:00
										 |  |  | local players_warned = {} | 
					
						
							|  |  |  | local entities_allowed_to_bomb = { | 
					
						
							|  |  |  |     ['stone-wall'] = true, | 
					
						
							|  |  |  |     ['transport-belt'] = true, | 
					
						
							|  |  |  |     ['fast-transport-belt'] = true, | 
					
						
							|  |  |  |     ['express-transport-belt'] = true, | 
					
						
							|  |  |  |     ['construction-robot'] = true, | 
					
						
							| 
									
										
										
										
											2019-05-02 17:02:53 +02:00
										 |  |  |     ['character'] = true, | 
					
						
							| 
									
										
										
										
											2019-02-19 19:38:11 -05:00
										 |  |  |     ['gun-turret'] = true, | 
					
						
							|  |  |  |     ['laser-turret'] = true, | 
					
						
							|  |  |  |     ['flamethrower-turret'] = true, | 
					
						
							|  |  |  |     ['rail'] = true, | 
					
						
							|  |  |  |     ['rail-chain-signal'] = true, | 
					
						
							|  |  |  |     ['rail-signal'] = true, | 
					
						
							|  |  |  |     ['tile-ghost'] = true, | 
					
						
							|  |  |  |     ['entity-ghost'] = true, | 
					
						
							|  |  |  |     ['gate'] = true, | 
					
						
							|  |  |  |     ['electric-pole'] = true, | 
					
						
							|  |  |  |     ['small-electric-pole'] = true, | 
					
						
							|  |  |  |     ['medium-electric-pole'] = true, | 
					
						
							|  |  |  |     ['big-electric-pole'] = true, | 
					
						
							|  |  |  |     ['logistic-robot'] = true, | 
					
						
							|  |  |  |     ['defender'] = true, | 
					
						
							|  |  |  |     ['destroyer'] = true, | 
					
						
							|  |  |  |     ['distractor'] = true | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Global.register( | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         players_warned = players_warned, | 
					
						
							|  |  |  |         entities_allowed_to_bomb = entities_allowed_to_bomb | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     function(tbl) | 
					
						
							|  |  |  |         players_warned = tbl.players_warned | 
					
						
							|  |  |  |         entities_allowed_to_bomb = tbl.entities_allowed_to_bomb | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-19 19:26:04 -05:00
										 |  |  | local function is_trusted(player) | 
					
						
							| 
									
										
										
										
											2019-01-29 22:52:43 -05:00
										 |  |  |     return Rank.equal_or_greater_than(player.name, Ranks.auto_trusted) | 
					
						
							| 
									
										
										
										
											2017-07-08 22:24:24 +02:00
										 |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | local function ammo_changed(event) | 
					
						
							| 
									
										
										
										
											2019-05-16 11:10:56 +01:00
										 |  |  |     local player = game.get_player(event.player_index) | 
					
						
							| 
									
										
										
										
											2019-02-19 19:26:04 -05:00
										 |  |  |     if is_trusted(player) then | 
					
						
							| 
									
										
										
										
											2018-11-18 06:59:52 -05:00
										 |  |  |         return | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2018-11-20 05:46:19 -05:00
										 |  |  |     local nukes = player.remove_item({name = 'atomic-bomb', count = 1000}) | 
					
						
							| 
									
										
										
										
											2018-11-18 06:59:52 -05:00
										 |  |  |     if nukes > 0 then | 
					
						
							| 
									
										
										
										
											2019-01-23 23:37:11 -05:00
										 |  |  |         Utils.action_warning('[Nuke]', player.name .. ' tried to use a nuke, but instead dropped it on his foot.') | 
					
						
							| 
									
										
										
										
											2018-11-18 06:59:52 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |         local character = player.character | 
					
						
							|  |  |  |         if character and character.valid then | 
					
						
							|  |  |  |             for _, p in ipairs(game.connected_players) do | 
					
						
							|  |  |  |                 if p ~= player then | 
					
						
							| 
									
										
										
										
											2018-11-20 05:46:19 -05:00
										 |  |  |                     p.add_custom_alert(character, {type = 'item', name = 'atomic-bomb'}, player.name, true) | 
					
						
							| 
									
										
										
										
											2018-11-18 06:59:52 -05:00
										 |  |  |                 end | 
					
						
							|  |  |  |             end | 
					
						
							| 
									
										
										
										
											2018-06-07 23:50:31 +01:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2018-11-18 06:59:52 -05:00
										 |  |  |         player.character.health = 0 | 
					
						
							| 
									
										
										
										
											2018-06-07 23:50:31 +01:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-07-08 22:24:24 +02:00
										 |  |  | end | 
					
						
							| 
									
										
										
										
											2017-07-23 04:39:02 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | local function on_player_deconstructed_area(event) | 
					
						
							| 
									
										
										
										
											2019-05-16 11:10:56 +01:00
										 |  |  |     local player = game.get_player(event.player_index) | 
					
						
							| 
									
										
										
										
											2019-02-19 19:26:04 -05:00
										 |  |  |     if is_trusted(player) then | 
					
						
							| 
									
										
										
										
											2018-11-18 06:59:52 -05:00
										 |  |  |         return | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2018-11-20 05:46:19 -05:00
										 |  |  |     player.remove_item({name = 'deconstruction-planner', count = 1000}) | 
					
						
							| 
									
										
										
										
											2017-11-09 20:28:56 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     --Make them think they arent noticed | 
					
						
							| 
									
										
										
										
											2020-02-02 13:43:17 +00:00
										 |  |  |     Utils.silent_action_warning( | 
					
						
							|  |  |  |         '[Deconstruct]', | 
					
						
							|  |  |  |         player.name .. ' tried to deconstruct something, but instead deconstructed themself.', | 
					
						
							|  |  |  |         player | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     player.print( | 
					
						
							|  |  |  |         'Only regulars can mark things for deconstruction, if you want to deconstruct something you may ask an admin to promote you.' | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-11-09 20:28:56 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-07 23:50:31 +01:00
										 |  |  |     local character = player.character | 
					
						
							|  |  |  |     if character and character.valid then | 
					
						
							| 
									
										
										
										
											2018-11-18 06:59:52 -05:00
										 |  |  |         for _, p in ipairs(game.connected_players) do | 
					
						
							|  |  |  |             if p ~= player then | 
					
						
							| 
									
										
										
										
											2018-11-20 05:46:19 -05:00
										 |  |  |                 p.add_custom_alert(character, {type = 'item', name = 'deconstruction-planner'}, player.name, true) | 
					
						
							| 
									
										
										
										
											2018-11-18 06:59:52 -05:00
										 |  |  |             end | 
					
						
							| 
									
										
										
										
											2018-06-07 23:50:31 +01:00
										 |  |  |         end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |     character.health = 0 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-24 23:31:08 +01:00
										 |  |  |     local area = event.area | 
					
						
							|  |  |  |     local left_top, right_bottom = area.left_top, area.right_bottom | 
					
						
							|  |  |  |     if left_top.x == right_bottom.x and left_top.y == right_bottom.y then | 
					
						
							| 
									
										
										
										
											2018-11-18 06:59:52 -05:00
										 |  |  |         return | 
					
						
							| 
									
										
										
										
											2018-06-24 23:31:08 +01:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2018-08-14 00:30:49 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-18 06:59:52 -05:00
										 |  |  |     local entities = player.surface.find_entities_filtered {area = area, force = player.force} | 
					
						
							| 
									
										
										
										
											2017-11-09 20:05:37 +01:00
										 |  |  |     if #entities > 1000 then | 
					
						
							| 
									
										
										
										
											2020-02-02 13:43:17 +00:00
										 |  |  |         Utils.print_admins( | 
					
						
							|  |  |  |             'Warning! ' .. player.name .. ' just tried to deconstruct ' .. tostring(#entities) .. ' entities!', | 
					
						
							|  |  |  |             nil | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2017-11-09 20:05:37 +01:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2018-11-18 06:59:52 -05:00
										 |  |  |     for _, entity in pairs(entities) do | 
					
						
							| 
									
										
										
										
											2019-05-16 11:10:56 +01:00
										 |  |  |         if entity.valid and entity.to_be_deconstructed(game.get_player(event.player_index).force) then | 
					
						
							|  |  |  |             entity.cancel_deconstruction(game.get_player(event.player_index).force) | 
					
						
							| 
									
										
										
										
											2018-11-18 06:59:52 -05:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-07-23 04:39:02 +02:00
										 |  |  |     end | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-27 01:33:29 +01:00
										 |  |  | local function item_not_sanctioned(item) | 
					
						
							| 
									
										
										
										
											2018-11-18 06:59:52 -05:00
										 |  |  |     local name = item.name | 
					
						
							| 
									
										
										
										
											2020-02-02 13:43:17 +00:00
										 |  |  |     if name:find('capsule') or name == 'cliff-explosives' or name == 'discharge-defense-remote' then | 
					
						
							|  |  |  |         return true | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     local capsule_action = item.capsule_action | 
					
						
							|  |  |  |     if capsule_action and capsule_action.type == 'use-on-self' then | 
					
						
							|  |  |  |         return true | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return false | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | local function entity_allowed_to_bomb(entity_name) | 
					
						
							|  |  |  |     return entities_allowed_to_bomb[entity_name] | 
					
						
							| 
									
										
										
										
											2017-12-27 01:33:29 +01:00
										 |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 13:43:17 +00:00
										 |  |  | local function list_damaged_entities(item_name, entities) | 
					
						
							|  |  |  |     local set = {} | 
					
						
							|  |  |  |     for i = 1, #entities do | 
					
						
							|  |  |  |         local e = entities[i] | 
					
						
							|  |  |  |         local name = e.name | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if name ~= item_name then | 
					
						
							|  |  |  |             local count = set[name] | 
					
						
							|  |  |  |             if count then | 
					
						
							|  |  |  |                 set[name] = count + 1 | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |                 set[name] = 1 | 
					
						
							|  |  |  |             end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     local list = {} | 
					
						
							|  |  |  |     local i = 1 | 
					
						
							|  |  |  |     for k, v in pairs(set) do | 
					
						
							|  |  |  |         list[i] = k | 
					
						
							|  |  |  |         i = i + 1 | 
					
						
							|  |  |  |         list[i] = '(' | 
					
						
							|  |  |  |         i = i + 1 | 
					
						
							|  |  |  |         list[i] = v | 
					
						
							|  |  |  |         i = i + 1 | 
					
						
							|  |  |  |         list[i] = ')' | 
					
						
							|  |  |  |         i = i + 1 | 
					
						
							|  |  |  |         list[i] = ', ' | 
					
						
							|  |  |  |         i = i + 1 | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |     list[i - 1] = nil | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return table.concat(list) | 
					
						
							| 
									
										
										
										
											2018-02-08 08:55:26 +01:00
										 |  |  | end | 
					
						
							| 
									
										
										
										
											2018-11-28 11:15:44 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-25 23:00:24 +01:00
										 |  |  | local function on_capsule_used(event) | 
					
						
							| 
									
										
										
										
											2018-11-18 06:59:52 -05:00
										 |  |  |     local item = event.item | 
					
						
							| 
									
										
										
										
											2019-05-16 11:10:56 +01:00
										 |  |  |     local player = game.get_player(event.player_index) | 
					
						
							| 
									
										
										
										
											2018-11-18 06:59:52 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-28 11:15:44 +00:00
										 |  |  |     if not player or not player.valid then | 
					
						
							| 
									
										
										
										
											2018-11-18 06:59:52 -05:00
										 |  |  |         return | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-20 05:46:19 -05:00
										 |  |  |     if item.name == 'artillery-targeting-remote' then | 
					
						
							| 
									
										
										
										
											2018-11-28 11:15:44 +00:00
										 |  |  |         player.surface.create_entity { | 
					
						
							|  |  |  |             name = 'flying-text', | 
					
						
							|  |  |  |             text = player.name, | 
					
						
							|  |  |  |             color = player.color, | 
					
						
							|  |  |  |             position = event.position | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     local nuke_control = global.config.nuke_control | 
					
						
							| 
									
										
										
										
											2018-11-28 17:56:31 +00:00
										 |  |  |     if not nuke_control.enable_autokick and not nuke_control.enable_autoban then | 
					
						
							| 
									
										
										
										
											2018-11-28 11:15:44 +00:00
										 |  |  |         return | 
					
						
							| 
									
										
										
										
											2018-01-07 11:14:36 +01:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2018-11-18 06:59:52 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 13:43:17 +00:00
										 |  |  |     if is_trusted(player) or item_not_sanctioned(item) then | 
					
						
							| 
									
										
										
										
											2018-11-18 06:59:52 -05:00
										 |  |  |         return | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-02 13:43:17 +00:00
										 |  |  |     local position = event.position | 
					
						
							|  |  |  |     local x, y = position.x, position.y | 
					
						
							|  |  |  |     local surface = player.surface | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if surface.count_entities_filtered({force = 'enemy', area = {{x - 10, y - 10}, {x + 10, y + 10}}, limit = 1}) > 0 then | 
					
						
							|  |  |  |         return | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     local count = 0 | 
					
						
							|  |  |  |     local entities = | 
					
						
							|  |  |  |         player.surface.find_entities_filtered {force = player.force, area = {{x - 5, y - 5}, {x + 5, y + 5}}} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     local item_name = item.name | 
					
						
							|  |  |  |     for i = 1, #entities do | 
					
						
							|  |  |  |         local e = entities[i] | 
					
						
							|  |  |  |         local entity_name = e.name | 
					
						
							|  |  |  |         if entity_name ~= item_name and not entity_allowed_to_bomb(entity_name) then | 
					
						
							|  |  |  |             count = count + 1 | 
					
						
							| 
									
										
										
										
											2018-09-11 16:21:35 +02:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2020-02-02 13:43:17 +00:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if count <= capsule_bomb_threshold then | 
					
						
							|  |  |  |         return | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if players_warned[event.player_index] then | 
					
						
							|  |  |  |         if nuke_control.enable_autoban then | 
					
						
							|  |  |  |             Server.ban_sync( | 
					
						
							|  |  |  |                 player.name, | 
					
						
							|  |  |  |                 format( | 
					
						
							|  |  |  |                     'Damaged entities: %s with %s. This action was performed automatically. If you want to contest this ban please visit redmew.com/discord', | 
					
						
							|  |  |  |                     list_damaged_entities(item_name, entities), | 
					
						
							|  |  |  |                     item_name | 
					
						
							|  |  |  |                 ), | 
					
						
							|  |  |  |                 '<script>' | 
					
						
							|  |  |  |             ) | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |         players_warned[event.player_index] = true | 
					
						
							|  |  |  |         if nuke_control.enable_autokick then | 
					
						
							|  |  |  |             game.kick_player( | 
					
						
							|  |  |  |                 player, | 
					
						
							|  |  |  |                 format('Damaged entities: %s with %s -Antigrief', list_damaged_entities(item_name, entities), item_name) | 
					
						
							|  |  |  |             ) | 
					
						
							| 
									
										
										
										
											2018-09-11 16:21:35 +02:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-12-25 23:00:24 +01:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-12-19 18:10:55 +01:00
										 |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-04 10:53:35 +02:00
										 |  |  | local function on_player_joined(event) | 
					
						
							| 
									
										
										
										
											2018-11-18 06:59:52 -05:00
										 |  |  |     local player = game.players[event.player_index] | 
					
						
							| 
									
										
										
										
											2019-01-23 23:37:11 -05:00
										 |  |  |     if match(player.name, '^[Ili1|]+$') then | 
					
						
							| 
									
										
										
										
											2018-11-28 17:59:32 +00:00
										 |  |  |         Server.ban_sync(player.name, '', '<script>') --No reason given, to not give them any hints to change their name | 
					
						
							| 
									
										
										
										
											2018-11-18 06:59:52 -05:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2018-10-04 10:53:35 +02:00
										 |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-17 02:28:14 -05:00
										 |  |  | local train_to_manual = | 
					
						
							|  |  |  |     Token.register( | 
					
						
							|  |  |  |     function(train) | 
					
						
							| 
									
										
										
										
											2019-02-19 18:18:19 -05:00
										 |  |  |         if train.valid then | 
					
						
							| 
									
										
										
										
											2019-02-17 02:28:14 -05:00
										 |  |  |             train.manual_mode = true | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | local function on_entity_died(event) | 
					
						
							| 
									
										
										
										
											2019-02-19 18:47:22 -05:00
										 |  |  |     -- We only care if a train is killed by a member of its own force | 
					
						
							| 
									
										
										
										
											2019-02-17 02:28:14 -05:00
										 |  |  |     local entity = event.entity | 
					
						
							| 
									
										
										
										
											2019-02-19 18:47:22 -05:00
										 |  |  |     if (not entity or not entity.valid) or not entity.train or (event.force ~= entity.force) then | 
					
						
							| 
									
										
										
										
											2019-02-17 02:28:14 -05:00
										 |  |  |         return | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |     -- Check that an entity did the killing | 
					
						
							|  |  |  |     local cause = event.cause | 
					
						
							|  |  |  |     if not cause or not cause.valid then | 
					
						
							|  |  |  |         return | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |     -- Check that the entity was a train and in manual | 
					
						
							|  |  |  |     local train = cause.train | 
					
						
							|  |  |  |     if not train or not train.manual_mode then | 
					
						
							|  |  |  |         return | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |     -- Check if the train has passengers | 
					
						
							|  |  |  |     local passengers = train.passengers | 
					
						
							|  |  |  |     local num_passengers = #passengers | 
					
						
							|  |  |  |     if num_passengers == 0 then | 
					
						
							|  |  |  |         train.manual_mode = false -- if the train is in manual and has no passengers, stop it | 
					
						
							|  |  |  |         Task.set_timeout_in_ticks(30, train_to_manual, train) | 
					
						
							|  |  |  |         return | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     -- Go through the passengers and punish any guests involved | 
					
						
							|  |  |  |     local player_punished | 
					
						
							|  |  |  |     local player_unpunished | 
					
						
							|  |  |  |     local name_list = {} | 
					
						
							| 
									
										
										
										
											2019-02-20 13:07:47 -05:00
										 |  |  |     for i = 1, num_passengers do | 
					
						
							| 
									
										
										
										
											2019-02-17 02:28:14 -05:00
										 |  |  |         local player = passengers[i] | 
					
						
							| 
									
										
										
										
											2019-02-19 18:18:19 -05:00
										 |  |  |         if player.valid then | 
					
						
							| 
									
										
										
										
											2019-02-19 19:26:04 -05:00
										 |  |  |             if is_trusted(player) then | 
					
						
							| 
									
										
										
										
											2019-02-19 18:18:19 -05:00
										 |  |  |                 player_unpunished = true | 
					
						
							|  |  |  |                 name_list[#name_list + 1] = player.name | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |                 -- If they aren't allowed to nuke, stop the train and act accordingly. | 
					
						
							|  |  |  |                 player_punished = true | 
					
						
							|  |  |  |                 name_list[#name_list + 1] = player.name | 
					
						
							|  |  |  |                 player.driving = false | 
					
						
							|  |  |  |                 train.manual_mode = false | 
					
						
							|  |  |  |                 Task.set_timeout_in_ticks(30, train_to_manual, train) | 
					
						
							| 
									
										
										
										
											2019-02-20 13:07:47 -05:00
										 |  |  |                 if players_warned[player.index] and num_passengers == 1 then -- jail for later offenses if they're solely guilty | 
					
						
							| 
									
										
										
										
											2019-02-19 18:18:19 -05:00
										 |  |  |                     Report.jail(player) | 
					
						
							|  |  |  |                     Utils.print_admins({'nuke_control.train_jailing', player.name}) | 
					
						
							| 
									
										
										
										
											2019-02-20 13:07:47 -05:00
										 |  |  |                 else -- warn for first offense or if there's someone else in the train | 
					
						
							| 
									
										
										
										
											2019-02-19 18:18:19 -05:00
										 |  |  |                     players_warned[player.index] = true | 
					
						
							|  |  |  |                     Utils.print_admins({'nuke_control.train_warning', player.name}) | 
					
						
							|  |  |  |                     Popup.player(player, {'nuke_control.train_player_warning'}) | 
					
						
							|  |  |  |                 end | 
					
						
							| 
									
										
										
										
											2019-02-17 02:28:14 -05:00
										 |  |  |             end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     -- If there was a passenger who was unpunished along with a punished passenger, let the admins know | 
					
						
							|  |  |  |     if player_punished and player_unpunished then | 
					
						
							| 
									
										
										
										
											2019-02-17 12:09:24 -05:00
										 |  |  |         local name_string = table.concat(name_list, ', ') | 
					
						
							| 
									
										
										
										
											2019-02-17 02:28:14 -05:00
										 |  |  |         Utils.print_admins({'nuke_control.multiple_passengers', num_passengers, name_string}) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-06 20:58:50 +01:00
										 |  |  | Event.add(defines.events.on_player_ammo_inventory_changed, ammo_changed) | 
					
						
							| 
									
										
										
										
											2018-10-04 10:53:35 +02:00
										 |  |  | Event.add(defines.events.on_player_joined_game, on_player_joined) | 
					
						
							| 
									
										
										
										
											2018-04-06 20:58:50 +01:00
										 |  |  | Event.add(defines.events.on_player_deconstructed_area, on_player_deconstructed_area) | 
					
						
							|  |  |  | Event.add(defines.events.on_player_used_capsule, on_capsule_used) | 
					
						
							| 
									
										
										
										
											2019-02-17 02:28:14 -05:00
										 |  |  | Event.add(defines.events.on_entity_died, on_entity_died) |