2018-11-20 12:46:19 +02:00
local Event = require ' utils.event '
local UserGroups = require ' features.user_groups '
local Utils = require ' utils.utils '
local Game = require ' utils.game '
2017-07-08 22:24:24 +02:00
2018-11-06 13:55:52 +02:00
local function allowed_to_nuke ( player )
2018-11-20 12:46:19 +02:00
if type ( player ) == ' table ' then
2018-11-18 13:59:52 +02:00
return player.admin or UserGroups.is_regular ( player.name ) or ( ( player.online_time / 216000 ) > global.scenario . config.nuke_control . nuke_min_time_hours )
2018-11-20 12:46:19 +02:00
elseif type ( player ) == ' number ' then
2018-11-18 13:59:52 +02:00
return allowed_to_nuke ( Game.get_player_by_index ( player ) )
end
2017-07-08 22:24:24 +02:00
end
local function ammo_changed ( event )
2018-11-18 13:59:52 +02:00
local player = Game.get_player_by_index ( event.player_index )
if allowed_to_nuke ( player ) then
return
end
2018-11-20 12:46:19 +02:00
local nukes = player.remove_item ( { name = ' atomic-bomb ' , count = 1000 } )
2018-11-18 13:59:52 +02:00
if nukes > 0 then
2018-11-20 12:46:19 +02:00
game.print ( player.name .. ' tried to use a nuke, but instead dropped it on his foot. ' )
2018-11-18 13:59:52 +02: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 12:46:19 +02:00
p.add_custom_alert ( character , { type = ' item ' , name = ' atomic-bomb ' } , player.name , true )
2018-11-18 13:59:52 +02:00
end
end
2018-06-08 00:50:31 +02:00
end
2018-11-18 13:59:52 +02:00
player.character . health = 0
2018-06-08 00:50:31 +02: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 )
2018-11-18 13:59:52 +02:00
local player = Game.get_player_by_index ( event.player_index )
if allowed_to_nuke ( player ) then
return
end
2018-11-20 12:46:19 +02:00
player.remove_item ( { name = ' deconstruction-planner ' , count = 1000 } )
2017-11-09 21:28:56 +02:00
--Make them think they arent noticed
2018-11-20 12:46:19 +02:00
Utils.print_except ( 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 21:28:56 +02:00
2018-06-08 00:50:31 +02:00
local character = player.character
if character and character.valid then
2018-11-18 13:59:52 +02:00
for _ , p in ipairs ( game.connected_players ) do
if p ~= player then
2018-11-20 12:46:19 +02:00
p.add_custom_alert ( character , { type = ' item ' , name = ' deconstruction-planner ' } , player.name , true )
2018-11-18 13:59:52 +02:00
end
2018-06-08 00:50:31 +02:00
end
end
character.health = 0
2018-06-25 00:31:08 +02: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 13:59:52 +02:00
return
2018-06-25 00:31:08 +02:00
end
2018-08-14 00:30:49 +02:00
2018-11-18 13:59:52 +02:00
local entities = player.surface . find_entities_filtered { area = area , force = player.force }
2017-11-09 21:05:37 +02:00
if # entities > 1000 then
2018-11-20 12:46:19 +02:00
Utils.print_admins ( ' Warning! ' .. player.name .. ' just tried to deconstruct ' .. tostring ( # entities ) .. ' entities! ' , false )
2017-11-09 21:05:37 +02:00
end
2018-11-18 13:59:52 +02:00
for _ , entity in pairs ( entities ) do
if entity.valid and entity.to_be_deconstructed ( Game.get_player_by_index ( event.player_index ) . force ) then
entity.cancel_deconstruction ( Game.get_player_by_index ( event.player_index ) . force )
end
2017-07-23 04:39:02 +02:00
end
end
2017-12-27 02:33:29 +02:00
local function item_not_sanctioned ( item )
2018-11-18 13:59:52 +02:00
local name = item.name
2018-11-20 12:46:19 +02:00
return ( name : find ( ' capsule ' ) or name == ' cliff-explosives ' or name == ' raw-fish ' or name == ' discharge-defense-remote ' )
2017-12-27 02:33:29 +02:00
end
2018-08-14 00:30:49 +02:00
global.entities_allowed_to_bomb = {
2018-11-20 12:46:19 +02:00
[ ' stone-wall ' ] = true ,
[ ' transport-belt ' ] = true ,
[ ' fast-transport-belt ' ] = true ,
[ ' express-transport-belt ' ] = true ,
[ ' construction-robot ' ] = true ,
[ ' player ' ] = true ,
[ ' 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
2018-08-14 00:30:49 +02:00
}
2018-05-16 11:58:55 +02:00
local function entity_allowed_to_bomb ( entity )
2018-11-18 13:59:52 +02:00
return global.entities_allowed_to_bomb [ entity.name ]
2018-02-08 09:55:26 +02:00
end
2017-12-26 00:00:24 +02:00
global.players_warned = { }
local function on_capsule_used ( event )
2018-11-18 13:59:52 +02:00
local item = event.item
local player = Game.get_player_by_index ( event.player_index )
if not player or not player.valid or ( global.scenario . config.nuke_control . enable_autokick and global.scenario . config.nuke_control . enable_autoban ) then
return
end
2018-11-20 12:46:19 +02:00
if item.name == ' artillery-targeting-remote ' then
player.surface . create_entity { name = ' flying-text ' , text = player.name , color = player.color , position = event.position }
2018-01-07 12:14:36 +02:00
end
2018-11-18 13:59:52 +02:00
if item_not_sanctioned ( item ) then
return
end
if ( not allowed_to_nuke ( player ) ) then
local area = { { event.position . x - 5 , event.position . y - 5 } , { event.position . x + 5 , event.position . y + 5 } }
local count = 0
local entities = player.surface . find_entities_filtered { force = player.force , area = area }
for _ , e in pairs ( entities ) do
if not entity_allowed_to_bomb ( e ) then
count = count + 1
end
2018-09-11 16:21:35 +02:00
end
2018-11-18 13:59:52 +02:00
if count > 8 then
if global.players_warned [ event.player_index ] then
if global.scenario . config.nuke_control . enable_autokick then
2018-11-20 12:46:19 +02:00
game.ban_player ( player , string.format ( ' Damaged %i entities with %s. This action was performed automatically. If you want to contest this ban please visit redmew.com/discord. ' , count , event.item . name ) )
2018-11-18 13:59:52 +02:00
end
else
global.players_warned [ event.player_index ] = true
if global.scenario . config.nuke_control . enable_autoban then
2018-11-20 12:46:19 +02:00
game.print ( player , string.format ( ' Damaged %i entities with %s -Antigrief ' , count , event.item . name ) )
2018-11-18 13:59:52 +02:00
end
end
2018-09-11 16:21:35 +02:00
end
2017-12-26 00:00:24 +02:00
end
2017-12-19 19:10:55 +02:00
end
2018-10-04 10:53:35 +02:00
local function on_player_joined ( event )
2018-11-18 13:59:52 +02:00
local player = game.players [ event.player_index ]
2018-11-20 12:46:19 +02:00
if string.match ( player.name , ' ^[Ili1|]+$ ' ) then
2018-11-18 13:59:52 +02:00
game.ban_player ( player ) --No reason given, to not give them any hints to change their name
end
2018-10-04 10:53:35 +02:00
end
2018-04-06 21:58:50 +02: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 21:58:50 +02:00
Event.add ( defines.events . on_player_deconstructed_area , on_player_deconstructed_area )
--Event.add(defines.events.on_player_mined_entity, on_player_mined_item)
Event.add ( defines.events . on_player_used_capsule , on_capsule_used )