2017-07-08 22:24:24 +02:00
2017-12-19 19:10:55 +02:00
function allowed_to_nuke ( player )
2017-12-26 00:00:24 +02:00
if type ( player ) == " table " then
2017-07-09 15:20:01 +02:00
return player.admin or is_mod ( player.name ) or is_regular ( player.name ) or ( ( player.online_time / 216000 ) > global.scenario . config.nuke_min_time_hours )
2017-12-29 00:03:50 +02:00
elseif type ( player ) == " number " then
2017-12-26 00:00:24 +02:00
return allowed_to_nuke ( game.players [ player ] )
end
2017-07-08 22:24:24 +02:00
end
local function ammo_changed ( event )
local player = game.players [ event.player_index ]
if allowed_to_nuke ( player ) then return end
2017-07-23 04:39:02 +02:00
local nukes = player.remove_item ( { name = " atomic-bomb " , count = 1000 } )
2017-07-08 22:24:24 +02:00
if nukes > 0 then
game.print ( player.name .. " tried to use a nuke, but instead dropped it on his foot. " )
player.character . health = 0
end
end
2017-07-23 04:39:02 +02:00
local function on_player_deconstructed_area ( event )
local player = game.players [ event.player_index ]
if allowed_to_nuke ( player ) then return end
local nukes = player.remove_item ( { name = " deconstruction-planner " , count = 1000 } )
2017-11-09 21:28:56 +02:00
--Make them think they arent noticed
print_except ( player.name .. " tried to deconstruct something, but instead deconstructed himself. " , player )
2017-12-26 00:00:24 +02:00
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
2017-07-23 04:39:02 +02:00
player.character . health = 0
2017-11-09 21:05:37 +02:00
local entities = player.surface . find_entities_filtered { area = event.area , force = player.force }
if # entities > 1000 then
2017-11-09 21:28:56 +02:00
print_admins ( " Warning! " .. player.name .. " just tried to deconstruct " .. tostring ( # entities ) .. " entities! " )
2017-11-09 21:05:37 +02:00
end
for _ , entity in pairs ( entities ) do
2017-11-09 20:52:55 +02:00
if entity.valid and entity.to_be_deconstructed ( game.players [ event.player_index ] . force ) then
2017-09-28 01:07:38 +02:00
entity.cancel_deconstruction ( game.players [ event.player_index ] . force )
end
2017-07-23 04:39:02 +02:00
end
end
2017-10-26 16:28:08 +02:00
local function log_on_player_mined_entity ( str , event )
2017-10-27 23:18:26 +02:00
game.write_file ( " on_player_mined_entity_debug " , game.tick .. " ( " .. game.players [ event.player_index ] . name .. " ) " .. str .. " \n " , true , 0 )
2017-10-26 16:28:08 +02:00
end
global.on_player_mined_item_enabled = true
global.on_player_mined_item_init = true
2017-12-26 00:00:24 +02:00
--Never knew the debug code made it into the codebase lol
2017-09-24 00:22:51 +02:00
local function on_player_mined_item ( event )
2017-10-26 16:28:08 +02:00
log_on_player_mined_entity ( " nuke_control.on_player_mined_item: entry " , event )
if global.on_player_mined_item_enabled then
log_on_player_mined_entity ( " nuke_control.on_player_mined_item: enabled " , event )
if global.on_player_mined_item_init then
log_on_player_mined_entity ( " nuke_control.on_player_mined_item: init " , event )
game.forces . enemy.research_all_technologies ( ) --avoids losing logstics slot configuration on force toggle
global.on_player_mined_item_init = false
end
local entity = event.entity
2017-11-09 20:56:53 +02:00
if entity.valid and entity.force . name ~= " enemy " and entity.force . name ~= " neutral " and entity.name ~= " entity-ghost " and entity.type ~= " logistic-robot " and entity.type ~= " construction-robot " then
2017-10-26 16:28:08 +02:00
log_on_player_mined_entity ( " nuke_control.on_player_mined_item: in body " , event )
local entity_name = entity.name
if entity_name == " pipe-to-ground " then entity_name = " pipe " end
log_on_player_mined_entity ( " nuke_control.on_player_mined_item: before ghost placement " , event )
local ghost = event.entity . surface.create_entity { name = " entity-ghost " , position = event.entity . position , inner_name = entity_name , expires = false , force = " enemy " , direction = event.entity . direction }
log_on_player_mined_entity ( " nuke_control.on_player_mined_item: ghost placed " , event )
ghost.last_user = event.player_index
log_on_player_mined_entity ( " nuke_control.on_player_mined_item: last user set " , event )
end
2017-09-24 00:22:51 +02:00
end
2017-10-26 16:28:08 +02:00
log_on_player_mined_entity ( " nuke_control.on_player_mined_item: exit " , event )
2017-09-24 00:22:51 +02:00
end
2017-12-27 02:33:29 +02:00
local function item_not_sanctioned ( item )
local name = item.name
return (
name : find ( " capsule " ) or
name == " cliff-explosives " or
name == " raw-fish " or
name == " discharge-defense-remote "
)
end
2017-12-26 00:00:24 +02:00
global.players_warned = { }
local function on_capsule_used ( event )
2017-12-27 02:33:29 +02:00
if item_not_sanctioned ( event.item ) then return nil end
2017-12-26 00:00:24 +02:00
local player = game.players [ event.player_index ]
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 } }
2018-01-07 12:14:36 +02:00
local count = 0
local entities = player.surface . find_entities_filtered { force = player.force , area = area }
for _ , e in pairs ( entities ) do
if e.name ~= " entity-ghost " then count = count + 1 end
end
2017-12-26 00:00:24 +02:00
if count > 4 then
if global.players_warned [ event.player_index ] then
2017-12-26 01:09:32 +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 ) )
2017-12-26 00:00:24 +02:00
else
global.players_warned [ event.player_index ] = true
game.kick_player ( player , string.format ( " Damaged %i entities with %s -Antigrief " , count , event.item . name ) )
end
end
2017-12-19 19:10:55 +02:00
end
end
2017-07-08 22:24:24 +02:00
Event.register ( defines.events . on_player_ammo_inventory_changed , ammo_changed )
2017-07-23 04:39:02 +02:00
Event.register ( defines.events . on_player_deconstructed_area , on_player_deconstructed_area )
2017-12-16 17:55:47 +02:00
--Event.register(defines.events.on_player_mined_entity, on_player_mined_item)
2017-12-26 00:00:24 +02:00
Event.register ( defines.events . on_player_used_capsule , on_capsule_used )